-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (35 loc) · 1.03 KB
/
Dockerfile
File metadata and controls
48 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
FROM eclipse-temurin:17-jdk-alpine as build
WORKDIR /workspace/app
# Copy gradle files
COPY gradlew .
COPY gradle gradle
COPY build.gradle .
COPY settings.gradle .
# Make gradlew executable
RUN chmod +x gradlew
# Cache gradle dependencies
RUN ./gradlew dependencies --no-daemon
# Copy source code
COPY src src
# Build the application
RUN ./gradlew build -x test --no-daemon
# Extract the JAR file
RUN mkdir -p build/extract && \
(cd build/extract && jar -xf ../libs/*.jar)
# Create runtime image
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
# Copy files from build stage
COPY --from=build /workspace/app/build/libs/*.jar app.jar
# Create non-root user
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
# Set environment variables
ENV JAVA_OPTS="-Xms256m -Xmx512m"
# Health check
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget -q --spider http://localhost:8080/actuator/health || exit 1
# Expose port
EXPOSE 8080
# Run the application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]