-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (27 loc) · 925 Bytes
/
Dockerfile
File metadata and controls
39 lines (27 loc) · 925 Bytes
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
# Multi-stage build for Spring Boot application
FROM gradle:8.5-jdk17 AS builder
WORKDIR /app
COPY build.gradle settings.gradle ./
COPY gradle gradle
COPY gradlew ./
# Download dependencies (this layer will be cached)
RUN ./gradlew --no-daemon dependencies
# Copy source code and build
COPY src src
RUN ./gradlew --no-daemon build -x test
# Runtime stage
FROM eclipse-temurin:17-jre-alpine
# Add a non-root user
RUN addgroup -g 1001 appuser && adduser -D -u 1001 -G appuser appuser
WORKDIR /app
# Copy the jar from builder stage
COPY --from=builder /app/build/libs/*.jar app.jar
# Change ownership to appuser
RUN chown appuser:appuser app.jar
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]