Skip to content

Commit

Permalink
build: add Dockerfile with builder
Browse files Browse the repository at this point in the history
SVC-1398
  • Loading branch information
florianesser committed Feb 26, 2024
1 parent 0b17617 commit bbeca02
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit bbeca02

Please sign in to comment.