From 039c05f3e72da2dafaf0853c8d258db182aa2c1e Mon Sep 17 00:00:00 2001 From: LionsCtl Bot Date: Sat, 30 Aug 2025 15:21:53 +0000 Subject: [PATCH] Add Quarkus REST application - Java 17 with Quarkus 3.6.0 - REST endpoint /hello - Health check endpoint /hello/health - JUnit tests with RestAssured - Optimized Dockerfile for production - Ready for CI/CD pipeline --- Dockerfile | 15 +++++ pom.xml | 56 +++++++++++++++++++ src/main/java/dev/lions/HelloResource.java | 23 ++++++++ src/main/resources/application.properties | 17 ++++++ .../java/dev/lions/HelloResourceTest.java | 29 ++++++++++ 5 files changed, 140 insertions(+) create mode 100644 Dockerfile create mode 100644 pom.xml create mode 100644 src/main/java/dev/lions/HelloResource.java create mode 100644 src/main/resources/application.properties create mode 100644 src/test/java/dev/lions/HelloResourceTest.java diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9a275fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM registry.access.redhat.com/ubi8/openjdk-17:1.18 + +ENV LANGUAGE='en_US:en' + +COPY target/quarkus-app/lib/ /deployments/lib/ +COPY target/quarkus-app/*.jar /deployments/ +COPY target/quarkus-app/app/ /deployments/app/ +COPY target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ee61586 --- /dev/null +++ b/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + dev.lions + test-lionsctl + 1.0.0 + + 17 + 17 + UTF-8 + 3.6.0 + + + + + io.quarkus.platform + quarkus-bom + ${quarkus.platform.version} + pom + import + + + + + + io.quarkus + quarkus-resteasy-reactive + + + io.quarkus + quarkus-junit5 + test + + + + + + io.quarkus.platform + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + + + + + + + diff --git a/src/main/java/dev/lions/HelloResource.java b/src/main/java/dev/lions/HelloResource.java new file mode 100644 index 0000000..264acd8 --- /dev/null +++ b/src/main/java/dev/lions/HelloResource.java @@ -0,0 +1,23 @@ +package dev.lions; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "Hello from LionsCtl CI/CD Pipeline!"; + } + + @GET + @Path("/health") + @Produces(MediaType.TEXT_PLAIN) + public String health() { + return "OK"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..e392901 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,17 @@ +# Application Configuration +quarkus.http.port=8080 +quarkus.http.host=0.0.0.0 + +# Health check configuration +quarkus.health.extensions.enabled=true + +# Logging configuration +quarkus.log.level=INFO +quarkus.log.console.enable=true +quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n + +# Container image configuration (for Quarkus native build) +quarkus.container-image.build=true +quarkus.container-image.group=registry.lions.dev +quarkus.container-image.name=test-lionsctl +quarkus.container-image.tag=latest diff --git a/src/test/java/dev/lions/HelloResourceTest.java b/src/test/java/dev/lions/HelloResourceTest.java new file mode 100644 index 0000000..fd470a1 --- /dev/null +++ b/src/test/java/dev/lions/HelloResourceTest.java @@ -0,0 +1,29 @@ +package dev.lions; + +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.is; + +@QuarkusTest +public class HelloResourceTest { + + @Test + public void testHelloEndpoint() { + given() + .when().get("/hello") + .then() + .statusCode(200) + .body(is("Hello from LionsCtl CI/CD Pipeline!")); + } + + @Test + public void testHealthEndpoint() { + given() + .when().get("/hello/health") + .then() + .statusCode(200) + .body(is("OK")); + } +}