fixing(gradle)
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
# syntax=docker/dockerfile:1.7
|
||||
# syntax=docker/dockerfile:1.8
|
||||
|
||||
# ===================================================================
|
||||
# Optimized Dockerfile for Spring Boot Ping Service
|
||||
# Features: Multi-stage build, security hardening, monitoring support
|
||||
# Features: Multi-stage build, security hardening, monitoring support, enhanced caching
|
||||
# ===================================================================
|
||||
|
||||
# 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
|
||||
@@ -42,11 +41,15 @@ COPY build.gradle.kts ./
|
||||
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
|
||||
# Download and cache dependencies in a separate layer with build cache
|
||||
RUN --mount=type=cache,target=/home/gradle/.gradle/caches \
|
||||
--mount=type=cache,target=/home/gradle/.gradle/wrapper \
|
||||
./gradlew :temp:ping-service:dependencies --no-daemon --info
|
||||
|
||||
# Build the application with optimizations
|
||||
RUN ./gradlew :temp:ping-service:bootJar --no-daemon --info \
|
||||
# Build the application with optimizations and build cache
|
||||
RUN --mount=type=cache,target=/home/gradle/.gradle/caches \
|
||||
--mount=type=cache,target=/home/gradle/.gradle/wrapper \
|
||||
./gradlew :temp:ping-service:bootJar --no-daemon --info \
|
||||
-Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}
|
||||
|
||||
# ===================================================================
|
||||
@@ -54,6 +57,10 @@ RUN ./gradlew :temp:ping-service:bootJar --no-daemon --info \
|
||||
# ===================================================================
|
||||
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
|
||||
|
||||
# Build arguments for runtime stage
|
||||
ARG BUILD_DATE
|
||||
ARG SPRING_PROFILES_ACTIVE=default
|
||||
|
||||
# Add comprehensive metadata
|
||||
LABEL service="ping-service" \
|
||||
version="1.0.0" \
|
||||
@@ -61,7 +68,7 @@ LABEL service="ping-service" \
|
||||
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.date="${BUILD_DATE}"
|
||||
|
||||
# Build arguments for runtime configuration
|
||||
ARG APP_USER=appuser
|
||||
@@ -72,21 +79,16 @@ ARG APP_GID=1001
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Update Alpine packages and install required tools
|
||||
# Update Alpine packages, install tools, create user and directories in one layer
|
||||
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 && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
addgroup -g ${APP_GID} -S ${APP_GROUP} && \
|
||||
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh && \
|
||||
mkdir -p /app/logs /app/tmp && \
|
||||
chown -R ${APP_USER}:${APP_GROUP} /app
|
||||
|
||||
# Copy the built JAR from builder stage with proper ownership
|
||||
@@ -103,41 +105,33 @@ EXPOSE 8082 5005
|
||||
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 \
|
||||
# Optimized JVM settings for Spring Boot 3.x with Java 21 and monitoring support
|
||||
ENV JAVA_OPTS="-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 \
|
||||
-Duser.timezone=Europe/Vienna \
|
||||
-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
|
||||
# Enhanced entrypoint with conditional debug support and better logging
|
||||
ENTRYPOINT ["sh", "-c", "\
|
||||
echo 'Starting ping-service with Java ${JAVA_VERSION}...'; \
|
||||
echo 'Active Spring profiles: ${SPRING_PROFILES_ACTIVE}'; \
|
||||
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
|
||||
echo 'Starting application in DEBUG mode on port 5005...'; \
|
||||
exec java ${JAVA_OPTS} ${JAVA_OPTS_DEBUG} -jar app.jar; \
|
||||
echo 'DEBUG mode enabled - remote debugging available on port 5005'; \
|
||||
exec java ${JAVA_OPTS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar; \
|
||||
else \
|
||||
echo 'Starting application in production mode'; \
|
||||
exec java ${JAVA_OPTS} -jar app.jar; \
|
||||
fi"]
|
||||
|
||||
Reference in New Issue
Block a user