File tree Expand file tree Collapse file tree 1 file changed +31
-8
lines changed
Expand file tree Collapse file tree 1 file changed +31
-8
lines changed Original file line number Diff line number Diff line change 1- # Use Java 17 JRE as the base image
2- FROM openjdk:17-jdk-slim
1+ # Use Gradle with JDK 17 for build stage
2+ FROM gradle:7.6-jdk17-alpine as builder
3+ WORKDIR /build
34
4- # Copy the JAR file from the build output to the container
5- # The build.gradle produces the JAR file under build/libs/
6- ARG JAR_FILE=build/libs/*.jar
7- COPY ${JAR_FILE} app.jar
5+ # Only download dependencies if build.gradle or settings.gradle changes
6+ COPY build.gradle settings.gradle /build/
7+ RUN gradle build -x test --parallel
88
9- # Run the application
10- ENTRYPOINT ["java" , "-jar" , "/app/app.jar" ]
9+ # Build the application
10+ COPY . /build
11+ RUN gradle build -x test
12+
13+ # Final runtime image
14+ FROM openjdk:17.0-slim
15+ WORKDIR /app
16+
17+ # Copy JAR file from builder
18+ COPY --from=builder /build/build/libs/*-SNAPSHOT.jar ./app.jar
19+
20+ # Set appropriate permissions for non-root user
21+ RUN chown nobody:nogroup /app
22+
23+ # Run as non-root user
24+ USER nobody
25+
26+ # Expose application port
27+ EXPOSE 8080
28+
29+ # Environment variables for JVM options
30+ ENV JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Dsun.net.inetaddr.ttl=0"
31+
32+ # Application entrypoint
33+ ENTRYPOINT ["java" , "-jar" , "$JAVA_OPTS" , "app.jar" ]
You can’t perform that action at this time.
0 commit comments