-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (44 loc) · 1.82 KB
/
Dockerfile
File metadata and controls
61 lines (44 loc) · 1.82 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
# Build stage
FROM gradle:8.7.0-jdk21 AS build
WORKDIR /app
# Copy gradle wrapper and properties first for better caching
COPY gradle ./gradle
COPY gradlew gradlew.bat gradle.properties ./
COPY settings.gradle.kts build.gradle.kts ./
COPY domain/build.gradle.kts ./domain/
COPY infrastructure/build.gradle.kts ./infrastructure/
# Download dependencies (this layer will be cached)
RUN ./gradlew dependencies --no-daemon
# Copy source code
COPY domain/src ./domain/src
COPY infrastructure/src ./infrastructure/src
# Build the fat JAR without detekt and tests for faster Docker builds
RUN ./gradlew infrastructure:buildFatJar --no-daemon -x test -x detekt
# Runtime stage
FROM eclipse-temurin:21-jre-alpine AS runtime
# Install wget for healthcheck and create non-root user
RUN apk add --no-cache wget && \
addgroup -g 1001 appgroup && \
adduser -u 1001 -G appgroup -s /bin/sh -D appuser
# Set working directory
WORKDIR /app
RUN wget -O dd-java-agent.jar 'https://dtdg.co/latest-java-tracer'
# Add metadata labels
LABEL maintainer="Person API Team" \
description="Person API Ktor Application" \
version="1.0"
# Copy the fat JAR from the build stage
COPY --from=build /app/infrastructure/build/libs/app.jar /app/app.jar
# Change ownership to non-root user
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose the port the app runs on
EXPOSE 8080
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s --retries=5 \
CMD wget -q --spider http://localhost:8080/api/persons || exit 1
# Set JVM options for containerized environment
ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError"
# Set the entrypoint
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -javaagent:dd-java-agent.jar -Ddd.logs.injection=true -Ddd.trace.sample.rate=1 -jar /app/app.jar"]