From 0b2aa070377e8a4e31548c693011c74d2727f877 Mon Sep 17 00:00:00 2001 From: Cesare De Cal Date: Sat, 13 Jul 2024 22:14:23 +0200 Subject: [PATCH] update backend Dockerfile to use GraalVM img --- backend/Dockerfile | 54 +++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index fcc874d..0e85483 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,20 +1,34 @@ -FROM openjdk:17-jdk-alpine - -WORKDIR /backend-app - -# Copy the build.gradle, settings.gradle, and gradle.properties files first -# This step helps leverage Docker's caching mechanism -COPY build.gradle settings.gradle gradle.properties ./ - -COPY gradlew ./ -COPY gradle ./gradle - -RUN ./gradlew dependencies --no-daemon - -COPY . . - -RUN ./gradlew build --no-daemon - -EXPOSE 8080 - -CMD ["java", "-jar", "build/libs/wookieepedia-0.1-all.jar"] +# Stage 1: Build the native executable using GraalVM +FROM ghcr.io/graalvm/native-image:latest as build + +WORKDIR /backend-app + +# Copy the build.gradle, settings.gradle, and gradle.properties files first +# This step helps leverage Docker's caching mechanism +COPY build.gradle settings.gradle gradle.properties ./ + +COPY gradlew ./ +COPY gradle ./gradle + +RUN ./gradlew dependencies --no-daemon + +COPY . . + +RUN ./gradlew build --no-daemon + +# Create the native image +RUN native-image --no-fallback -H:Name=wookieepedia -cp build/libs/wookieepedia-0.1-all.jar + +# Stage 2: Create the final lightweight image +FROM debian:buster-slim + +WORKDIR /backend-app + +# Copy the native executable from the build stage +COPY --from=build /backend-app/wookieepedia /backend-app/wookieepedia + +# Expose the application port +EXPOSE 8080 + +# Set the entry point to the native executable +ENTRYPOINT ["/backend-app/wookieepedia"]