-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (32 loc) · 1.14 KB
/
Dockerfile
File metadata and controls
47 lines (32 loc) · 1.14 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
# Multi-stage build for optimal image size
FROM eclipse-temurin:17-jdk-alpine AS builder
WORKDIR /build
# Copy Maven wrapper and pom.xml first (for layer caching)
COPY .mvn/ .mvn/
COPY mvnw pom.xml ./
# Download dependencies (cached layer)
RUN ./mvnw dependency:go-offline -B
# Copy source code
COPY src ./src
# Build application (skip tests in Docker build)
RUN ./mvnw clean package -DskipTests -B
# Runtime stage - minimal image
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
# Create non-root user for security
RUN addgroup -S matrikkel && adduser -S matrikkel -G matrikkel
# Copy JAR from builder stage
COPY --from=builder /build/target/*.jar app.jar
# Change ownership to non-root user
RUN chown -R matrikkel:matrikkel /app
# Switch to non-root user
USER matrikkel
# Health check (if REST API is enabled)
# HEALTHCHECK --interval=30s --timeout=3s --start-period=40s \
# CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
# Expose port (if REST API is enabled)
# EXPOSE 8080
# Set JVM options
ENV JAVA_OPTS="-Xmx1g -Xms256m -XX:+UseG1GC"
# Run application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]