Skip to content

Commit 585c98d

Browse files
committed
[CICD] Dockerfile 수정
1 parent 51f7360 commit 585c98d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

Dockerfile

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
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"]

0 commit comments

Comments
 (0)