upgrade(docker)

This commit is contained in:
stefan
2025-08-16 15:47:57 +02:00
parent 1ef14a3692
commit 9c21154199
48 changed files with 6250 additions and 549 deletions
+119
View File
@@ -0,0 +1,119 @@
# ===================================================================
# Dockerfile for Meldestelle Web Application
# Based on kotlin-multiplatform-web template
# ===================================================================
# Build arguments
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG NGINX_VERSION=alpine
# ===================================================================
# Build Stage - Kotlin/JS Compilation
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS kotlin-builder
LABEL stage=kotlin-builder
LABEL service=web-app
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations for Kotlin Multiplatform builds
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Dorg.gradle.jvmargs=-Xmx3g \
-Dkotlin.compiler.execution.strategy=in-process"
# Copy build configuration files first for optimal Docker layer caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY build.gradle.kts ./
# Copy platform and core dependencies (changes less frequently)
COPY platform/ platform/
COPY core/ core/
# Copy client modules in dependency order for optimal caching
COPY client/common-ui/ client/common-ui/
COPY client/web-app/ client/web-app/
# Download and cache dependencies in a separate layer
RUN ./gradlew :client:web-app:dependencies --no-daemon --info
# Build web application with production optimizations
RUN ./gradlew :client:web-app:jsBrowserProductionWebpack --no-daemon --info
# Verify build output
RUN ls -la /workspace/client/web-app/build/dist/ || (echo "Build failed - no dist directory found" && exit 1)
# ===================================================================
# Production Stage - Nginx serving
# ===================================================================
FROM nginx:${NGINX_VERSION} AS runtime
# Comprehensive metadata
LABEL service="web-app" \
version="1.0.0" \
description="Meldestelle Web Application - Kotlin Multiplatform Client" \
maintainer="Meldestelle Development Team" \
build.gradle.version="${GRADLE_VERSION}" \
java.version="${JAVA_VERSION}" \
nginx.version="${NGINX_VERSION}"
# Security and system setup
RUN apk update && \
apk upgrade && \
apk add --no-cache curl jq && \
rm -rf /var/cache/apk/*
# Remove default nginx content and logs
RUN rm -rf /usr/share/nginx/html/* && \
rm -f /var/log/nginx/*.log
# Copy built web application from builder stage
COPY --from=kotlin-builder /workspace/client/web-app/build/dist/ /usr/share/nginx/html/
# Copy optimized nginx configuration
COPY client/web-app/nginx.conf /etc/nginx/nginx.conf
# Set proper permissions for nginx
RUN chown -R nginx:nginx /usr/share/nginx/html /var/cache/nginx /var/run /var/log/nginx && \
chmod -R 755 /usr/share/nginx/html
# Switch to nginx user for security
USER nginx
# Health check specifically for the web application
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD curl -f http://localhost/health || exit 1
# Expose HTTP port
EXPOSE 80
# Start nginx with proper signal handling for graceful shutdowns
STOPSIGNAL SIGQUIT
# Run nginx in foreground with error handling
CMD ["sh", "-c", "nginx -t && exec nginx -g 'daemon off;'"]
# ===================================================================
# Build and Usage Instructions
# ===================================================================
# Build:
# docker build -t meldestelle/web-app:latest -f client/web-app/Dockerfile .
#
# Run standalone:
# docker run -p 3001:80 --name web-app meldestelle/web-app:latest
#
# Run with API backend:
# docker run -p 3001:80 --link api-gateway:api-gateway --name web-app meldestelle/web-app:latest
#
# Access application:
# http://localhost:3001
# http://localhost:3001/health (health check)
#
# Development with hot-reload (use docker-compose.override.yml instead)
# ===================================================================
@@ -0,0 +1,142 @@
# syntax=docker/dockerfile:1.7
# ===================================================================
# Dockerfile for Meldestelle Auth Server
# Based on spring-boot-service template with auth-server specifics
# ===================================================================
# Build arguments
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG SPRING_PROFILES_ACTIVE=docker
# ===================================================================
# Build Stage
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
LABEL stage=builder
LABEL service=auth-server
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
# Copy build files in optimal order for caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY platform/ platform/
COPY core/ core/
COPY build.gradle.kts ./
# Copy infrastructure dependencies
COPY infrastructure/auth/auth-client/ infrastructure/auth/auth-client/
# Copy auth-server specific files
COPY infrastructure/auth/auth-server/build.gradle.kts infrastructure/auth/auth-server/
COPY infrastructure/auth/auth-server/src/ infrastructure/auth/auth-server/src/
# Build application
RUN ./gradlew :infrastructure:auth:auth-server:dependencies --no-daemon --info
RUN ./gradlew :infrastructure:auth:auth-server:bootJar --no-daemon --info \
-Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}
# ===================================================================
# Runtime Stage
# ===================================================================
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
# Comprehensive metadata
LABEL service="auth-server" \
version="1.0.0" \
description="Authentication and Authorization Server for Meldestelle" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}" \
spring.profiles.active="${SPRING_PROFILES_ACTIVE}"
# Build arguments for user configuration
ARG APP_USER=authuser
ARG APP_GROUP=authgroup
ARG APP_UID=1002
ARG APP_GID=1002
WORKDIR /app
# System setup with security updates
RUN apk update && \
apk upgrade && \
apk add --no-cache curl jq tzdata ca-certificates && \
rm -rf /var/cache/apk/*
# Create non-root user for auth-server
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh
# Create required directories with proper permissions
RUN mkdir -p /app/logs /app/tmp /app/config && \
chown -R ${APP_USER}:${APP_GROUP} /app
# Copy the built JAR from builder stage
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} \
/workspace/infrastructure/auth/auth-server/build/libs/*.jar app.jar
# Switch to non-root user
USER ${APP_USER}
# Expose auth-server port and debug port
EXPOSE 8081 5005
# Enhanced health check for auth service
HEALTHCHECK --interval=15s --timeout=5s --start-period=60s --retries=3 \
CMD curl -fsS --max-time 3 http://localhost:8081/actuator/health/readiness || exit 1
# Optimized JVM settings for auth workloads
ENV JAVA_OPTS="-XX:MaxRAMPercentage=80.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-XX:G1HeapRegionSize=16m \
-XX:+OptimizeStringConcat \
-XX:+UseCompressedOops \
-Djava.security.egd=file:/dev/./urandom \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Europe/Vienna \
-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus,configprops"
# Auth-server specific Spring Boot configuration
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE} \
SERVER_PORT=8081 \
MANAGEMENT_SERVER_PORT=8081 \
LOGGING_LEVEL_ROOT=INFO \
LOGGING_LEVEL_AT_MOCODE=DEBUG
# Security-focused startup command with debug support
ENTRYPOINT ["sh", "-c", "\
echo 'Starting Meldestelle Auth Server on port 8081...'; \
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Debug mode enabled on port 5005'; \
exec java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar; \
else \
exec java $JAVA_OPTS -jar app.jar; \
fi"]
# ===================================================================
# Build and Usage Instructions
# ===================================================================
# Build:
# docker build -t meldestelle/auth-server:latest -f infrastructure/auth/auth-server/Dockerfile .
#
# Run standalone:
# docker run -p 8081:8081 --name auth-server meldestelle/auth-server:latest
#
# Run with debug:
# docker run -p 8081:8081 -p 5005:5005 -e DEBUG=true --name auth-server meldestelle/auth-server:latest
# ===================================================================
@@ -0,0 +1,163 @@
# =============================================================================
# Multi-stage Dockerfile for Meldestelle API Gateway
# Optimized for security, performance, and maintainability
# =============================================================================
# =============================================================================
# Build stage - Full Gradle build for better dependency management
# =============================================================================
FROM gradle:8.14-jdk21-alpine AS builder
LABEL stage=builder
LABEL service=api-gateway
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
# Copy build files in optimal order for caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY platform/ platform/
COPY core/ core/
COPY build.gradle.kts ./
# Copy gateway specific files
COPY infrastructure/gateway/build.gradle.kts infrastructure/gateway/
COPY infrastructure/gateway/src/ infrastructure/gateway/src/
# Build application
RUN ./gradlew :infrastructure:gateway:dependencies --no-daemon --info
RUN ./gradlew :infrastructure:gateway:bootJar --no-daemon --info
# Extract JAR layers for optimized Docker layer caching
WORKDIR /builder
RUN cp /workspace/infrastructure/gateway/build/libs/*.jar app.jar && \
java -Djarmode=layertools -jar app.jar extract
# =============================================================================
# Runtime stage - Optimized production image
# =============================================================================
FROM eclipse-temurin:21-jre-alpine AS runtime
# =============================================================================
# Metadata and Build Information
# =============================================================================
LABEL maintainer="Meldestelle Team <support@meldestelle.at>"
LABEL description="Self-Contained Systems API Gateway for Austrian Equestrian Federation"
LABEL version="1.0.0"
LABEL org.opencontainers.image.title="Meldestelle Gateway"
LABEL org.opencontainers.image.description="Spring Cloud Gateway with Circuit Breaker, Health Monitoring, and Service Discovery"
LABEL org.opencontainers.image.vendor="Meldestelle"
LABEL org.opencontainers.image.version="1.0.0"
LABEL org.opencontainers.image.created="2025-08-14"
LABEL org.opencontainers.image.source="https://github.com/meldestelle/api-gateway"
LABEL org.opencontainers.image.documentation="https://api.meldestelle.at/docs"
# =============================================================================
# Security and System Setup
# =============================================================================
# Install curl for health checks and security updates
RUN apk update && \
apk add --no-cache curl ca-certificates tzdata && \
apk upgrade && \
rm -rf /var/cache/apk/*
# Create dedicated non-root user with specific UID/GID for security
RUN addgroup -g 1001 -S gateway && \
adduser -u 1001 -S gateway -G gateway -s /bin/sh
# Set timezone for consistent logging and operations
ENV TZ=Europe/Vienna
# =============================================================================
# Application Setup
# =============================================================================
# Set working directory
WORKDIR /app
# Create required directories with proper permissions
RUN mkdir -p /app/logs /app/tmp && \
chown -R gateway:gateway /app
# Copy Spring Boot layers in optimal order for Docker layer caching
# Dependencies change less frequently than application code
COPY --from=builder --chown=gateway:gateway /builder/dependencies/ ./
COPY --from=builder --chown=gateway:gateway /builder/spring-boot-loader/ ./
COPY --from=builder --chown=gateway:gateway /builder/snapshot-dependencies/ ./
COPY --from=builder --chown=gateway:gateway /builder/application/ ./
# =============================================================================
# Runtime Configuration
# =============================================================================
# Switch to non-root user for security
USER gateway
# Expose application port and debug port
EXPOSE 8080 5005
# =============================================================================
# JVM and Application Configuration
# =============================================================================
# Optimized JVM settings for containerized Spring Boot reactive applications
ENV JAVA_OPTS="-XX:MaxRAMPercentage=80.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-XX:G1HeapRegionSize=16m \
-XX:+OptimizeStringConcat \
-XX:+UseCompressedOops \
-Djava.security.egd=file:/dev/./urandom \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Europe/Vienna \
-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus,gateway"
# Spring Boot specific optimizations
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_PROFILES_ACTIVE=docker \
SERVER_PORT=8080 \
MANAGEMENT_SERVER_PORT=8080 \
LOGGING_LEVEL_ROOT=INFO
# =============================================================================
# Health Check Configuration
# =============================================================================
# Enhanced health check with proper timing for Spring Boot startup
HEALTHCHECK --interval=15s --timeout=5s --start-period=60s --retries=3 \
CMD curl -fsS --max-time 3 http://localhost:8080/actuator/health/readiness || exit 1
# =============================================================================
# Application Startup
# =============================================================================
# Gateway-focused startup command with debug support
ENTRYPOINT ["sh", "-c", "\
echo 'Starting Meldestelle API Gateway on port 8080...'; \
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Debug mode enabled on port 5005'; \
exec java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 org.springframework.boot.loader.launch.JarLauncher; \
else \
exec java $JAVA_OPTS org.springframework.boot.loader.launch.JarLauncher; \
fi"]
# =============================================================================
# Documentation
# =============================================================================
# Build commands:
# docker build -t meldestelle/gateway:latest -f infrastructure/gateway/Dockerfile .
# docker run -p 8080:8080 --name gateway meldestelle/gateway:latest
#
# Key optimizations:
# - Multi-stage build with JAR layer extraction for better caching
# - Non-root user execution for security
# - Optimized JVM settings for containers
# - Comprehensive health checks
# - Proper timezone and encoding configuration
# - Security updates and minimal attack surface
# =============================================================================
@@ -0,0 +1,152 @@
# syntax=docker/dockerfile:1.7
# ===================================================================
# Dockerfile for Meldestelle Monitoring Server
# Based on spring-boot-service template with monitoring specifics
# ===================================================================
# Build arguments
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG SPRING_PROFILES_ACTIVE=docker
# ===================================================================
# Build Stage
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
LABEL stage=builder
LABEL service=monitoring-server
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
# Copy build files in optimal order for caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY platform/ platform/
COPY core/ core/
COPY build.gradle.kts ./
# Copy monitoring dependencies
COPY infrastructure/monitoring/monitoring-client/ infrastructure/monitoring/monitoring-client/
# Copy monitoring-server specific files
COPY infrastructure/monitoring/monitoring-server/build.gradle.kts infrastructure/monitoring/monitoring-server/
COPY infrastructure/monitoring/monitoring-server/src/ infrastructure/monitoring/monitoring-server/src/
# Build application
RUN ./gradlew :infrastructure:monitoring:monitoring-server:dependencies --no-daemon --info
RUN ./gradlew :infrastructure:monitoring:monitoring-server:bootJar --no-daemon --info \
-Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}
# ===================================================================
# Runtime Stage
# ===================================================================
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
# Comprehensive metadata
LABEL service="monitoring-server" \
version="1.0.0" \
description="Monitoring and Observability Server for Meldestelle" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}" \
spring.profiles.active="${SPRING_PROFILES_ACTIVE}"
# Build arguments for user configuration
ARG APP_USER=monitoruser
ARG APP_GROUP=monitorgroup
ARG APP_UID=1003
ARG APP_GID=1003
WORKDIR /app
# System setup with additional monitoring tools
RUN apk update && \
apk upgrade && \
apk add --no-cache curl jq tzdata ca-certificates netcat-openbsd && \
rm -rf /var/cache/apk/*
# Create non-root user for monitoring-server
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh
# Create required directories with proper permissions
RUN mkdir -p /app/logs /app/tmp /app/config /app/metrics && \
chown -R ${APP_USER}:${APP_GROUP} /app
# Copy the built JAR from builder stage
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} \
/workspace/infrastructure/monitoring/monitoring-server/build/libs/*.jar app.jar
# Switch to non-root user
USER ${APP_USER}
# Expose monitoring-server port and debug port
EXPOSE 8083 5005
# Enhanced health check for monitoring service
HEALTHCHECK --interval=10s --timeout=5s --start-period=45s --retries=3 \
CMD curl -fsS --max-time 3 http://localhost:8083/actuator/health/readiness || exit 1
# Optimized JVM settings for monitoring workloads
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-XX:G1HeapRegionSize=8m \
-XX:+OptimizeStringConcat \
-XX:+UseCompressedOops \
-XX:MaxMetaspaceSize=256m \
-Djava.security.egd=file:/dev/./urandom \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Europe/Vienna \
-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus,env,configprops,beans"
# Monitoring-server specific Spring Boot configuration
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE} \
SERVER_PORT=8083 \
MANAGEMENT_SERVER_PORT=8083 \
MANAGEMENT_ENDPOINTS_WEB_BASE_PATH=/actuator \
LOGGING_LEVEL_ROOT=INFO \
LOGGING_LEVEL_AT_MOCODE=DEBUG \
LOGGING_LEVEL_MICROMETER=DEBUG
# Monitoring-focused startup command with debug support
ENTRYPOINT ["sh", "-c", "\
echo 'Starting Meldestelle Monitoring Server on port 8083...'; \
echo 'Metrics endpoint: http://localhost:8083/actuator/metrics'; \
echo 'Prometheus endpoint: http://localhost:8083/actuator/prometheus'; \
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Debug mode enabled on port 5005'; \
exec java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar; \
else \
exec java $JAVA_OPTS -jar app.jar; \
fi"]
# ===================================================================
# Build and Usage Instructions
# ===================================================================
# Build:
# docker build -t meldestelle/monitoring-server:latest -f infrastructure/monitoring/monitoring-server/Dockerfile .
#
# Run standalone:
# docker run -p 8083:8083 --name monitoring-server meldestelle/monitoring-server:latest
#
# Run with debug:
# docker run -p 8083:8083 -p 5005:5005 -e DEBUG=true --name monitoring-server meldestelle/monitoring-server:latest
#
# Access endpoints:
# Health: http://localhost:8083/actuator/health
# Metrics: http://localhost:8083/actuator/metrics
# Prometheus: http://localhost:8083/actuator/prometheus
# ===================================================================
@@ -0,0 +1,143 @@
# syntax=docker/dockerfile:1.7
# ===================================================================
# Optimized Dockerfile for Spring Boot Ping Service
# Features: Multi-stage build, security hardening, monitoring support
# ===================================================================
# Build arguments for flexibility
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG ALPINE_VERSION=3.19
ARG SPRING_PROFILES_ACTIVE=default
# Build stage: compile the ping-service JAR inside Docker
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
# Add metadata labels
LABEL stage=builder
LABEL service=ping-service
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Optimize Gradle build settings for containerized builds
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
# Copy gradle wrapper and configuration files first for optimal caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
# Copy platform dependencies (changes less frequently)
COPY platform/ platform/
# Copy root build configuration
COPY build.gradle.kts ./
# Copy ping-service specific files last (changes most frequently)
COPY temp/ping-service/build.gradle.kts temp/ping-service/
COPY temp/ping-service/src/ temp/ping-service/src/
# Download and cache dependencies in a separate layer
RUN ./gradlew :temp:ping-service:dependencies --no-daemon --info
# Build the application with optimizations
RUN ./gradlew :temp:ping-service:bootJar --no-daemon --info \
-Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}
# ===================================================================
# Runtime stage: optimized JRE image for production
# ===================================================================
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
# Add comprehensive metadata
LABEL service="ping-service" \
version="1.0.0" \
description="Microservice demonstrating circuit breaker patterns and monitoring" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}" \
spring.profiles.active="${SPRING_PROFILES_ACTIVE}" \
build.date="${BUILD_DATE:-$(date -u +'%Y-%m-%dT%H:%M:%SZ')}"
# Build arguments for runtime configuration
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG APP_UID=1001
ARG APP_GID=1001
# Set working directory
WORKDIR /app
# Update Alpine packages and install required tools
RUN apk update && \
apk upgrade && \
apk add --no-cache \
curl \
jq \
tzdata && \
rm -rf /var/cache/apk/*
# Create non-root user with specific UID/GID for better security
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh
# Create required directories with proper permissions
RUN mkdir -p /app/logs /app/tmp && \
chown -R ${APP_USER}:${APP_GROUP} /app
# Copy the built JAR from builder stage with proper ownership
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} \
/workspace/temp/ping-service/build/libs/*.jar app.jar
# Switch to non-root user
USER ${APP_USER}
# Expose application port and debug port
EXPOSE 8082 5005
# Enhanced health check with better configuration
HEALTHCHECK --interval=15s --timeout=3s --start-period=40s --retries=3 \
CMD curl -fsS --max-time 2 http://localhost:8082/actuator/health/readiness || exit 1
# Optimized JVM settings for Spring Boot 3.x with monitoring support
ENV JAVA_OPTS_BASE="-XX:MaxRAMPercentage=80.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-XX:+OptimizeStringConcat \
-XX:+UseCompressedOops \
-Djava.security.egd=file:/dev/./urandom \
-Dspring.jmx.enabled=false \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Europe/Vienna"
# Monitoring and observability settings
ENV JAVA_OPTS_MONITORING="-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus \
-Dmanagement.endpoint.health.show-details=always \
-Dmanagement.metrics.export.prometheus.enabled=true"
# Development/debugging options (enabled via environment variables)
ENV JAVA_OPTS_DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
# Combined JAVA_OPTS (debug options only applied if DEBUG=true)
ENV JAVA_OPTS="${JAVA_OPTS_BASE} ${JAVA_OPTS_MONITORING}"
# Spring Boot configuration
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE} \
SERVER_PORT=8082 \
LOGGING_LEVEL_ROOT=INFO
# Optimized entrypoint with conditional debug support
ENTRYPOINT ["sh", "-c", "\
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Starting application in DEBUG mode on port 5005...'; \
exec java ${JAVA_OPTS} ${JAVA_OPTS_DEBUG} -jar app.jar; \
else \
exec java ${JAVA_OPTS} -jar app.jar; \
fi"]
@@ -0,0 +1,90 @@
# ===================================================================
# Multi-stage Dockerfile Template for Kotlin Multiplatform Web Client
# Features: Kotlin/JS compilation, Nginx serving, development support
# ===================================================================
# Build arguments
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG NGINX_VERSION=alpine
# ===================================================================
# Build Stage - Kotlin/JS Compilation
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS kotlin-builder
LABEL stage=kotlin-builder
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations for Kotlin Multiplatform
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx3g"
# Copy build configuration files first for optimal caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY build.gradle.kts ./
# Copy platform and core dependencies
COPY platform/ platform/
COPY core/ core/
# Copy client modules in dependency order
COPY client/common-ui/ client/common-ui/
COPY ${CLIENT_PATH}/ ${CLIENT_PATH}/
# Download dependencies in a separate layer
RUN ./gradlew :${CLIENT_MODULE}:dependencies --no-daemon --info
# Build web application with production optimizations
RUN ./gradlew :${CLIENT_MODULE}:jsBrowserProductionWebpack --no-daemon --info
# ===================================================================
# Production Stage - Nginx serving
# ===================================================================
FROM nginx:${NGINX_VERSION} AS runtime
# Metadata
LABEL service="${CLIENT_NAME}" \
version="1.0.0" \
description="Kotlin Multiplatform Web Client for Meldestelle" \
maintainer="Meldestelle Development Team"
# Security and system setup
RUN apk update && \
apk upgrade && \
apk add --no-cache curl && \
rm -rf /var/cache/apk/*
# Remove default nginx content
RUN rm -rf /usr/share/nginx/html/*
# Copy built web application from builder stage
COPY --from=kotlin-builder /workspace/${CLIENT_PATH}/build/dist/ /usr/share/nginx/html/
# Copy nginx configuration if exists, otherwise use default
COPY ${CLIENT_PATH}/nginx.conf /etc/nginx/nginx.conf
# Create non-root user for nginx (if not using default nginx user)
RUN adduser -D -s /bin/sh -G www-data nginx-user
# Set proper permissions
RUN chown -R nginx:nginx /usr/share/nginx/html /var/cache/nginx /var/run /var/log/nginx
# Health check for web application
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD curl -f http://localhost:80/ || exit 1
# Expose HTTP port
EXPOSE 80
# Start nginx with proper signal handling
STOPSIGNAL SIGQUIT
# Run nginx in foreground
CMD ["nginx", "-g", "daemon off;"]
@@ -0,0 +1,116 @@
# syntax=docker/dockerfile:1.7
# ===================================================================
# Multi-stage Dockerfile Template for Spring Boot Services
# Features: Security hardening, monitoring support, optimal caching
# ===================================================================
# Build arguments
ARG GRADLE_VERSION=8.14
ARG JAVA_VERSION=21
ARG ALPINE_VERSION=3.19
ARG SPRING_PROFILES_ACTIVE=default
# ===================================================================
# Build Stage
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
LABEL stage=builder
LABEL maintainer="Meldestelle Development Team"
WORKDIR /workspace
# Gradle optimizations
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
# Copy build files in optimal order for caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
COPY platform/ platform/
COPY build.gradle.kts ./
# Copy service-specific files (replace SERVICE_PATH with actual path)
COPY ${SERVICE_PATH}/build.gradle.kts ${SERVICE_PATH}/
COPY ${SERVICE_PATH}/src/ ${SERVICE_PATH}/src/
# Build application
RUN ./gradlew :${SERVICE_NAME}:dependencies --no-daemon --info
RUN ./gradlew :${SERVICE_NAME}:bootJar --no-daemon --info \
-Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}
# ===================================================================
# Runtime Stage
# ===================================================================
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
# Metadata
LABEL service="${SERVICE_NAME}" \
version="1.0.0" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}"
# Build arguments
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG APP_UID=1001
ARG APP_GID=1001
WORKDIR /app
# System setup
RUN apk update && \
apk upgrade && \
apk add --no-cache curl jq tzdata && \
rm -rf /var/cache/apk/*
# Non-root user creation
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh
# Directory setup
RUN mkdir -p /app/logs /app/tmp && \
chown -R ${APP_USER}:${APP_GROUP} /app
# Copy JAR
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} \
/workspace/${SERVICE_PATH}/build/libs/*.jar app.jar
USER ${APP_USER}
# Expose ports
EXPOSE ${SERVICE_PORT} 5005
# Health check
HEALTHCHECK --interval=15s --timeout=3s --start-period=40s --retries=3 \
CMD curl -fsS --max-time 2 http://localhost:${SERVICE_PORT}/actuator/health/readiness || exit 1
# JVM configuration
ENV JAVA_OPTS="-XX:MaxRAMPercentage=80.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-Djava.security.egd=file:/dev/./urandom \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=UTC \
-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus"
# Spring Boot configuration
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE} \
SERVER_PORT=${SERVICE_PORT} \
LOGGING_LEVEL_ROOT=INFO
# Startup command with debug support
ENTRYPOINT ["sh", "-c", "\
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Starting ${SERVICE_NAME} in DEBUG mode on port 5005...'; \
exec java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar; \
else \
exec java $JAVA_OPTS -jar app.jar; \
fi"]