Skip to content

Commit

Permalink
Container Image - Finalize switch to @ConfigMapping
Browse files Browse the repository at this point in the history
There was some remaining config for container-image-s2i (extension
removed a while ago) and I got rid of it.

Part of quarkusio#45446
  • Loading branch information
gsmet committed Feb 4, 2025
1 parent 305e9e7 commit 7b130b0
Show file tree
Hide file tree
Showing 26 changed files with 153 additions and 484 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public BuildpackBuild(ContainerImageConfig containerImageConfig) {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(BuildpackProcessor.BUILDPACK)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(BuildpackProcessor.BUILDPACK)).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class BuildpackBuildEnabled implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(BuildpackProcessor.BUILDPACK)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(BuildpackProcessor.BUILDPACK)).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private String runBuildpackBuild(BuildpackConfig buildpackConfig,
});
AuthConfig authConfig = new AuthConfig();
authConfig.withRegistryAddress(registry);
containerImageConfig.username.ifPresent(u -> authConfig.withUsername(u));
containerImageConfig.password.ifPresent(p -> authConfig.withPassword(p));
containerImageConfig.username().ifPresent(u -> authConfig.withUsername(u));
containerImageConfig.password().ifPresent(p -> authConfig.withPassword(p));

log.info("Pushing image to " + authConfig.getRegistryAddress());
Stream.concat(Stream.of(containerImage.getImage()), containerImage.getAdditionalImageTags().stream()).forEach(i -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ protected void loginToRegistryIfNeeded(ContainerImageConfig containerImageConfig
});

