From bacad44057adf94f300efa0eba4591fac55985ea Mon Sep 17 00:00:00 2001 From: Daniel Stefani Date: Sat, 13 Apr 2024 20:18:48 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=9A=80=20native=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 68 +++++++++--------------------- Dockerfile.jvm | 53 +++++++++++++++++++++++ Dockerfile.native | 21 --------- settings.gradle.kts | 4 ++ src/main/resources/application.yml | 6 ++- 5 files changed, 82 insertions(+), 70 deletions(-) create mode 100644 Dockerfile.jvm delete mode 100644 Dockerfile.native diff --git a/Dockerfile b/Dockerfile index d46c257..7afd861 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,53 +1,25 @@ -FROM gradle:8.4.0-jdk17-jammy AS BUILD +FROM ghcr.io/graalvm/graalvm-ce:ol8-java17-22.3.3 AS BUILD WORKDIR /appbuild COPY . . -RUN gradle build -Dquarkus.package.type=uber-jar --no-daemon - -#FROM amazoncorretto:17-alpine as CORRETTO-DEPS -# -#WORKDIR /app -# -#COPY --from=build /appbuild/build/paddy-backend-runner.jar . -# -## Get modules list -#RUN unzip paddy-backend-runner.jar -d temp && \ -# jdeps \ -# --print-module-deps \ -# --ignore-missing-deps \ -# --recursive \ -# --multi-release 17 \ -# --class-path="./temp/BOOT-INF/lib/*" \ -# --module-path="./temp/BOOT-INF/lib/*" \ -# paddy-backend-runner.jar > modules.txt -# -#FROM amazoncorretto:17-alpine as CORRETTO-JDK -# -#WORKDIR /app -# -#COPY --from=corretto-deps /app/modules.txt . -# -## Output a custom jre built from the modules list -#RUN apk add --no-cache binutils && \ -# jlink \ -# --verbose \ -# --add-modules "$(cat modules.txt)" \ -# --strip-debug \ -# --no-man-pages \ -# --no-header-files \ -# --compress=2 \ -# --output /jre - -FROM amazoncorretto:17-alpine as CORRETTO-JDK - -#COPY --from=corretto-jdk /jre /app/jre -COPY --from=build /appbuild/build/paddy-backend-runner.jar /app/paddy-backend-runner.jar - -WORKDIR /app - -ARG DEBUG_OPT -ENV DEBUG_API_OPT=$DEBUG_OPT - -CMD java $DEBUG_API_OPT -jar paddy-backend-runner.jar \ No newline at end of file +RUN gu install native-image + +RUN ./gradlew build --no-daemon -Dquarkus.package.type=native + + +FROM quay.io/quarkus/quarkus-micro-image:2.0 AS NATIVE + +WORKDIR /work + +COPY --from=BUILD /appbuild/* . + +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work + +EXPOSE 8080 +USER 1001 + +CMD ["/work/quarkus-build/gen/paddy-backend-runner", "-Dquarkus.http.host=0.0.0.0"] diff --git a/Dockerfile.jvm b/Dockerfile.jvm new file mode 100644 index 0000000..d46c257 --- /dev/null +++ b/Dockerfile.jvm @@ -0,0 +1,53 @@ +FROM gradle:8.4.0-jdk17-jammy AS BUILD + +WORKDIR /appbuild + +COPY . . + +RUN gradle build -Dquarkus.package.type=uber-jar --no-daemon + +#FROM amazoncorretto:17-alpine as CORRETTO-DEPS +# +#WORKDIR /app +# +#COPY --from=build /appbuild/build/paddy-backend-runner.jar . +# +## Get modules list +#RUN unzip paddy-backend-runner.jar -d temp && \ +# jdeps \ +# --print-module-deps \ +# --ignore-missing-deps \ +# --recursive \ +# --multi-release 17 \ +# --class-path="./temp/BOOT-INF/lib/*" \ +# --module-path="./temp/BOOT-INF/lib/*" \ +# paddy-backend-runner.jar > modules.txt +# +#FROM amazoncorretto:17-alpine as CORRETTO-JDK +# +#WORKDIR /app +# +#COPY --from=corretto-deps /app/modules.txt . +# +## Output a custom jre built from the modules list +#RUN apk add --no-cache binutils && \ +# jlink \ +# --verbose \ +# --add-modules "$(cat modules.txt)" \ +# --strip-debug \ +# --no-man-pages \ +# --no-header-files \ +# --compress=2 \ +# --output /jre + +FROM amazoncorretto:17-alpine as CORRETTO-JDK + +#COPY --from=corretto-jdk /jre /app/jre +COPY --from=build /appbuild/build/paddy-backend-runner.jar /app/paddy-backend-runner.jar + +WORKDIR /app + +ARG DEBUG_OPT +ENV DEBUG_API_OPT=$DEBUG_OPT + +CMD java $DEBUG_API_OPT -jar paddy-backend-runner.jar \ No newline at end of file diff --git a/Dockerfile.native b/Dockerfile.native deleted file mode 100644 index 9d0cd63..0000000 --- a/Dockerfile.native +++ /dev/null @@ -1,21 +0,0 @@ -## Stage 1 : build with maven builder image with native capabilities -FROM quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-21 AS build -USER root -RUN microdnf install findutils -COPY --chown=quarkus:quarkus gradlew /code/gradlew -COPY --chown=quarkus:quarkus gradle /code/gradle -COPY --chown=quarkus:quarkus build.gradle.kts /code/ -COPY --chown=quarkus:quarkus settings.gradle.kts /code/ -COPY --chown=quarkus:quarkus gradle.properties /code/ -USER quarkus -WORKDIR /code -COPY src /code/src -RUN ./gradlew build -Dquarkus.package.type=native --no-daemon --initialize-at-run-time=com.hivemq.client.internal.mqtt.handler.proxy.MqttProxyAdapterHandler - -## Stage 2 : create the docker final image -FROM quay.io/quarkus/quarkus-micro-image:2.0 -WORKDIR /work/ -COPY --from=build /code/build/*-runner /work/application -RUN chmod 775 /work -EXPOSE 8080 -CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index bdf229f..9cff92e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,13 +1,17 @@ pluginManagement { + val quarkusPluginVersion: String by settings val quarkusPluginId: String by settings + repositories { mavenCentral() gradlePluginPortal() mavenLocal() } + plugins { id(quarkusPluginId) version quarkusPluginVersion } } + rootProject.name="paddy-backend" diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c6e23d7..6c18429 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,9 @@ quarkus: + native: + additional-build-args: + - '--initialize-at-run-time=com.hivemq.client.internal.mqtt.codec.encoder.MqttPingReqEncoder' + - '--initialize-at-run-time=com.hivemq.client.internal.mqtt.codec.encoder.mqtt3.Mqtt3DisconnectEncoder' + package: output-name: paddy-backend @@ -6,7 +11,6 @@ quarkus: enabled: false http: - port: 80 root-path: /api/v1