From be83da63baee1fd5ceaa843c6fdf1bf477febe20 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 26 Jul 2022 12:16:14 +0300 Subject: [PATCH 1/3] Apply minor polish to container image build classes --- .../container/image/openshift/deployment/OpenshiftBuild.java | 2 +- .../io/quarkus/container/image/s2i/deployment/S2iBuild.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java index 8956edbf3e03e..32ce09e05fcff 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftBuild.java @@ -6,7 +6,7 @@ public class OpenshiftBuild implements BooleanSupplier { - private ContainerImageConfig containerImageConfig; + private final ContainerImageConfig containerImageConfig; OpenshiftBuild(ContainerImageConfig containerImageConfig) { this.containerImageConfig = containerImageConfig; diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java index 9feb35ca3e96c..7ac85ef0ad4e1 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iBuild.java @@ -6,7 +6,7 @@ public class S2iBuild implements BooleanSupplier { - private ContainerImageConfig containerImageConfig; + private final ContainerImageConfig containerImageConfig; S2iBuild(ContainerImageConfig containerImageConfig) { this.containerImageConfig = containerImageConfig; From c712bf1a35dd7ea433fb4318ed91f2b314d19c72 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 26 Jul 2022 12:20:11 +0300 Subject: [PATCH 2/3] Use Java 11 construct for creating Map --- .../ContainerImageCapabilitiesUtil.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java index d7591e4824036..6a42d6c13cc76 100644 --- a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java +++ b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java @@ -1,6 +1,5 @@ package io.quarkus.container.image.deployment; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; @@ -11,14 +10,12 @@ public final class ContainerImageCapabilitiesUtil { - public final static Map CAPABILITY_TO_EXTENSION_NAME = new HashMap<>(); - static { - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_JIB, "quarkus-container-image-jib"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_DOCKER, "quarkus-container-image-docker"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_S2I, "quarkus-container-image-s2i"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_OPENSHIFT, "quarkus-container-image-openshift"); - CAPABILITY_TO_EXTENSION_NAME.put(Capability.CONTAINER_IMAGE_BUILDPACK, "quarkus-container-image-buildpack"); - } + public final static Map CAPABILITY_TO_EXTENSION_NAME = Map.of( + Capability.CONTAINER_IMAGE_JIB, "quarkus-container-image-jib", + Capability.CONTAINER_IMAGE_DOCKER, "quarkus-container-image-docker", + Capability.CONTAINER_IMAGE_S2I, "quarkus-container-image-s2i", + Capability.CONTAINER_IMAGE_OPENSHIFT, "quarkus-container-image-openshift", + Capability.CONTAINER_IMAGE_BUILDPACK, "quarkus-container-image-buildpack"); private ContainerImageCapabilitiesUtil() { } From 3f0ec53efd77ae9dffb90c5ac075c3714cb0518a Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 26 Jul 2022 12:37:31 +0300 Subject: [PATCH 3/3] Improve error message when multiple container image extensions are present Closes: #26789 --- .../ContainerImageCapabilitiesUtil.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java index 6a42d6c13cc76..c07c9b483f242 100644 --- a/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java +++ b/extensions/container-image/deployment/src/main/java/io/quarkus/container/image/deployment/ContainerImageCapabilitiesUtil.java @@ -17,6 +17,13 @@ public final class ContainerImageCapabilitiesUtil { Capability.CONTAINER_IMAGE_OPENSHIFT, "quarkus-container-image-openshift", Capability.CONTAINER_IMAGE_BUILDPACK, "quarkus-container-image-buildpack"); + private final static Map CAPABILITY_TO_BUILDER_NAME = Map.of( + Capability.CONTAINER_IMAGE_JIB, "jib", + Capability.CONTAINER_IMAGE_DOCKER, "docker", + Capability.CONTAINER_IMAGE_S2I, "s2i", + Capability.CONTAINER_IMAGE_OPENSHIFT, "openshift", + Capability.CONTAINER_IMAGE_BUILDPACK, "buildpack"); + private ContainerImageCapabilitiesUtil() { } @@ -29,16 +36,34 @@ public static Optional getActiveContainerImageCapability(Capabilities ca if (activeContainerImageCapabilities.size() > 1) { throw new IllegalStateException(String.join(" and ", activeContainerImageCapabilities) + " were detected, at most one container-image extension can be present.\n" - + "Either remove the unneeded ones, or select one by adding the property 'quarkus.container-image.builder=' in application.properties or as a system property."); + + "Either remove the unneeded ones, or select one by setting any of the following configuration properties: " + + createBuilderSelectionPropertySuggestion(capabilities)); } return activeContainerImageCapabilities.isEmpty() ? Optional.empty() : Optional.of(activeContainerImageCapabilities.iterator().next()); } + private static StringBuilder createBuilderSelectionPropertySuggestion(Capabilities capabilities) { + StringBuilder suggestion = new StringBuilder(); + boolean isFirst = true; + for (String capability : capabilities.getCapabilities()) { + if (!isContainerImageCapability(capability)) { + continue; + } + if (!isFirst) { + suggestion.append(", "); + } + isFirst = false; + suggestion.append('\'').append("quarkus.container-image.builder=") + .append(CAPABILITY_TO_BUILDER_NAME.get(capability)).append('\''); + } + return suggestion; + } + private static Set getContainerImageCapabilities(Capabilities capabilities) { Set activeContainerImageCapabilities = new HashSet<>(); for (String capability : capabilities.getCapabilities()) { - if (capability.toLowerCase().contains("container.image")) { + if (isContainerImageCapability(capability)) { if (!CAPABILITY_TO_EXTENSION_NAME.containsKey(capability)) { throw new IllegalArgumentException("Unknown container image capability: " + capability); } @@ -47,4 +72,8 @@ private static Set getContainerImageCapabilities(Capabilities capabiliti } return activeContainerImageCapabilities; } + + private static boolean isContainerImageCapability(String capability) { + return capability.toLowerCase().contains("container.image"); + } }