Skip to content

Commit

Permalink
Merge pull request #45400 from mcruzdev/config-container-image-buildpack
Browse files Browse the repository at this point in the history
Convert container-image-buildpack to @ConfigMapping
  • Loading branch information
geoand authored Jan 7, 2025
2 parents 6fa7852 + 85af070 commit ea41300
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,61 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigDocMapKey;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public class BuildpackConfig {
@ConfigMapping(prefix = "quarkus.buildpack")
public interface BuildpackConfig {

/**
* The buildpacks builder image to use when building the project in jvm mode.
*/
@ConfigItem(defaultValue = "paketocommunity/builder-ubi-base:latest")
public String jvmBuilderImage;
@WithDefault("paketocommunity/builder-ubi-base:latest")
String jvmBuilderImage();

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

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

/**
* Environment key/values to pass to buildpacks.
*/
@ConfigItem
@ConfigDocMapKey("environment-variable-name")
public Map<String, String> builderEnv;
Map<String, String> builderEnv();

/**
* The buildpacks run image to use when building the project
*
* When not supplied, the run image is determined by the builder image.
*/
@ConfigItem
public Optional<String> runImage;
Optional<String> runImage();

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

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

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

/**
* DOCKER_HOST value to use.
Expand All @@ -69,39 +67,35 @@ public class BuildpackConfig {
* '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;
Optional<String> dockerHost();

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

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

/**
* Log level to use..
* Log level to use.
* Defaults to 'info'
*/
@ConfigItem(defaultValue = "info")
public String logLevel;
@WithDefault("info")
String logLevel();

/**
* The username to use to authenticate with the registry used to pull the base JVM image
*/
@ConfigItem
public Optional<String> baseRegistryUsername;
Optional<String> baseRegistryUsername();

/**
* The password to use to authenticate with the registry used to pull the base JVM image
*/
@ConfigItem
public Optional<String> baseRegistryPassword;
Optional<String> baseRegistryPassword();

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ 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();
if (buildpackConfig.dockerHost().isPresent()) {
dockerHostVal = buildpackConfig.dockerHost().get();
} else {
String dockerHostEnv = System.getenv("DOCKER_HOST");
if (dockerHostEnv != null && !dockerHostEnv.isEmpty()) {
Expand Down Expand Up @@ -189,7 +189,7 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig,
String targetImageName = containerImage.getImage();
log.debug("Using Destination image of " + targetImageName);

Map<String, String> envMap = new HashMap<>(buildpackConfig.builderEnv);
Map<String, String> envMap = new HashMap<>(buildpackConfig.builderEnv());
if (!envMap.isEmpty()) {
log.info("Using builder environment of " + envMap);
}
Expand All @@ -208,31 +208,31 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig,
.endPlatformConfig()
.withNewLogConfig()
.withLogger(new BuildpackLogger())
.withLogLevel(buildpackConfig.logLevel)
.withLogLevel(buildpackConfig.logLevel())
.endLogConfig()
.withNewDockerConfig()
.withPullRetryIncreaseSeconds(buildpackConfig.pullTimeoutIncreaseSeconds)
.withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds)
.withPullRetryCount(buildpackConfig.pullRetryCount)
.withPullRetryIncreaseSeconds(buildpackConfig.pullTimeoutIncreaseSeconds())
.withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds())
.withPullRetryCount(buildpackConfig.pullRetryCount())
.withDockerHost(getDockerHost(buildpackConfig))
.withDockerNetwork(buildpackConfig.dockerNetwork.orElse(null))
.withUseDaemon(buildpackConfig.useDaemon)
.withDockerNetwork(buildpackConfig.dockerNetwork().orElse(null))
.withUseDaemon(buildpackConfig.useDaemon())
.endDockerConfig()
.accept(BuildConfigBuilder.class, b -> {
if (isNativeBuild) {
buildpackConfig.nativeBuilderImage.ifPresent(i -> b.withBuilderImage(new ImageReference(i)));
buildpackConfig.nativeBuilderImage().ifPresent(i -> b.withBuilderImage(new ImageReference(i)));
} else {
b.withBuilderImage(new ImageReference(buildpackConfig.jvmBuilderImage));
b.withBuilderImage(new ImageReference(buildpackConfig.jvmBuilderImage()));
}

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

if (buildpackConfig.trustBuilderImage.isPresent()) {
log.info("Setting trusted image to " + buildpackConfig.trustBuilderImage.get());
b.editPlatformConfig().withTrustBuilder(buildpackConfig.trustBuilderImage.get())
if (buildpackConfig.trustBuilderImage().isPresent()) {
log.info("Setting trusted image to " + buildpackConfig.trustBuilderImage().get());
b.editPlatformConfig().withTrustBuilder(buildpackConfig.trustBuilderImage().get())
.endPlatformConfig();
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down

0 comments on commit ea41300

Please sign in to comment.