-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
38 lines (27 loc) · 1.02 KB
/
Copy pathDockerfile
File metadata and controls
38 lines (27 loc) · 1.02 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
# Stage 1: Build stage using Maven + JDK 21
FROM maven:3.9.6-eclipse-temurin-21-alpine AS builder
WORKDIR /build
# Copy pom.xml first to cache dependencies
COPY pom.xml .
RUN mvn dependency:go-offline -B
# Copy source code and package application
COPY src ./src
RUN mvn clean package -DskipTests -B
# Stage 2: Slim JRE-only runtime stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Install curl for container healthcheck
RUN apk add --no-cache curl
# Create non-root system user and group
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy compiled executable JAR from builder stage
COPY --from=builder /build/target/distributed-file-sharing-*.jar app.jar
# Set file ownership for non-root execution
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
EXPOSE 8080
# Healthcheck hitting Spring Boot Actuator endpoint
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8080/actuator/health || exit 1
ENTRYPOINT ["java", "-jar", "app.jar"]