diff --git a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java index dba24339b4903..21182063346be 100644 --- a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java +++ b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java @@ -70,8 +70,12 @@ public void dockerBuildFromJar(DockerConfig dockerConfig, @SuppressWarnings("unused") // used to ensure that the jar has been built JarBuildItem jar) { - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } @@ -104,8 +108,12 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig, // used to ensure that the native binary has been built NativeImageBuildItem nativeImage) { - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } @@ -151,7 +159,7 @@ private String createContainerImage(ContainerImageConfig containerImageConfig, D createAdditionalTags(containerImageInfo.getImage(), containerImageInfo.getAdditionalImageTags(), dockerConfig); } - if (pushRequested || containerImageConfig.push) { + if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) { String registry = "docker.io"; if (!containerImageInfo.getRegistry().isPresent()) { log.info("No container image registry was set, so 'docker.io' will be used"); diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java index 631fb799bb175..33742d7e0e985 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibProcessor.java @@ -89,7 +89,7 @@ public AvailableContainerImageExtensionBuildItem availability() { public void appCDS(ContainerImageConfig containerImageConfig, JibConfig jibConfig, BuildProducer producer) { - if (!containerImageConfig.build && !containerImageConfig.push) { + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()) { return; } @@ -110,8 +110,10 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, JibConfig ji Optional appCDSResult, BuildProducer artifactResultProducer) { - Boolean buildContainerImage = containerImageConfig.build || buildRequest.isPresent(); - Boolean pushContainerImage = containerImageConfig.push || pushRequest.isPresent(); + Boolean buildContainerImage = containerImageConfig.isBuildExplicitlyEnabled() + || (buildRequest.isPresent() && !containerImageConfig.isBuildExplicitlyDisabled()); + Boolean pushContainerImage = containerImageConfig.isPushExplicitlyEnabled() + || (pushRequest.isPresent() && !containerImageConfig.isPushExplicitlyDisabled()); if (!buildContainerImage && !pushContainerImage) { return; } @@ -151,8 +153,10 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig List containerImageLabels, BuildProducer artifactResultProducer) { - Boolean buildContainerImage = containerImageConfig.build || buildRequest.isPresent(); - Boolean pushContainerImage = containerImageConfig.push || pushRequest.isPresent(); + Boolean buildContainerImage = containerImageConfig.isBuildExplicitlyEnabled() + || (buildRequest.isPresent() && !containerImageConfig.isBuildExplicitlyDisabled()); + Boolean pushContainerImage = containerImageConfig.isPushExplicitlyEnabled() + || (pushRequest.isPresent() && !containerImageConfig.isPushExplicitlyDisabled()); if (!buildContainerImage && !pushContainerImage) { return; } @@ -187,7 +191,7 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig, log.info("Starting container image build"); JibContainer container = jibContainerBuilder.containerize(containerizer); log.infof("%s container image %s (%s)\n", - containerImageConfig.push ? "Pushed" : "Created", + containerImageConfig.isPushExplicitlyEnabled() ? "Pushed" : "Created", container.getTargetImage(), container.getDigest()); return container; @@ -203,7 +207,7 @@ private Containerizer createContainerizer(ContainerImageConfig containerImageCon ImageReference imageReference = ImageReference.of(containerImage.getRegistry().orElse(null), containerImage.getRepository(), containerImage.getTag()); - if (pushRequested || containerImageConfig.push) { + if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) { if (!containerImageConfig.registry.isPresent()) { log.info("No container image registry was set, so 'docker.io' will be used"); } diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java index 77801f331d967..c5ac33b959450 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java @@ -222,8 +222,12 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig, JarBuildItem jar) { OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig); - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } @@ -283,8 +287,13 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig NativeImageBuildItem nativeImage) { OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig); - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java index ad4d2f9add5ff..c5e6e6361c684 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java @@ -176,8 +176,12 @@ public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerI // used to ensure that the jar has been built JarBuildItem jar) { - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } @@ -212,8 +216,12 @@ public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig contain BuildProducer artifactResultProducer, NativeImageBuildItem nativeImage) { - if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent() - && !pushRequest.isPresent()) { + if (containerImageConfig.isBuildExplicitlyDisabled()) { + return; + } + + if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() + && !buildRequest.isPresent() && !pushRequest.isPresent()) { return; } diff --git a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageConfig.java b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageConfig.java index df6d5f6de9794..f093801383318 100644 --- a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageConfig.java +++ b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageConfig.java @@ -80,13 +80,13 @@ public class ContainerImageConfig { * Whether or not a image build will be performed. */ @ConfigItem - public boolean build; + public Optional build; /** * Whether or not an image push will be performed. */ @ConfigItem - public boolean push; + public Optional push; /** * The name of the container image extension to use (e.g. docker, jib, s2i). @@ -95,6 +95,22 @@ public class ContainerImageConfig { @ConfigItem public Optional builder; + public boolean isBuildExplicitlyEnabled() { + return build.isPresent() && build.get(); + } + + public boolean isBuildExplicitlyDisabled() { + return build.isPresent() && !build.get(); + } + + public boolean isPushExplicitlyEnabled() { + return push.isPresent() && push.get(); + } + + public boolean isPushExplicitlyDisabled() { + return push.isPresent() && !push.get(); + } + /** * Since user.name which is default value can be uppercase and uppercase values are not allowed * in the repository part of image references, we need to make the username lowercase.