From c57185e754b766d3dbc7e961d2fd4888e207d1df Mon Sep 17 00:00:00 2001 From: Fedor Dudinsky Date: Wed, 7 Aug 2024 14:01:22 +0200 Subject: [PATCH 1/2] Move Docker build to a separate directory --- README.md | 2 +- {docker-build => build/docker}/pom.xml | 2 +- {docker-build => build/docker}/src/main/docker/Dockerfile.jvm | 0 .../docker}/src/main/docker/Dockerfile.native | 0 .../src/main/java/io/quarkus/ts/docker/HelloResource.java | 0 .../docker}/src/main/resources/application.properties | 0 .../src/test/java/io/quarkus/ts/docker/DockerBuildIT.java | 0 .../test/java/io/quarkus/ts/docker/NativeConfigurationIT.java | 0 pom.xml | 2 +- 9 files changed, 3 insertions(+), 3 deletions(-) rename {docker-build => build/docker}/pom.xml (98%) rename {docker-build => build/docker}/src/main/docker/Dockerfile.jvm (100%) rename {docker-build => build/docker}/src/main/docker/Dockerfile.native (100%) rename {docker-build => build/docker}/src/main/java/io/quarkus/ts/docker/HelloResource.java (100%) rename {docker-build => build/docker}/src/main/resources/application.properties (100%) rename {docker-build => build/docker}/src/test/java/io/quarkus/ts/docker/DockerBuildIT.java (100%) rename {docker-build => build/docker}/src/test/java/io/quarkus/ts/docker/NativeConfigurationIT.java (100%) diff --git a/README.md b/README.md index ac66f99da..78f48fb73 100644 --- a/README.md +++ b/README.md @@ -454,7 +454,7 @@ Checks that the application can read configuration from a ConfigMap and a Secret The ConfigMap/Secret is exposed by mounting it into the container file system or the Kubernetes API server. Also ensures proper integration of SmallRye Config [Secret Keys](https://smallrye.io/smallrye-config/Main/config/secret-keys/) with Quarkus. -### `docker-build` +### `build/docker-build` Checks that an application can generate a Docker image based on some configuration parameters. ### `lifecycle-application` diff --git a/docker-build/pom.xml b/build/docker/pom.xml similarity index 98% rename from docker-build/pom.xml rename to build/docker/pom.xml index 5023cdb6b..1d9970fe5 100644 --- a/docker-build/pom.xml +++ b/build/docker/pom.xml @@ -5,7 +5,7 @@ io.quarkus.ts.qe parent 1.0.0-SNAPSHOT - .. + ../.. docker-build jar diff --git a/docker-build/src/main/docker/Dockerfile.jvm b/build/docker/src/main/docker/Dockerfile.jvm similarity index 100% rename from docker-build/src/main/docker/Dockerfile.jvm rename to build/docker/src/main/docker/Dockerfile.jvm diff --git a/docker-build/src/main/docker/Dockerfile.native b/build/docker/src/main/docker/Dockerfile.native similarity index 100% rename from docker-build/src/main/docker/Dockerfile.native rename to build/docker/src/main/docker/Dockerfile.native diff --git a/docker-build/src/main/java/io/quarkus/ts/docker/HelloResource.java b/build/docker/src/main/java/io/quarkus/ts/docker/HelloResource.java similarity index 100% rename from docker-build/src/main/java/io/quarkus/ts/docker/HelloResource.java rename to build/docker/src/main/java/io/quarkus/ts/docker/HelloResource.java diff --git a/docker-build/src/main/resources/application.properties b/build/docker/src/main/resources/application.properties similarity index 100% rename from docker-build/src/main/resources/application.properties rename to build/docker/src/main/resources/application.properties diff --git a/docker-build/src/test/java/io/quarkus/ts/docker/DockerBuildIT.java b/build/docker/src/test/java/io/quarkus/ts/docker/DockerBuildIT.java similarity index 100% rename from docker-build/src/test/java/io/quarkus/ts/docker/DockerBuildIT.java rename to build/docker/src/test/java/io/quarkus/ts/docker/DockerBuildIT.java diff --git a/docker-build/src/test/java/io/quarkus/ts/docker/NativeConfigurationIT.java b/build/docker/src/test/java/io/quarkus/ts/docker/NativeConfigurationIT.java similarity index 100% rename from docker-build/src/test/java/io/quarkus/ts/docker/NativeConfigurationIT.java rename to build/docker/src/test/java/io/quarkus/ts/docker/NativeConfigurationIT.java diff --git a/pom.xml b/pom.xml index e7dd19479..ed0a1e541 100644 --- a/pom.xml +++ b/pom.xml @@ -407,7 +407,7 @@ env-info config properties - docker-build + build/docker javaee-like-getting-started scaling service-discovery/stork From eb47ea861fb5089fe36f80d6f249f48dd5c7b302 Mon Sep 17 00:00:00 2001 From: Fedor Dudinsky Date: Wed, 7 Aug 2024 16:47:54 +0200 Subject: [PATCH 2/2] Cover podman-build extension --- README.md | 4 ++ build/podman/pom.xml | 59 +++++++++++++++++++ build/podman/src/main/docker/Dockerfile.jvm | 40 +++++++++++++ .../podman/src/main/docker/Dockerfile.native | 25 ++++++++ .../io/quarkus/ts/docker/HelloResource.java | 16 +++++ .../src/main/resources/application.properties | 4 ++ .../io/quarkus/ts/docker/PodmanBuildIT.java | 40 +++++++++++++ pom.xml | 1 + 8 files changed, 189 insertions(+) create mode 100644 build/podman/pom.xml create mode 100644 build/podman/src/main/docker/Dockerfile.jvm create mode 100644 build/podman/src/main/docker/Dockerfile.native create mode 100644 build/podman/src/main/java/io/quarkus/ts/docker/HelloResource.java create mode 100644 build/podman/src/main/resources/application.properties create mode 100644 build/podman/src/test/java/io/quarkus/ts/docker/PodmanBuildIT.java diff --git a/README.md b/README.md index 78f48fb73..5ebdc2fce 100644 --- a/README.md +++ b/README.md @@ -457,6 +457,10 @@ Also ensures proper integration of SmallRye Config [Secret Keys](https://smallry ### `build/docker-build` Checks that an application can generate a Docker image based on some configuration parameters. +### `build/podman` +Checks that an application can generate a Docker image using podman extension. + + ### `lifecycle-application` Verifies lifecycle application features like `@QuarkusMain` and `@CommandLineArguments`. Also ensures maven profile activation with properties and additional repository definition propagation into Quarkus maven plugin. diff --git a/build/podman/pom.xml b/build/podman/pom.xml new file mode 100644 index 000000000..36378ceff --- /dev/null +++ b/build/podman/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + io.quarkus.ts.qe + parent + 1.0.0-SNAPSHOT + ../.. + + podman-build + jar + Quarkus QE TS: Podman-build + + true + + + + io.quarkus + quarkus-rest-jackson + + + io.quarkus + quarkus-container-image-podman + + + + + + skip-tests-on-windows + + + windows + + + !linux-containers-available + + + + false + + + + + maven-surefire-plugin + + true + + + + maven-failsafe-plugin + + true + + + + + + + diff --git a/build/podman/src/main/docker/Dockerfile.jvm b/build/podman/src/main/docker/Dockerfile.jvm new file mode 100644 index 000000000..29545f743 --- /dev/null +++ b/build/podman/src/main/docker/Dockerfile.jvm @@ -0,0 +1,40 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw 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 +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5005 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started-jvm +# +### +FROM registry.access.redhat.com/ubi8/openjdk-17:latest + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV AB_JOLOKIA_OFF="" +ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + diff --git a/build/podman/src/main/docker/Dockerfile.native b/build/podman/src/main/docker/Dockerfile.native new file mode 100644 index 000000000..bc4399f20 --- /dev/null +++ b/build/podman/src/main/docker/Dockerfile.native @@ -0,0 +1,25 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode +# +# Before building the container image run: +# +# ./mvnw package -Pnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/getting-started . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/getting-started +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application +EXPOSE 8080 +USER 1001 +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/build/podman/src/main/java/io/quarkus/ts/docker/HelloResource.java b/build/podman/src/main/java/io/quarkus/ts/docker/HelloResource.java new file mode 100644 index 000000000..45266e6dc --- /dev/null +++ b/build/podman/src/main/java/io/quarkus/ts/docker/HelloResource.java @@ -0,0 +1,16 @@ +package io.quarkus.ts.docker; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; + +@Path("/hello") +public class HelloResource { + @GET + @Produces(MediaType.TEXT_PLAIN) + public Response get() { + return Response.ok("hello World").build(); + } +} diff --git a/build/podman/src/main/resources/application.properties b/build/podman/src/main/resources/application.properties new file mode 100644 index 000000000..4f44d5955 --- /dev/null +++ b/build/podman/src/main/resources/application.properties @@ -0,0 +1,4 @@ +quarkus.container-image.group=qe +# DON'T remove the spaces that are at the end of quarkus app name +quarkus.application.name=hello-world-podman-app +quarkus.container-image.tag=1.0.0 diff --git a/build/podman/src/test/java/io/quarkus/ts/docker/PodmanBuildIT.java b/build/podman/src/test/java/io/quarkus/ts/docker/PodmanBuildIT.java new file mode 100644 index 000000000..a5f7ebe5c --- /dev/null +++ b/build/podman/src/test/java/io/quarkus/ts/docker/PodmanBuildIT.java @@ -0,0 +1,40 @@ +package io.quarkus.ts.docker; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Objects; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; + +import com.github.dockerjava.api.model.Image; + +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.utils.DockerUtils; + +@QuarkusScenario +@EnabledIfEnvironmentVariable(named = "DOCKER_HOST", matches = ".*podman.*") +/** + * We run the tests only when podman is enabled and does not pretend to be Docker + * since otherwise we won't be able to distinguish between the extension being broken + * and a situation, when podman is not installed. + * + * Unfortunately, that means, that the test is disabled on Windows and Mac + */ +public class PodmanBuildIT { + // Local container build, no need in tracking image in properties + private static final String IMAGE_NAME = "hello-world-podman-app"; + private static final String IMAGE_VERSION = "1.0.0"; + + @AfterAll + public static void tearDown() { + DockerUtils.removeImage(IMAGE_NAME, IMAGE_VERSION); + } + + @Test + public void verifyImageNameWithSpaces() { + Image image = DockerUtils.getImage(IMAGE_NAME, IMAGE_VERSION); + assertTrue(Objects.nonNull(image.getId()) && !image.getId().isEmpty(), "The image was not created"); + } +} diff --git a/pom.xml b/pom.xml index ed0a1e541..4fd8a542d 100644 --- a/pom.xml +++ b/pom.xml @@ -408,6 +408,7 @@ config properties build/docker + build/podman javaee-like-getting-started scaling service-discovery/stork