|
1 | 1 | # Build Stage |
2 | 2 | FROM gradle:8.13-jdk21 AS build |
3 | | - |
4 | | -# Set the working directory inside the container |
5 | 3 | WORKDIR /home/gradle/src |
6 | | - |
7 | | -# Copy only the necessary files to the container to minimize cache invalidation |
8 | | -COPY . /home/gradle/src |
9 | | - |
10 | | -# Build the project without the Gradle daemon to avoid cache issues |
| 4 | +COPY . . |
11 | 5 | RUN gradle clean build --no-daemon |
12 | 6 |
|
13 | | -# Final Stage: Create a minimal Docker image with just the JAR file |
14 | | -FROM openjdk:21-jdk-slim |
15 | | - |
16 | | -# Install curl for debugging purposes |
17 | | -RUN apt update && apt install -y curl |
18 | | - |
19 | | -# Set the working directory inside the container |
| 7 | +# Runtime Stage (JRE only) |
| 8 | +FROM eclipse-temurin:21-jre |
20 | 9 | WORKDIR /app |
21 | 10 |
|
| 11 | +RUN apt-get update \ |
| 12 | + && apt-get install -y --no-install-recommends curl \ |
| 13 | + && rm -rf /var/lib/apt/lists/* |
| 14 | + |
22 | 15 | # Copy the built jar from the build stage |
23 | | -COPY --from=build /home/gradle/src/build/libs/*.jar app.jar |
| 16 | +COPY --from=build /home/gradle/src/build/libs/*.jar /app/app.jar |
24 | 17 |
|
25 | | -# Expose the application's port |
26 | 18 | EXPOSE 8083 |
27 | 19 |
|
28 | | -# Set JVM options to handle memory issues |
29 | | -ENV JAVA_OPTS="-Xms2g -Xmx4g" |
| 20 | +# JVM options (optional) |
| 21 | +ENV JAVA_OPTS="-XX:MaxRAMPercentage=75" |
30 | 22 |
|
31 | | -# Command to run the application |
32 | | -CMD ["java", "-jar", "app.jar"] |
| 23 | +# Use a shell form to expand JAVA_OPTS |
| 24 | +CMD ["sh", "-c", "java $JAVA_OPTS -jar /app/app.jar"] |
0 commit comments