Skip to content

Commit

Permalink
#875: added docker error message (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Dec 12, 2024
1 parent 68713f1 commit 47f7b23
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.devonfw.tools.ide.cli.CliException;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.process.ProcessMode;
Expand All @@ -19,8 +20,8 @@
*/
public class LazyDocker extends LocalToolCommandlet {

public static final VersionIdentifier MIN_API_VERSION = VersionIdentifier.of("1.25");
public static final VersionIdentifier MIN_COMPOSE_VERSION = VersionIdentifier.of("1.23.2");
private static final VersionIdentifier MIN_API_VERSION = VersionIdentifier.of("1.25");
private static final VersionIdentifier MIN_COMPOSE_VERSION = VersionIdentifier.of("1.23.2");

/**
* The constructor.
Expand All @@ -38,21 +39,23 @@ protected void installDependencies() {
// TODO create lazydocker/lazydocker/dependencies.json file in ide-urls and delete this method
getCommandlet(Docker.class).install();
// verify docker API version requirements
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.NONE).executable("docker")
.addArg("version").addArg("--format").addArg("'{{.Client.APIVersion}}'");
ProcessContext pc = this.context.newProcess().errorHandling(ProcessErrorHandling.NONE).executable("docker").addArg("version").addArg("--format")
.addArg("'{{.Client.APIVersion}}'");
ProcessResult result = pc.run(ProcessMode.DEFAULT_CAPTURE);
verifyDockerVersion(result, MIN_API_VERSION, "docker API");

// verify docker compose version requirements
pc = this.context.newProcess().errorHandling(ProcessErrorHandling.NONE).executable("docker-compose").addArg("version")
.addArg("--short");
pc = this.context.newProcess().errorHandling(ProcessErrorHandling.NONE).executable("docker-compose").addArg("version").addArg("--short");
result = pc.run(ProcessMode.DEFAULT_CAPTURE);
verifyDockerVersion(result, MIN_COMPOSE_VERSION, "docker-compose");
}

private static void verifyDockerVersion(ProcessResult result, VersionIdentifier minimumVersion, String kind) {
private void verifyDockerVersion(ProcessResult result, VersionIdentifier minimumVersion, String kind) {
// we have this pattern a lot that we want to get a single line output of a successful ProcessResult.
// we should create a generic method in ProcessResult for this use-case.
if (!result.isSuccessful()) {
result.log(IdeLogLevel.WARNING, this.context);
}
if (result.getOut().isEmpty()) {
throw new CliException("Docker is not installed, but required for lazydocker.\n" //
+ "To install docker, call the following command:\n" //
Expand Down

0 comments on commit 47f7b23

Please sign in to comment.