Skip to content

Commit

Permalink
update backend Dockerfile to use GraalVM img
Browse files Browse the repository at this point in the history
  • Loading branch information
Cesare De Cal committed Jul 13, 2024
1 parent ed6690a commit 0b2aa07
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 0b2aa07

Please sign in to comment.