-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (25 loc) · 883 Bytes
/
Copy pathDockerfile
File metadata and controls
36 lines (25 loc) · 883 Bytes
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
# Multi-stage build for Spring Boot M-Pesa C2B API
# Stage 1: Build the application
FROM maven:3.9-eclipse-temurin-21 AS builder
WORKDIR /app
# Copy pom.xml and download dependencies (cache layer)
COPY pom.xml .
RUN mvn dependency:go-offline -B
# Copy source code and build
COPY src ./src
RUN mvn clean package -DskipTests
# Stage 2: Run the application
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Create a non-root user
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
# Copy the built jar from builder stage
COPY --from=builder /app/target/*.jar app.jar
# Expose application port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/v1/mpesa/c2b/health || exit 1
# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]