URL-4 Added Dockerfiles for all Services

This commit is contained in:
LenaGmbh
2026-01-01 20:58:53 +01:00
parent 23241f4af1
commit 54496229c2
2 changed files with 106 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
# Build stage
FROM gradle:8.10.1-jdk21 AS build
WORKDIR /app
# Copy Gradle wrapper and build files for dependency caching
COPY gradle/ gradle/
COPY gradlew gradlew.bat ./
COPY build.gradle settings.gradle ./
# Copy source code
COPY services/analytics-service/build.gradle ./services/analytics-service/
COPY services/analytics-service/src ./services/analytics-service/src/
# Build the application
RUN ./gradlew :services:analytics-service:bootJar --no-daemon
# Runtime stage
FROM eclipse-temurin:21-jre-jammy AS runtime
# Install curl for health checks (minimal size impact)
RUN apt-get update && \
apt-get install -y --no-install-recommends curl && \
rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r spring && useradd -r -g spring spring
# Set working directory
WORKDIR /app
# Copy the JAR from build stage
COPY --from=build /app/services/analytics-service/build/libs/*.jar app.jar
# Change ownership to non-root user
RUN chown spring:spring app.jar
# Switch to non-root user
USER spring:spring
# Expose application port (default Spring Boot port, can be overridden via env)
EXPOSE 8080
# Health check for Kubernetes (can be overridden by K8s probes)
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
CMD curl -f http://localhost:${SERVER_PORT:-8080}/actuator/health || exit 1
# Optimize JVM for containers
ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:+UseG1GC -XX:+UseStringDeduplication"
# Run the application
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]