// Check if we need to login first
if (containerImageConfig.username.isPresent() && containerImageConfig.password.isPresent()) {
var loginSuccessful = ExecUtil.exec(executableName, "login", registry, "-u", containerImageConfig.username.get(),
"-p", containerImageConfig.password.get());
if (containerImageConfig.username().isPresent() && containerImageConfig.password().isPresent()) {
var loginSuccessful = ExecUtil.exec(executableName, "login", registry, "-u", containerImageConfig.username().get(),
"-p", containerImageConfig.password().get());

if (!loginSuccessful) {
throw containerRuntimeException(executableName,
new String[] { "-u", containerImageConfig.username.get(), "-p", "********" });
new String[] { "-u", containerImageConfig.username().get(), "-p", "********" });
}
}
}
Expand All @@ -184,7 +184,7 @@ protected List<String> getContainerCommonBuildArgs(String image,
args.addAll(List.of("build", "-f", dockerfilePaths.dockerfilePath().toAbsolutePath().toString()));

config.buildArgs().forEach((k, v) -> args.addAll(List.of("--build-arg", "%s=%s".formatted(k, v))));
containerImageConfig.labels.forEach((k, v) -> args.addAll(List.of("--label", "%s=%s".formatted(k, v))));
containerImageConfig.labels().forEach((k, v) -> args.addAll(List.of("--label", "%s=%s".formatted(k, v))));
config.cacheFrom()
.filter(cacheFrom -> !cacheFrom.isEmpty())
.ifPresent(cacheFrom -> args.addAll(List.of("--cache-from", String.join(",", cacheFrom))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class DockerBuild implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(DockerProcessor.DOCKER_CONTAINER_IMAGE_NAME)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(DockerProcessor.DOCKER_CONTAINER_IMAGE_NAME)).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public JibBuild(ContainerImageConfig containerImageConfig) {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(JibProcessor.JIB)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(JibProcessor.JIB)).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public class JibBuildEnabled implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(JibProcessor.JIB)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(JibProcessor.JIB)).orElse(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ private Containerizer createContainerizer(ContainerImageConfig containerImageCon
if (imageReference.getRegistry() == null) {
log.info("No container image registry was set, so 'docker.io' will be used");
}
RegistryImage registryImage = toRegistryImage(imageReference, containerImageConfig.username,
containerImageConfig.password);
RegistryImage registryImage = toRegistryImage(imageReference, containerImageConfig.username(),
containerImageConfig.password());
containerizer = Containerizer.to(registryImage);
} else {
DockerDaemonImage dockerDaemonImage = DockerDaemonImage.named(imageReference);
Expand All @@ -296,7 +296,7 @@ private Containerizer createContainerizer(ContainerImageConfig containerImageCon
log.log(toJBossLoggingLevel(e.getLevel()), e.getMessage());
}
});
containerizer.setAllowInsecureRegistries(containerImageConfig.insecure);
containerizer.setAllowInsecureRegistries(containerImageConfig.insecure());
containerizer.setAlwaysCacheBaseImage(jibConfig.alwaysCacheBaseImage());
containerizer.setOfflineMode(jibConfig.offlineMode());
jibConfig.baseImageLayersCache().ifPresent(cacheDir -> containerizer.setBaseImageLayersCache(Paths.get(cacheDir)));
Expand Down Expand Up @@ -867,11 +867,11 @@ private void handleExtraFiles(OutputTargetBuildItem outputTarget, JibContainerBu

private Map<String, String> allLabels(ContainerImageJibConfig jibConfig, ContainerImageConfig containerImageConfig,
List<ContainerImageLabelBuildItem> containerImageLabels) {
if (containerImageLabels.isEmpty() && containerImageConfig.labels.isEmpty()) {
if (containerImageLabels.isEmpty() && containerImageConfig.labels().isEmpty()) {
return Collections.emptyMap();
}

final Map<String, String> allLabels = new HashMap<>(containerImageConfig.labels);
final Map<String, String> allLabels = new HashMap<>(containerImageConfig.labels());
for (ContainerImageLabelBuildItem containerImageLabel : containerImageLabels) {
// we want the user supplied labels to take precedence so the user can override labels generated from other extensions if desired
allLabels.putIfAbsent(containerImageLabel.getName(), containerImageLabel.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,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 @@ -9,12 +9,14 @@

import io.quarkus.deployment.images.ContainerImages;
import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem;
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(name = "openshift", phase = ConfigPhase.BUILD_TIME)
public class ContainerImageOpenshiftConfig {
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
@ConfigMapping(prefix = "quarkus.openshift")
public interface ContainerImageOpenshiftConfig {

public static final String DEFAULT_NATIVE_TARGET_FILENAME = "application";

Expand All @@ -36,8 +38,8 @@ public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion
/**
* The build config strategy to use.
*/
@ConfigItem(defaultValue = "binary")
public BuildStrategy buildStrategy;
@WithDefault("binary")
BuildStrategy buildStrategy();

/**
* The base image to be used when a container image is being produced for the jar build.
Expand All @@ -48,131 +50,123 @@ public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion
* is used as the default.
* Otherwise {@code registry.access.redhat.com/ubi8/openjdk-17:1.20} is used as the default.
*/
@ConfigItem
public Optional<String> baseJvmImage;
Optional<String> baseJvmImage();

/**
* The base image to be used when a container image is being produced for the native binary build.
* The value of this property is used to create an ImageStream for the builder image used in the Openshift build.
* When it references images already available in the internal Openshift registry, the corresponding streams are used
* instead.
*/
@ConfigItem(defaultValue = ContainerImages.QUARKUS_BINARY_S2I)
public String baseNativeImage;
@WithDefault(ContainerImages.QUARKUS_BINARY_S2I)
String baseNativeImage();

/**
* The default Dockerfile to use for jvm builds
*/
@ConfigItem(defaultValue = DEFAULT_JVM_DOCKERFILE)
public String jvmDockerfile;
@WithDefault(DEFAULT_JVM_DOCKERFILE)
String jvmDockerfile();

/**
* The default Dockerfile to use for native builds
*/
@ConfigItem(defaultValue = DEFAULT_NATIVE_DOCKERFILE)
public String nativeDockerfile;
@WithDefault(DEFAULT_NATIVE_DOCKERFILE)
String nativeDockerfile();

/**
* The JVM arguments to pass to the JVM when starting the application
*/
@ConfigItem
public Optional<List<String>> jvmArguments;
Optional<List<String>> jvmArguments();

/**
* Additional arguments to pass when starting the native application
*/
@ConfigItem
public Optional<List<String>> nativeArguments;
Optional<List<String>> nativeArguments();

/**
* The directory where the jar is added during the assemble phase.
* This is dependent on the S2I image and should be supplied if a non default image is used.
*/
@ConfigItem
public Optional<String> jarDirectory;
Optional<String> jarDirectory();

/**
* The resulting filename of the jar in the S2I image.
* This option may be used if the selected S2I image uses a fixed name for the jar.
*/
@ConfigItem
public Optional<String> jarFileName;
Optional<String> jarFileName();

/**
* The directory where the native binary is added during the assemble phase.
* This is dependent on the S2I image and should be supplied if a non-default image is used.
*/
@ConfigItem
public Optional<String> nativeBinaryDirectory;
Optional<String> nativeBinaryDirectory();

/**
* The resulting filename of the native binary in the S2I image.
* This option may be used if the selected S2I image uses a fixed name for the native binary.
*/
@ConfigItem
public Optional<String> nativeBinaryFileName;
Optional<String> nativeBinaryFileName();

/**
* The build timeout.
*/
@ConfigItem(defaultValue = "PT5M")
Duration buildTimeout;
@WithDefault("PT5M")
Duration buildTimeout();

/**
* The log level of OpenShift build log.
*/
@ConfigItem(defaultValue = DEFAULT_BUILD_LOG_LEVEL)
public Logger.Level buildLogLevel;
@WithDefault(DEFAULT_BUILD_LOG_LEVEL)
Logger.Level buildLogLevel();

/**
* The image push secret to use for pushing to external registries.
* (see: https://cloud.redhat.com/blog/pushing-application-images-to-an-external-registry)
**/
@ConfigItem
public Optional<String> imagePushSecret;
Optional<String> imagePushSecret();

/**
* Check if baseJvmImage is the default
*
* @returns true if baseJvmImage is the default
*/
public boolean hasDefaultBaseJvmImage() {
return baseJvmImage.isPresent();
default boolean hasDefaultBaseJvmImage() {
return baseJvmImage().isPresent();
}

/**
* Check if baseNativeImage is the default
*
* @returns true if baseNativeImage is the default
*/
public boolean hasDefaultBaseNativeImage() {
return baseNativeImage.equals(ContainerImages.QUARKUS_BINARY_S2I);
default boolean hasDefaultBaseNativeImage() {
return baseNativeImage().equals(ContainerImages.QUARKUS_BINARY_S2I);
}

/**
* Check if jvmDockerfile is the default
*
* @returns true if jvmDockerfile is the default
*/
public boolean hasDefaultJvmDockerfile() {
return jvmDockerfile.equals(DEFAULT_JVM_DOCKERFILE);
default boolean hasDefaultJvmDockerfile() {
return jvmDockerfile().equals(DEFAULT_JVM_DOCKERFILE);
}

/**
* Check if nativeDockerfile is the default
*
* @returns true if nativeDockerfile is the default
*/
public boolean hasDefaultNativeDockerfile() {
return nativeDockerfile.equals(DEFAULT_NATIVE_DOCKERFILE);
default boolean hasDefaultNativeDockerfile() {
return nativeDockerfile().equals(DEFAULT_NATIVE_DOCKERFILE);
}

/**
* @return the effective JVM arguments to use by getting the jvmArguments and the jvmAdditionalArguments properties.
*/
public List<String> getEffectiveJvmArguments() {
default List<String> getEffectiveJvmArguments() {
List<String> effectiveJvmArguments = new ArrayList<>();
jvmArguments.ifPresent(effectiveJvmArguments::addAll);
jvmArguments().ifPresent(effectiveJvmArguments::addAll);
return effectiveJvmArguments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class OpenshiftBuild implements BooleanSupplier {

@Override
public boolean getAsBoolean() {
return containerImageConfig.builder.map(b -> b.equals(OpenshiftProcessor.OPENSHIFT)).orElse(true);
return containerImageConfig.builder().map(b -> b.equals(OpenshiftProcessor.OPENSHIFT)).orElse(true);
}
}
Loading

0 comments on commit 7b130b0

Please sign in to comment.