-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (43 loc) · 1.67 KB
/
Dockerfile
File metadata and controls
59 lines (43 loc) · 1.67 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
49
50
51
52
53
54
55
56
57
58
59
# ===================================================================
# Stage 1: Build Stage
# ===================================================================
FROM maven:3.9.5-eclipse-temurin-17 AS builder
# Set working directory
WORKDIR /build
# Copy pom.xml first for dependency caching
COPY pom.xml .
# Download dependencies (cached layer)
RUN mvn dependency:go-offline -B
# Copy source code
COPY src ./src
# Build the application with production profile
RUN mvn -B clean package -DskipTests=true
# ===================================================================
# Stage 2: Runtime Stage
# ===================================================================
FROM eclipse-temurin:17-jre-alpine
# Labels for metadata
LABEL maintainer="saas-team@company.com" \
version="1.0.0" \
description="SaaS Application - Production Ready"
# Set working directory
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1000 -S appgroup && \
adduser -u 1000 -S appuser -G appgroup
# Create necessary directories
RUN mkdir -p /app/logs /app/config /app/temp && \
chown -R appuser:appgroup /app
# Copy the built artifact from builder stage
COPY --from=builder /build/target/*.jar app.jar
# Switch to non-root user
USER appuser
# Expose application port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/actuator/health || exit 1
# JVM Options for production
ENV JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+HeapDumpOnOutOfMemoryError"
# Entrypoint with Java options
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]