Skip to content

Commit

Permalink
Update to latest snowdrop buildpack platform impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
BarDweller authored and ajo1 committed Sep 19, 2024
1 parent 95ef24c commit c3d52ab
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
<strimzi-oauth.version>0.15.0</strimzi-oauth.version>
<strimzi-oauth.nimbus.version>9.41.1</strimzi-oauth.nimbus.version>
<jose4j.version>0.9.6</jose4j.version>
<java-buildpack-client.version>0.0.6</java-buildpack-client.version>
<java-buildpack-client.version>0.0.12</java-buildpack-client.version>
<org-crac.version>0.1.3</org-crac.version>
<sshd-common.version>2.12.1</sshd-common.version>
<mime4j.version>0.8.11</mime4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ public class BuildpackConfig {
/**
* The buildpacks builder image to use when building the project in jvm mode.
*/
@ConfigItem
public Optional<String> jvmBuilderImage;
@ConfigItem(defaultValue = "paketocommunity/builder-ubi-base:latest")
public String jvmBuilderImage;

/**
* The buildpacks builder image to use when building the project in jvm mode.
* The buildpacks builder image to use when building the project in native mode.
*/
@ConfigItem
public Optional<String> nativeBuilderImage;

/**
* Should the builder image be 'trusted' (use creator lifecycle)
*/
@ConfigItem
public Optional<Boolean> trustBuilderImage;

/**
* Environment key/values to pass to buildpacks.
*/
Expand All @@ -39,16 +45,29 @@ public class BuildpackConfig {
public Optional<String> runImage;

/**
* Max pull timeout for builder/run images, in seconds
* Initial pull timeout for builder/run images, in seconds
*/
@ConfigItem(defaultValue = "300")
public Integer pullTimeoutSeconds;

/**
* Increase pull timeout for builder/run images after failure, in seconds
*/
@ConfigItem(defaultValue = "15")
public Integer pullTimeoutIncreaseSeconds;

/**
* How many times to retry an image pull after a failure
*/
@ConfigItem(defaultValue = "3")
public Integer pullRetryCount;

/**
* DOCKER_HOST value to use.
*
* If not set, the env var DOCKER_HOST is used, if that is not set
* the value `unix:///var/run/docker.sock' (or 'npipe:///./pipe/docker_engine' for windows) is used.
* If not set, the env var DOCKER_HOST is used, if that is not set the platform will look for
* 'npipe:///./pipe/docker_engine' for windows, and `unix:///var/run/docker.sock' then
* `unix:///var/run/podman.sock` then `unix:///var/run/user/<uid>/podman/podman.sock` for linux
*/
@ConfigItem
public Optional<String> dockerHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.PushResponseItem;

import dev.snowdrop.buildpack.Buildpack;
import dev.snowdrop.buildpack.BuildpackBuilder;
import dev.snowdrop.buildpack.BuildConfig;
import dev.snowdrop.buildpack.BuildConfigBuilder;
import dev.snowdrop.buildpack.config.ImageReference;
import dev.snowdrop.buildpack.docker.DockerClientUtils;
import io.quarkus.container.image.deployment.ContainerImageConfig;
import io.quarkus.container.image.deployment.util.NativeBinaryUtil;
Expand Down Expand Up @@ -181,33 +182,49 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig,

if (buildContainerImage) {
log.info("Initiating Buildpack build");
Buildpack buildpack = Buildpack.builder()
.addNewFileContent(dirs.get(ProjectDirs.ROOT).toFile())
.withFinalImage(targetImageName)
int exitCode = BuildConfig.builder()
.addNewFileContentApplication(dirs.get(ProjectDirs.ROOT).toFile())
.withOutputImage(new ImageReference(targetImageName))
.withNewPlatformConfig()
.withEnvironment(envMap)
.endPlatformConfig()
.withNewLogConfig()
.withLogger(new BuildpackLogger())
.withLogLevel(buildpackConfig.logLevel)
.endLogConfig()
.withNewDockerConfig()
.withPullRetryIncreaseSeconds(buildpackConfig.pullTimeoutIncreaseSeconds)
.withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds)
.withLogger(new BuildpackLogger())
.accept(BuildpackBuilder.class, b -> {

.withPullRetryCount(buildpackConfig.pullRetryCount)
.endDockerConfig()
.accept(BuildConfigBuilder.class, b -> {
if (isNativeBuild) {
buildpackConfig.nativeBuilderImage.ifPresent(i -> b.withBuilderImage(i));
buildpackConfig.nativeBuilderImage.ifPresent(i -> b.withBuilderImage(new ImageReference(i)));
} else {
buildpackConfig.jvmBuilderImage.ifPresent(i -> b.withBuilderImage(i));
b.withBuilderImage(new ImageReference(buildpackConfig.jvmBuilderImage));
}

if (buildpackConfig.runImage.isPresent()) {
log.info("Using Run image of " + buildpackConfig.runImage.get());
b.withRunImage(buildpackConfig.runImage.get());
b.withRunImage(new ImageReference(buildpackConfig.runImage.get()));
}

if (buildpackConfig.dockerHost.isPresent()) {
log.info("Using DockerHost of " + buildpackConfig.dockerHost.get());
b.withDockerHost(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())
.endPlatformConfig();
}
})
.build()
.getExitCode();

}).build();

if (buildpack.getExitCode() != 0) {
if (exitCode != 0) {
throw new IllegalStateException("Buildpack build failed");
}

Expand Down

0 comments on commit c3d52ab

Please sign in to comment.