Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/podman build #1916

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,13 @@ 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.

### `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.
Expand Down
2 changes: 1 addition & 1 deletion docker-build/pom.xml → build/docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
<relativePath>../..</relativePath>
</parent>
<artifactId>docker-build</artifactId>
<packaging>jar</packaging>
Expand Down
59 changes: 59 additions & 0 deletions build/podman/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>podman-build</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: Podman-build</name>
<properties>
<quarkus.container-image.build>true</quarkus.container-image.build>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-podman</artifactId>
</dependency>
</dependencies>
<profiles>
<!-- Skipped on Windows when availability of Linux containers is not explicitly declared -->
michalvavrik marked this conversation as resolved.
Show resolved Hide resolved
<profile>
<id>skip-tests-on-windows</id>
<activation>
<os>
<family>windows</family>
</os>
<property>
<name>!linux-containers-available</name>
</property>
</activation>
<properties>
<quarkus.container-image.build>false</quarkus.container-image.build>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
40 changes: 40 additions & 0 deletions build/podman/src/main/docker/Dockerfile.jvm
Original file line number Diff line number Diff line change
@@ -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"

25 changes: 25 additions & 0 deletions build/podman/src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 16 additions & 0 deletions build/podman/src/main/java/io/quarkus/ts/docker/HelloResource.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 4 additions & 0 deletions build/podman/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions build/podman/src/test/java/io/quarkus/ts/docker/PodmanBuildIT.java
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels clumsy, why don't you try podman cli command instead, or are there no Podman specific environment variables or something else? We have Windows tests with Podman, so this must be tested there, or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we use DockerUtils, which use DOCKER_HOST, so it is the most direct way to check, that the test will work.

I am not able to start a podman machine on aws, so I can not verify, which parameter is used there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oki

*/
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");
}
}
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@
<module>env-info</module>
<module>config</module>
<module>properties</module>
<module>docker-build</module>
<module>build/docker</module>
<module>build/podman</module>
<module>javaee-like-getting-started</module>
<module>scaling</module>
<module>service-discovery/stork</module>
Expand Down