-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
45 lines (33 loc) · 1.03 KB
/
Copy pathDockerfile
File metadata and controls
45 lines (33 loc) · 1.03 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
# Build stage
FROM gradle:8.5-jdk21 AS build
WORKDIR /app
# Copy gradle files first for dependency caching
COPY build.gradle settings.gradle ./
COPY gradle ./gradle
COPY gradlew gradlew.bat ./
# Make gradlew executable
RUN chmod +x gradlew
# Download dependencies (this layer will be cached)
RUN ./gradlew dependencies
# Copy source code
COPY src ./src
# Build the application
RUN ./gradlew build -x test
# Runtime stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
# Copy the built artifact from build stage
COPY --from=build /app/build/libs/*.jar app.jar
# Add health check
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget --no-verbose --tries=1 --spider http://localhost:8081/actuator/health || exit 1
# Environment variables with defaults
ENV JAVA_OPTS="-Xms512m -Xmx1024m"
ENV SERVER_PORT=8081
# Expose the application port
EXPOSE ${SERVER_PORT}
# Create a non-root user and switch to it
RUN adduser -D appuser
USER appuser
# Run the application with configurable Java options
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar app.jar"]