-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaapp1
More file actions
66 lines (48 loc) · 1.46 KB
/
javaapp1
File metadata and controls
66 lines (48 loc) · 1.46 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
60
61
62
63
64
65
66
############################
# Stage 1: Build Stage
############################
FROM maven:3.9.1-eclipse-temurin-17 AS build
# Build-time argument
ARG APP_VERSION=1.0.0
# Set working directory
WORKDIR /app
# Copy only pom.xml first to leverage Docker cache
COPY pom.xml .
# Download dependencies for caching
RUN mvn dependency:go-offline -B
# Copy source code
COPY src ./src
# Build the project, skip tests for faster build
RUN mvn clean package -DskipTests
############################
# Stage 2: Runtime Stage
############################
FROM eclipse-temurin:17-jre-jammy
# Labels for metadata
LABEL maintainer="[email protected]" \
version="1.0" \
description="Spring Boot Java Application"
# Runtime argument (can override at build-time)
ARG APP_VERSION=1.0.0
# Set working directory
WORKDIR /app
# Create non-root user
RUN useradd -m appuser
USER appuser
# Copy built JAR from build stage
COPY --from=build /app/target/*.jar app.jar
# Expose the application port
EXPOSE 8080
# Environment variables
ENV JAVA_OPTS="-Xms512m -Xmx1024m" \
SPRING_PROFILES_ACTIVE=prod \
APP_VERSION=${APP_VERSION}
# Optional volume for logs/config
VOLUME ["/app/config", "/app/logs"]
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s \
CMD curl -f http://localhost:8080/actuator/health || exit 1
# Default arguments (can be overridden at runtime)
CMD ["--server.port=8080"]
# Entrypoint
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar $0"]