From ddcf8c1f848cade8f3a12cda88ac0d20792ea579 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Thu, 2 Jul 2020 20:07:30 +0300 Subject: [PATCH 1/3] feat: Allow choosing container image extension --- .../image/docker/deployment/DockerBuild.java | 20 +++++++++++++++++++ .../docker/deployment/DockerProcessor.java | 8 ++++---- .../image/jib/deployment/JibBuild.java | 2 +- .../image/jib/deployment/JibBuildEnabled.java | 20 +++++++++++++++++++ .../image/jib/deployment/JibProcessor.java | 4 ++-- .../image/s2i/deployment/S2iBuild.java | 2 +- .../image/s2i/deployment/S2iProcessor.java | 8 ++++---- .../deployment/ContainerImageConfig.java | 7 +++++++ 8 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerBuild.java create mode 100644 extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuildEnabled.java diff --git a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerBuild.java b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerBuild.java new file mode 100644 index 0000000000000..df2b94c3378ca --- /dev/null +++ b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerBuild.java @@ -0,0 +1,20 @@ + +package io.quarkus.container.image.docker.deployment; + +import java.util.function.BooleanSupplier; + +import io.quarkus.container.image.deployment.ContainerImageConfig; + +public class DockerBuild implements BooleanSupplier { + + private final ContainerImageConfig containerImageConfig; + + DockerBuild(ContainerImageConfig containerImageConfig) { + this.containerImageConfig = containerImageConfig; + } + + @Override + public boolean getAsBoolean() { + return containerImageConfig.builder.map(b -> b.equals(DockerProcessor.DOCKER)).orElse(true); + } +} 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 58365f88a17ae..dc4c84ab46aa0 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 @@ -43,20 +43,20 @@ public class DockerProcessor { private static final Logger log = Logger.getLogger(DockerProcessor.class); - private static final String DOCKER = "docker"; private static final String DOCKERFILE_JVM = "Dockerfile.jvm"; private static final String DOCKERFILE_FAST_JAR = "Dockerfile.fast-jar"; private static final String DOCKERFILE_NATIVE = "Dockerfile.native"; public static final String DOCKER_BINARY_NAME = "docker"; + public static final String DOCKER = "docker"; private final DockerWorking dockerWorking = new DockerWorking(); - @BuildStep + @BuildStep(onlyIf = DockerBuild.class) public CapabilityBuildItem capability() { return new CapabilityBuildItem(Capability.CONTAINER_IMAGE_DOCKER); } - @BuildStep(onlyIf = { IsNormal.class }, onlyIfNot = NativeBuild.class) + @BuildStep(onlyIf = { IsNormal.class, DockerBuild.class }, onlyIfNot = NativeBuild.class) public void dockerBuildFromJar(DockerConfig dockerConfig, ContainerImageConfig containerImageConfig, // TODO: use to check whether we need to also push to registry OutputTargetBuildItem out, @@ -89,7 +89,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig, artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap())); } - @BuildStep(onlyIf = { IsNormal.class, NativeBuild.class }) + @BuildStep(onlyIf = { IsNormal.class, NativeBuild.class, DockerBuild.class }) public void dockerBuildFromNativeImage(DockerConfig dockerConfig, ContainerImageConfig containerImageConfig, ContainerImageInfoBuildItem containerImage, diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuild.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuild.java index 90fa0a49d92bb..6e25a5c0ae0a3 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuild.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuild.java @@ -14,6 +14,6 @@ public JibBuild(ContainerImageConfig containerImageConfig) { @Override public boolean getAsBoolean() { - return true; + return containerImageConfig.builder.map(b -> b.equals(JibProcessor.JIB)).orElse(true); } } diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuildEnabled.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuildEnabled.java new file mode 100644 index 0000000000000..4412c5d4d4d0f --- /dev/null +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibBuildEnabled.java @@ -0,0 +1,20 @@ + +package io.quarkus.container.image.jib.deployment; + +import java.util.function.BooleanSupplier; + +import io.quarkus.container.image.deployment.ContainerImageConfig; + +public class JibBuildEnabled implements BooleanSupplier { + + private final ContainerImageConfig containerImageConfig; + + JibBuildEnabled(ContainerImageConfig containerImageConfig) { + this.containerImageConfig = containerImageConfig; + } + + @Override + public boolean getAsBoolean() { + return containerImageConfig.builder.map(b -> b.equals(JibProcessor.JIB)).orElse(true); + } +} 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 a55aba907f7c7..344ec2b8fd77b 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 @@ -61,11 +61,11 @@ public class JibProcessor { private static final Logger log = Logger.getLogger(JibProcessor.class); - private static final String JIB = "jib"; + public static final String JIB = "jib"; private static final IsClassPredicate IS_CLASS_PREDICATE = new IsClassPredicate(); private static final String BINARY_NAME_IN_CONTAINER = "application"; - @BuildStep + @BuildStep(onlyIf = JibBuild.class) public CapabilityBuildItem capability() { return new CapabilityBuildItem(Capability.CONTAINER_IMAGE_JIB); } 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 a1b88d0515f92..9feb35ca3e96c 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 @@ -14,6 +14,6 @@ public class S2iBuild implements BooleanSupplier { @Override public boolean getAsBoolean() { - return true; + return containerImageConfig.builder.map(b -> b.equals(S2iProcessor.S2I)).orElse(true); } } 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 bfbc8e127e844..14f672468fd91 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 @@ -53,19 +53,19 @@ public class S2iProcessor { - private static final String S2I = "s2i"; + public static final String S2I = "s2i"; private static final String OPENSHIFT = "openshift"; private static final String BUILD_CONFIG_NAME = "openshift.io/build-config.name"; private static final String RUNNING = "Running"; private static final Logger LOG = Logger.getLogger(S2iProcessor.class); - @BuildStep + @BuildStep(onlyIf = S2iBuild.class) public CapabilityBuildItem capability() { return new CapabilityBuildItem(Capability.CONTAINER_IMAGE_S2I); } - @BuildStep(onlyIf = IsNormal.class, onlyIfNot = NativeBuild.class) + @BuildStep(onlyIf = { IsNormal.class, S2iBuild.class }, onlyIfNot = NativeBuild.class) public void s2iRequirementsJvm(S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, @@ -106,7 +106,7 @@ public void s2iRequirementsJvm(S2iConfig s2iConfig, } } - @BuildStep(onlyIf = { IsNormal.class, NativeBuild.class }) + @BuildStep(onlyIf = { IsNormal.class, S2iBuild.class, NativeBuild.class }) public void s2iRequirementsNative(S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, 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 9cc0e047e67ce..edc379e8753e4 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 @@ -69,6 +69,13 @@ public class ContainerImageConfig { @ConfigItem public boolean push; + /** + * The name of the container image extension to use (e.g. docker, jib, s2i). + * The option will be used in case multiple extensions are present. + */ + @ConfigItem + public Optional builder; + /** * 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. From 96298fe80f3ed6e1ba6e51c62d8ab0662a0acb26 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Thu, 2 Jul 2020 20:08:13 +0300 Subject: [PATCH 2/3] feat: disable s2i when the capability is mising. --- docs/src/main/asciidoc/container-image.adoc | 11 ++++ .../main/asciidoc/deploying-to-openshift.adoc | 25 +++++++- .../ContainerImageCapabilitiesUtil.java | 3 +- .../deployment/KubernetesProcessor.java | 28 +++++++++ .../deployment/RemoveEnvVarDecorator.java | 58 +++++++++++++++++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/RemoveEnvVarDecorator.java diff --git a/docs/src/main/asciidoc/container-image.adoc b/docs/src/main/asciidoc/container-image.adoc index 7a54789b325ad..a4a0da120f0c4 100644 --- a/docs/src/main/asciidoc/container-image.adoc +++ b/docs/src/main/asciidoc/container-image.adoc @@ -91,6 +91,17 @@ To push a container image for your project, `quarkus.container-image.push=true` NOTE: If no registry is set (using `quarkus.container-image.registry`) then `docker.io` will be used as the default. +== Selecting among multiple extensions + +It does not make sense to use multiple extension as part of the same build. When multiple container image extensions are present, an error will be raised to inform the user. The user can either remove the uneeded extensions or select one using `application.properties`. + +For example, if both `container-image-docker` and `container-image-s2i` are present and the user needs to use `container-image-docker`: + +[source] +---- +quarkus.container-image.builder=docker +---- + == Customizing The following properties can be used to customize the container image build process. diff --git a/docs/src/main/asciidoc/deploying-to-openshift.adoc b/docs/src/main/asciidoc/deploying-to-openshift.adoc index 85ea788b27aef..543721836edf0 100644 --- a/docs/src/main/asciidoc/deploying-to-openshift.adoc +++ b/docs/src/main/asciidoc/deploying-to-openshift.adoc @@ -65,7 +65,30 @@ Building is handled by the link:container-image#s2i[container-image-s2i] extensi ./mvnw clean package -Dquarkus.container-image.build=true ---- -The command above will trigger an s2i binary build. +The build that will be performed is an s2i binary build. The input of the build is the jar that has been built locally and the output of the build is an ImageStream that is configured to automatically trigger a deployment. + +=== Non S2i Builds + +Out of the box the openshift extension is configured to use link:container-image#s2i[container-image-s2i]. However, it's still possible to use other container image extensions like: + +- link:container-image#s2i[container-image-docker] +- link:container-image#s2i[container-image-jib] + +When a non-s2i container image extension is used, an ImageStream is created that is pointing to an external `dockerImageRepository`. The image is built and pushed to the registry and the ImageStream populates the tags that are available in the `dockerImageRepository`. + +To select which extension will be used for building the image: + +[source] +--- +quarkus.container-image.builder=docker +--- + +or + +[source] +--- +quarkus.container-image.builder=jib +--- === Deploying 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 c719c72bdea0b..6177d54c7e016 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 @@ -29,7 +29,8 @@ public static Optional getActiveContainerImageCapability(Capabilities ca .getContainerImageCapabilities(capabilities); if (activeContainerImageCapabilities.size() > 1) { throw new IllegalStateException(String.join(" and ", activeContainerImageCapabilities) - + " were detected, at most one container-image extension can be present. "); + + " were detected, at most one container-image extension can be present.\n" + + "Either remove the uneeded ones, or select one using the property 'quarkus.container-image-builder='."); } return activeContainerImageCapabilities.isEmpty() ? Optional.empty() : Optional.of(activeContainerImageCapabilities.iterator().next()); diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java index 81dfebea0e5aa..70d9d2fef82b6 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KubernetesProcessor.java @@ -65,7 +65,9 @@ import io.dekorate.kubernetes.annotation.ImagePullPolicy; import io.dekorate.kubernetes.annotation.ServiceType; import io.dekorate.kubernetes.config.Annotation; +import io.dekorate.kubernetes.config.Configurator; import io.dekorate.kubernetes.config.EnvBuilder; +import io.dekorate.kubernetes.config.ImageConfigurationFluent; import io.dekorate.kubernetes.config.Label; import io.dekorate.kubernetes.config.LabelBuilder; import io.dekorate.kubernetes.config.PortBuilder; @@ -103,6 +105,7 @@ import io.dekorate.project.ScmInfo; import io.dekorate.s2i.config.S2iBuildConfig; import io.dekorate.s2i.config.S2iBuildConfigBuilder; +import io.dekorate.s2i.config.S2iBuildConfigFluent; import io.dekorate.s2i.decorator.AddBuilderImageStreamResourceDecorator; import io.dekorate.utils.Annotations; import io.dekorate.utils.Maps; @@ -321,7 +324,32 @@ public void build(ApplicationInfoBuildItem applicationInfo, determineImagePullPolicy(knativeConfig, needToForceUpdateImagePullPolicy)); applyKnativeConfig(session, project, getResourceName(knativeConfig, applicationInfo), knativeConfig); + //When S2i is disabled we need to pass that information to dekorate. + //Also we need to make sure that the alternatives (instances of ImageConfiguration) + //are properly configured. + if (!capabilities.isCapabilityPresent(Capabilities.CONTAINER_IMAGE_S2I)) { + session.configurators().add(new Configurator>() { + @Override + public void visit(ImageConfigurationFluent image) { + containerImage.ifPresent(i -> { + String group = ImageUtil.getRepository(i.getImage()).split("/")[0]; + image.withGroup(group); + i.getRegistry().ifPresent(r -> { + image.withRegistry(r); + }); + }); + } + }); + //JAVA_APP_JAR value is not compatible with our Dockerfiles, so its causing problems + session.resources().decorate(OPENSHIFT, new RemoveEnvVarDecorator("JAVA_APP_JAR")); + session.configurators().add(new Configurator>() { + @Override + public void visit(S2iBuildConfigFluent s2i) { + s2i.withEnabled(false); + } + }); + } //apply build item configurations to the dekorate session. applyBuildItems(session, applicationInfo, diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/RemoveEnvVarDecorator.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/RemoveEnvVarDecorator.java new file mode 100644 index 0000000000000..8e224f58f050b --- /dev/null +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/RemoveEnvVarDecorator.java @@ -0,0 +1,58 @@ +package io.quarkus.kubernetes.deployment; + +import io.dekorate.deps.kubernetes.api.model.ContainerFluent; +import io.dekorate.kubernetes.decorator.AddEnvVarDecorator; +import io.dekorate.kubernetes.decorator.ApplicationContainerDecorator; +import io.dekorate.kubernetes.decorator.Decorator; +import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator; + +public class RemoveEnvVarDecorator extends ApplicationContainerDecorator> { + + private final String envVarName; + + public RemoveEnvVarDecorator(String envVarName) { + this(ANY, envVarName); + } + + public RemoveEnvVarDecorator(String name, String envVarName) { + super(name); + this.envVarName = envVarName; + } + + public void andThenVisit(ContainerFluent container) { + container.removeMatchingFromEnv(e -> e.getName().equals(envVarName)); + } + + public String getEnvVarKey() { + return this.envVarName; + } + + public Class[] after() { + return new Class[] { ResourceProvidingDecorator.class, AddEnvVarDecorator.class }; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((envVarName == null) ? 0 : envVarName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RemoveEnvVarDecorator other = (RemoveEnvVarDecorator) obj; + if (envVarName == null) { + if (other.envVarName != null) + return false; + } else if (!envVarName.equals(other.envVarName)) + return false; + return true; + } +} From 9254fc1f0793971518c2f2025115037337162f42 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Thu, 2 Jul 2020 20:49:35 +0300 Subject: [PATCH 3/3] test: add openshift with docker invoker test --- .../invoker.properties | 4 + .../openshift-docker-build-and-deploy/pom.xml | 124 ++++++++++++++++++ .../src/main/docker/Dockerfile.jvm | 22 ++++ .../src/main/java/org/acme/Hello.java | 16 +++ .../src/main/resources/application.properties | 7 + .../verify.groovy | 19 +++ .../it/kubernetes/BasicOpenshiftTest.java | 10 -- 7 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/invoker.properties create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/pom.xml create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/docker/Dockerfile.jvm create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/java/org/acme/Hello.java create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/resources/application.properties create mode 100644 integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/invoker.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/invoker.properties new file mode 100644 index 0000000000000..30fa8f402eb68 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/invoker.properties @@ -0,0 +1,4 @@ +# invoker.goals=clean package -Dquarkus.container.build=true -Dquarkus.package.type=native +invoker.goals=clean package -Dquarkus.kubernetes.deploy=true +# expect a failure since there is no Kubernetes cluster to deploy to +invoker.buildResult = failure diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/pom.xml b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/pom.xml new file mode 100644 index 0000000000000..8376d3f76ea64 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + org.acme + openshift-docker-build-and-deploy + 0.1-SNAPSHOT + + UTF-8 + 3.0.0-M5 + 1.8 + UTF-8 + 1.8 + + + + + io.quarkus + quarkus-bom + @project.version@ + pom + import + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-openshift + + + io.quarkus + quarkus-container-image-docker + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + build + + + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + native + + + native + + + + + + io.quarkus + quarkus-maven-plugin + @project.version@ + + + + native-image + + + true + + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + + diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/docker/Dockerfile.jvm b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000000000..fa97e4b117200 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/docker/Dockerfile.jvm @@ -0,0 +1,22 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the docker image run: +# +# mvn package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/getting-started-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-jvm +# +### +FROM fabric8/java-alpine-openjdk8-jre +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV AB_ENABLED=jmx_exporter +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/app.jar +ENTRYPOINT [ "/deployments/run-java.sh" ] \ No newline at end of file diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/java/org/acme/Hello.java b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/java/org/acme/Hello.java new file mode 100644 index 0000000000000..ad80766a17747 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/java/org/acme/Hello.java @@ -0,0 +1,16 @@ +package org.acme; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class Hello { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "hello"; + } +} \ No newline at end of file diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/resources/application.properties b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/resources/application.properties new file mode 100644 index 0000000000000..7db3b55b441e4 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/src/main/resources/application.properties @@ -0,0 +1,7 @@ +# Configuration file +# key = value +quarkus.container-image.builder=docker +quarkus.container-image.registry=docker.io +quarkus.container-image.group=test +quarkus.kubernetes.deployment-target=openshift +quarkus.kubernetes-client.trust-certs=true diff --git a/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy new file mode 100644 index 0000000000000..ed88813601392 --- /dev/null +++ b/integration-tests/kubernetes/maven-invoker-way/src/it/openshift-docker-build-and-deploy/verify.groovy @@ -0,0 +1,19 @@ +import io.dekorate.utils.Serialization +import io.dekorate.deps.kubernetes.api.model.KubernetesList +import io.dekorate.deps.kubernetes.api.model.apps.Deployment; +import io.dekorate.deps.openshift.api.model.* + +//Check that file exits +String base = basedir +File openshiftYml = new File(base, "target/kubernetes/openshift.yml") +assert openshiftYml.exists() +openshiftYml.withInputStream { stream -> + //Check that its parse-able + KubernetesList list = Serialization.unmarshalAsList(stream) + assert list != null + + ImageStream imageStream = list.items.find{r -> r.kind == "ImageStream"} + + assert imageStream != null + assert imageStream.spec.dockerImageRepository == "docker.io/test/openshift-docker-build-and-deploy" +} diff --git a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java index a0e7b410e3581..42c229ac4143e 100644 --- a/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java +++ b/integration-tests/kubernetes/quarkus-standard-way/src/test/java/io/quarkus/it/kubernetes/BasicOpenshiftTest.java @@ -1,7 +1,6 @@ package io.quarkus.it.kubernetes; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.tuple; import java.io.IOException; import java.nio.file.Path; @@ -13,7 +12,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.api.model.PodSpec; import io.fabric8.kubernetes.api.model.Service; import io.quarkus.test.ProdBuildResults; import io.quarkus.test.ProdModeTestResults; @@ -48,14 +46,6 @@ public void assertGeneratedResources() throws IOException { assertThat(m.getNamespace()).isNull(); }); assertThat(h).extracting("spec").extracting("replicas").isEqualTo(1); - assertThat(h).extracting("spec").extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, - podSpec -> { - assertThat(podSpec.getContainers()).hasOnlyOneElementSatisfying(container -> { - assertThat(container.getEnv()).extracting("name", "value") - .contains(tuple("JAVA_APP_JAR", - "/deployments/basic-openshift-runner.jar")); - }); - }); }); assertThat(openshiftList).filteredOn(h -> "Service".equals(h.getKind())).hasOnlyOneElementSatisfying(h -> {