diff --git a/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackConfig.java b/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackConfig.java index 645d3260a9ff0..652c5a3cf99ee 100644 --- a/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackConfig.java +++ b/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackConfig.java @@ -72,6 +72,19 @@ public class BuildpackConfig { @ConfigItem public Optional dockerHost; + /** + * use Daemon mode? + * Defaults to 'true' + */ + @ConfigItem(defaultValue = "true") + public Boolean useDaemon; + + /** + * Use specified docker network during build + */ + @ConfigItem + public Optional dockerNetwork; + /** * Log level to use.. * Defaults to 'info' diff --git a/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackProcessor.java b/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackProcessor.java index 9efe801b87995..3f4c1c210c32c 100644 --- a/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackProcessor.java +++ b/extensions/container-image/container-image-buildpack/deployment/src/main/java/io/quarkus/container/image/buildpack/deployment/BuildpackProcessor.java @@ -154,6 +154,24 @@ private Map getPaths(OutputTargetBuildItem outputTarget) { return result; } + private final String getDockerHost(BuildpackConfig buildpackConfig) { + String dockerHostVal = null; + //use config if present, else try to use env var. + //use of null indicates to buildpack lib to default the value itself. + if (buildpackConfig.dockerHost.isPresent()) { + dockerHostVal = buildpackConfig.dockerHost.get(); + } else { + String dockerHostEnv = System.getenv("DOCKER_HOST"); + if (dockerHostEnv != null && !dockerHostEnv.isEmpty()) { + dockerHostVal = dockerHostEnv; + } + } + if (dockerHostVal != null) { + log.info("Using dockerHost of " + dockerHostVal); + } + return dockerHostVal; + } + private String runBuildpackBuild(BuildpackConfig buildpackConfig, ContainerImageInfoBuildItem containerImage, ContainerImageConfig containerImageConfig, @@ -196,6 +214,9 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig, .withPullRetryIncreaseSeconds(buildpackConfig.pullTimeoutIncreaseSeconds) .withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds) .withPullRetryCount(buildpackConfig.pullRetryCount) + .withDockerHost(getDockerHost(buildpackConfig)) + .withDockerNetwork(buildpackConfig.dockerNetwork.orElse(null)) + .withUseDaemon(buildpackConfig.useDaemon) .endDockerConfig() .accept(BuildConfigBuilder.class, b -> { if (isNativeBuild) { @@ -209,12 +230,6 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig, b.withRunImage(new ImageReference(buildpackConfig.runImage.get())); } - if (buildpackConfig.dockerHost.isPresent()) { - log.info("Using DockerHost of " + buildpackConfig.dockerHost.get()); - b.editDockerConfig().withDockerHost(buildpackConfig.dockerHost.get()) - .endDockerConfig(); - } - if (buildpackConfig.trustBuilderImage.isPresent()) { log.info("Setting trusted image to " + buildpackConfig.trustBuilderImage.get()); b.editPlatformConfig().withTrustBuilder(buildpackConfig.trustBuilderImage.get()) @@ -244,9 +259,8 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig, log.info("Pushing image to " + authConfig.getRegistryAddress()); Stream.concat(Stream.of(containerImage.getImage()), containerImage.getAdditionalImageTags().stream()).forEach(i -> { - //If no dockerHost is specified use empty String. The util will take care of the rest. - String dockerHost = buildpackConfig.dockerHost.orElse(""); - ResultCallback.Adapter callback = DockerClientUtils.getDockerClient(dockerHost) + ResultCallback.Adapter callback = DockerClientUtils + .getDockerClient(getDockerHost(buildpackConfig)) .pushImageCmd(i).start(); try { callback.awaitCompletion();