Skip to content

Commit

Permalink
Update Docker Config Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BarDweller committed Nov 18, 2024
1 parent 2dd6ae6 commit 7b9d7a0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ public class BuildpackConfig {
@ConfigItem
public Optional<String> dockerHost;

/**
* use Daemon mode?
* Defaults to 'true'
*/
@ConfigItem(defaultValue = "true")
public Boolean useDaemon;

/**
* Use specified docker network during build
*/
@ConfigItem
public Optional<String> dockerNetwork;

/**
* Log level to use..
* Defaults to 'info'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ private Map<ProjectDirs, Path> 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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
Expand Down Expand Up @@ -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<PushResponseItem> callback = DockerClientUtils.getDockerClient(dockerHost)
ResultCallback.Adapter<PushResponseItem> callback = DockerClientUtils
.getDockerClient(getDockerHost(buildpackConfig))
.pushImageCmd(i).start();
try {
callback.awaitCompletion();
Expand Down

0 comments on commit 7b9d7a0

Please sign in to comment.