From e5464914ac294cdaa461f9b6e65b3bb9adeca2cf Mon Sep 17 00:00:00 2001 From: Florian Esser Date: Mon, 26 Feb 2024 16:47:31 +0100 Subject: [PATCH] build: add Dockerfile with builder SVC-1398 --- Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3192e65 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM eclipse-temurin:17-jdk AS builder + +WORKDIR /app + +# Copy the Gradle wrapper files +COPY gradlew . +COPY gradle gradle + +# Copy the project build files +COPY build.gradle . +COPY settings.gradle . + +# Copy the project source +COPY src src + +# Build the application +RUN ./gradlew bootJar + +RUN java -Djarmode=layertools -jar build/libs/*.jar extract --destination build/extracted/ + +# Create the final image +FROM eclipse-temurin:17-jre + +WORKDIR /app + +# Run as non-root +RUN groupadd hale && useradd -d /app -g hale hale && chown hale:hale /app +USER hale + +# Copy the built JAR file from the builder image +#COPY --from=builder /app/build/libs/*.jar app.jar +COPY --from=builder --chown=hale /app/build/extracted/dependencies/ ./ +COPY --from=builder --chown=hale /app/build/extracted/spring-boot-loader/ ./ +COPY --from=builder --chown=hale /app/build/extracted/snapshot-dependencies/ ./ +COPY --from=builder --chown=hale /app/build/extracted/application/ ./ + +# Expose the port +EXPOSE 8080 + +# Define the command to run the application when the container starts +ENTRYPOINT ["java", "--add-exports=java.base/sun.nio.ch=ALL-UNNAMED", "--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED", "org.springframework.boot.loader.launch.JarLauncher"]