-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (38 loc) · 1.41 KB
/
Copy pathDockerfile
File metadata and controls
55 lines (38 loc) · 1.41 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
# =============================================
# CrimeLink Analyzer - Spring Boot Backend
# Multi-stage build: Maven → JRE 21
# =============================================
# Stage 1: Build with Maven
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /app
# Copy Maven wrapper and POM first (better caching)
COPY mvnw ./
COPY .mvn .mvn
COPY pom.xml ./
# Make mvnw executable and fix Windows CRLF line endings
RUN chmod +x mvnw && sed -i 's/\r$//' mvnw
# Download dependencies (cached unless pom.xml changes)
RUN ./mvnw dependency:go-offline -B
# Copy source code
COPY src src
# Build the application (skip tests for faster builds)
RUN ./mvnw package -DskipTests -B
# Stage 2: Runtime with minimal JRE
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Create non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Copy the built JAR from builder
COPY --from=builder /app/target/*.jar app.jar
# Create directories for backups and uploads
RUN mkdir -p /app/backups && chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/health || exit 1
# JVM tuning for containers
ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+UseG1GC"
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]