-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (36 loc) · 1.1 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (36 loc) · 1.1 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
# Multi-stage Dockerfile for contract-first-integrations
# Stage 1: Build
FROM eclipse-temurin:25-jdk-alpine AS build
WORKDIR /app
# Copy Maven files
COPY pom.xml .
COPY checkstyle.xml .
COPY contracts ./contracts
# Download dependencies (cached if pom.xml unchanged)
RUN apk add --no-cache maven && \
mvn dependency:go-offline -B
# Copy source code
COPY src ./src
# Build application (skip tests in Docker build)
RUN mvn clean package -DskipTests -B
# Stage 2: Runtime
FROM eclipse-temurin:25-jre-alpine
WORKDIR /app
# Create non-root user
RUN addgroup -S spring && adduser -S spring -G spring
# Copy JAR from build stage
COPY --from=build /app/target/*.jar app.jar
# Change ownership
RUN chown spring:spring app.jar
# Switch to non-root user
USER spring:spring
# Environment variables
ENV JAVA_OPTS="" \
SPRING_PROFILES_ACTIVE=prod
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/actuator/health || exit 1
# Run application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]