From cd05ced27ea09f3edf44a57b2fe3f07991e9d93c Mon Sep 17 00:00:00 2001 From: Ozzy Osborne Date: Wed, 14 Aug 2024 14:39:15 -0400 Subject: [PATCH] Update to latest Snowdrop Buildpack Platform Impl. --- bom/application/pom.xml | 2 +- .../buildpack/deployment/BuildpackConfig.java | 31 ++++++++++--- .../deployment/BuildpackProcessor.java | 46 +++++++++++++------ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/bom/application/pom.xml b/bom/application/pom.xml index bf2f52cafc159..87d22a7fe4bc7 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -211,7 +211,7 @@ 0.15.0 9.40 0.9.6 - 0.0.6 + 0.0.11 0.1.3 2.12.1 0.8.11 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 d5ff64ec4c910..1675944ee7c16 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 @@ -14,15 +14,21 @@ public class BuildpackConfig { /** * The buildpacks builder image to use when building the project in jvm mode. */ - @ConfigItem - public Optional jvmBuilderImage; + @ConfigItem(defaultValue = "paketocommunity/builder-ubi-base") + 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 nativeBuilderImage; + /** + * Should the builder image be 'trusted' (use creator lifecycle) + */ + @ConfigItem + public Optional trustBuilderImage; + /** * Environment key/values to pass to buildpacks. */ @@ -39,16 +45,29 @@ public class BuildpackConfig { public Optional 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//podman/podman.sock` for linux */ @ConfigItem public Optional dockerHost; 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 b40283807e712..faf3fec95bda5 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 @@ -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; @@ -181,33 +182,50 @@ 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) + .and() + .withNewLogConfig() + .withLogger(new BuildpackLogger()) .withLogLevel(buildpackConfig.logLevel) + .and() + .withNewDockerConfig() + .withPullRetryIncreaseSeconds(buildpackConfig.pullTimeoutIncreaseSeconds) .withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds) - .withLogger(new BuildpackLogger()) - .accept(BuildpackBuilder.class, b -> { - + .withPullRetryCount(buildpackConfig.pullRetryCount) + .and() + .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(); } - }).build(); + if (buildpackConfig.trustBuilderImage.isPresent()) { + log.info("Setting trusted image to " + buildpackConfig.trustBuilderImage.get()); + b.editPlatformConfig().withTrustBuilder(buildpackConfig.trustBuilderImage.get()) + .endPlatformConfig(); + } + }) + .build() + .getExitCode(); - if (buildpack.getExitCode() != 0) { + if (exitCode != 0) { throw new IllegalStateException("Buildpack build failed"); }