fixing(gradle)
This commit is contained in:
@@ -7,18 +7,38 @@
|
||||
ARG GRADLE_VERSION=8.14
|
||||
ARG JAVA_VERSION=21
|
||||
ARG NGINX_VERSION=alpine
|
||||
ARG NODE_VERSION=20.11.0
|
||||
|
||||
# Client-specific build arguments (parametrized for better maintainability)
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
|
||||
# ===================================================================
|
||||
# Build Stage - Kotlin/JS Compilation
|
||||
# ===================================================================
|
||||
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS kotlin-builder
|
||||
|
||||
# Re-declare build arguments for kotlin-builder stage
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
ARG NODE_VERSION=20.11.0
|
||||
|
||||
LABEL stage=kotlin-builder
|
||||
LABEL service=web-app
|
||||
LABEL maintainer="Meldestelle Development Team"
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
# Install specific Node.js version for Kotlin/JS compatibility
|
||||
RUN apk add --no-cache wget ca-certificates && \
|
||||
wget -q -O - https://unofficial-builds.nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64-musl.tar.xz | \
|
||||
tar -xJ -C /usr/local --strip-components=1 && \
|
||||
apk del wget ca-certificates && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
npm config set cache /tmp/.npm-cache && \
|
||||
npm config set progress false && \
|
||||
npm config set audit false
|
||||
|
||||
# Gradle optimizations for Kotlin Multiplatform builds
|
||||
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
|
||||
-Dorg.gradle.daemon=false \
|
||||
@@ -27,6 +47,11 @@ ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
|
||||
-Dorg.gradle.jvmargs=-Xmx3g \
|
||||
-Dkotlin.compiler.execution.strategy=in-process"
|
||||
|
||||
# Kotlin/JS and Node.js environment variables
|
||||
ENV NODE_OPTIONS="--max-old-space-size=4096" \
|
||||
NPM_CONFIG_CACHE="/tmp/.npm-cache" \
|
||||
KOTLIN_JS_GENERATE_EXTERNALS=false
|
||||
|
||||
# Copy build configuration files first for optimal Docker layer caching
|
||||
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
|
||||
COPY gradle/ gradle/
|
||||
@@ -38,22 +63,33 @@ 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/
|
||||
COPY ${CLIENT_PATH}/ ${CLIENT_PATH}/
|
||||
|
||||
# Clear npm cache and verify Node.js installation
|
||||
RUN npm cache clean --force && \
|
||||
node --version && npm --version
|
||||
|
||||
# Download and cache dependencies in a separate layer
|
||||
RUN ./gradlew :client:web-app:dependencies --no-daemon --info
|
||||
RUN ./gradlew :${CLIENT_MODULE}:dependencies --no-daemon --info --stacktrace
|
||||
|
||||
# Build web application with production optimizations
|
||||
RUN ./gradlew :client:web-app:jsBrowserProductionWebpack --no-daemon --info
|
||||
# Build web application with production optimizations and better error handling
|
||||
RUN ./gradlew :${CLIENT_MODULE}:jsBrowserProductionWebpack --no-daemon --info --stacktrace --debug
|
||||
|
||||
# Verify build output
|
||||
RUN ls -la /workspace/client/web-app/build/dist/ || (echo "Build failed - no dist directory found" && exit 1)
|
||||
RUN ls -la /workspace/${CLIENT_PATH}/build/dist/ || (echo "Build failed - no dist directory found" && exit 1)
|
||||
|
||||
# ===================================================================
|
||||
# Production Stage - Nginx serving
|
||||
# ===================================================================
|
||||
FROM nginx:${NGINX_VERSION} AS runtime
|
||||
|
||||
# Re-declare build arguments for runtime stage
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
ARG GRADLE_VERSION=8.14
|
||||
ARG JAVA_VERSION=21
|
||||
ARG NGINX_VERSION=alpine
|
||||
|
||||
# Comprehensive metadata
|
||||
LABEL service="web-app" \
|
||||
version="1.0.0" \
|
||||
@@ -74,10 +110,10 @@ 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 --from=kotlin-builder /workspace/${CLIENT_PATH}/build/dist/ /usr/share/nginx/html/
|
||||
|
||||
# Copy optimized nginx configuration
|
||||
COPY client/web-app/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY ${CLIENT_PATH}/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 && \
|
||||
@@ -102,8 +138,15 @@ 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 .
|
||||
# Build with default parameters:
|
||||
# docker build -t meldestelle/web-app:latest -f dockerfiles/clients/web-app/Dockerfile .
|
||||
#
|
||||
# Build with custom parameters:
|
||||
# docker build -t meldestelle/web-app:latest \
|
||||
# --build-arg NODE_VERSION=20.11.0 \
|
||||
# --build-arg CLIENT_PATH=client/web-app \
|
||||
# --build-arg CLIENT_MODULE=client:web-app \
|
||||
# -f dockerfiles/clients/web-app/Dockerfile .
|
||||
#
|
||||
# Run standalone:
|
||||
# docker run -p 3001:80 --name web-app meldestelle/web-app:latest
|
||||
@@ -116,4 +159,11 @@ CMD ["sh", "-c", "nginx -t && exec nginx -g 'daemon off;'"]
|
||||
# http://localhost:3001/health (health check)
|
||||
#
|
||||
# Development with hot-reload (use docker-compose.override.yml instead)
|
||||
#
|
||||
# Optimization improvements:
|
||||
# - Added Node.js v20.11.0 for optimal Kotlin/JS compatibility
|
||||
# - Parametrized build arguments for better maintainability
|
||||
# - Enhanced npm and Node.js environment variables
|
||||
# - Improved error handling with --stacktrace and --debug flags
|
||||
# - npm cache management for better performance
|
||||
# ===================================================================
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -7,23 +7,51 @@
|
||||
ARG GRADLE_VERSION=8.14
|
||||
ARG JAVA_VERSION=21
|
||||
ARG NGINX_VERSION=alpine
|
||||
ARG NODE_VERSION=20.11.0
|
||||
|
||||
# Client-specific build arguments (can be overridden at build time)
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
ARG CLIENT_NAME=web-app
|
||||
|
||||
# ===================================================================
|
||||
# Build Stage - Kotlin/JS Compilation
|
||||
# ===================================================================
|
||||
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS kotlin-builder
|
||||
|
||||
# Re-declare build arguments for kotlin-builder stage
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
ARG CLIENT_NAME=web-app
|
||||
ARG NODE_VERSION=20.11.0
|
||||
|
||||
LABEL stage=kotlin-builder
|
||||
LABEL maintainer="Meldestelle Development Team"
|
||||
|
||||
WORKDIR /workspace
|
||||
|
||||
# Gradle optimizations for Kotlin Multiplatform
|
||||
# Install specific Node.js version for Kotlin/JS compatibility
|
||||
RUN apk add --no-cache wget ca-certificates && \
|
||||
wget -q -O - https://unofficial-builds.nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64-musl.tar.xz | \
|
||||
tar -xJ -C /usr/local --strip-components=1 && \
|
||||
apk del wget ca-certificates && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
npm config set cache /tmp/.npm-cache && \
|
||||
npm config set progress false && \
|
||||
npm config set audit false
|
||||
|
||||
# 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 \
|
||||
-Xmx3g"
|
||||
-Dorg.gradle.jvmargs=-Xmx3g \
|
||||
-Dkotlin.compiler.execution.strategy=in-process"
|
||||
|
||||
# Kotlin/JS and Node.js environment variables
|
||||
ENV NODE_OPTIONS="--max-old-space-size=4096" \
|
||||
NPM_CONFIG_CACHE="/tmp/.npm-cache" \
|
||||
KOTLIN_JS_GENERATE_EXTERNALS=false
|
||||
|
||||
# Copy build configuration files first for optimal caching
|
||||
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
|
||||
@@ -38,17 +66,29 @@ COPY core/ core/
|
||||
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
|
||||
# Clear npm cache and verify Node.js installation
|
||||
RUN npm cache clean --force && \
|
||||
node --version && npm --version
|
||||
|
||||
# Build web application with production optimizations
|
||||
RUN ./gradlew :${CLIENT_MODULE}:jsBrowserProductionWebpack --no-daemon --info
|
||||
# Download dependencies in a separate layer
|
||||
RUN ./gradlew :${CLIENT_MODULE}:dependencies --no-daemon --info --stacktrace
|
||||
|
||||
# Build web application with production optimizations and better error handling
|
||||
RUN ./gradlew :${CLIENT_MODULE}:jsBrowserProductionWebpack --no-daemon --info --stacktrace --debug
|
||||
|
||||
# Verify build output
|
||||
RUN ls -la /workspace/${CLIENT_PATH}/build/dist/ || (echo "Build failed - no dist directory found" && exit 1)
|
||||
|
||||
# ===================================================================
|
||||
# Production Stage - Nginx serving
|
||||
# ===================================================================
|
||||
FROM nginx:${NGINX_VERSION} AS runtime
|
||||
|
||||
# Re-declare build arguments for runtime stage
|
||||
ARG CLIENT_PATH=client/web-app
|
||||
ARG CLIENT_MODULE=client:web-app
|
||||
ARG CLIENT_NAME=web-app
|
||||
|
||||
# Metadata
|
||||
LABEL service="${CLIENT_NAME}" \
|
||||
version="1.0.0" \
|
||||
@@ -58,33 +98,35 @@ LABEL service="${CLIENT_NAME}" \
|
||||
# Security and system setup
|
||||
RUN apk update && \
|
||||
apk upgrade && \
|
||||
apk add --no-cache curl && \
|
||||
apk add --no-cache curl jq && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
# Remove default nginx content
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
# 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_PATH}/build/dist/ /usr/share/nginx/html/
|
||||
|
||||
# Copy nginx configuration if exists, otherwise use default
|
||||
# Copy nginx configuration
|
||||
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 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
|
||||
|
||||
# Set proper permissions
|
||||
RUN chown -R nginx:nginx /usr/share/nginx/html /var/cache/nginx /var/run /var/log/nginx
|
||||
# Switch to nginx user for security
|
||||
USER nginx
|
||||
|
||||
# Health check for web application
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD curl -f http://localhost:80/ || exit 1
|
||||
# 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
|
||||
# Start nginx with proper signal handling for graceful shutdowns
|
||||
STOPSIGNAL SIGQUIT
|
||||
|
||||
# Run nginx in foreground
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
# Run nginx in foreground with error handling
|
||||
CMD ["sh", "-c", "nginx -t && exec nginx -g 'daemon off;'"]
|
||||
|
||||
@@ -10,12 +10,21 @@ ARG GRADLE_VERSION=8.14
|
||||
ARG JAVA_VERSION=21
|
||||
ARG ALPINE_VERSION=3.19
|
||||
ARG SPRING_PROFILES_ACTIVE=default
|
||||
ARG SERVICE_PATH=.
|
||||
ARG SERVICE_NAME=spring-boot-service
|
||||
ARG SERVICE_PORT=8080
|
||||
|
||||
# ===================================================================
|
||||
# Build Stage
|
||||
# ===================================================================
|
||||
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
|
||||
|
||||
# Re-declare build arguments for this stage
|
||||
ARG SERVICE_PATH=.
|
||||
ARG SERVICE_NAME=spring-boot-service
|
||||
ARG SERVICE_PORT=8080
|
||||
ARG SPRING_PROFILES_ACTIVE=default
|
||||
|
||||
LABEL stage=builder
|
||||
LABEL maintainer="Meldestelle Development Team"
|
||||
|
||||
@@ -34,14 +43,28 @@ 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}
|
||||
# Create standalone project structure when using template generically
|
||||
RUN if [ "${SERVICE_PATH}" = "." ]; then \
|
||||
echo "Creating isolated standalone Spring Boot application..."; \
|
||||
mkdir -p /tmp/standalone-app/src/main/kotlin/com/example /tmp/standalone-app/src/main/resources; \
|
||||
cd /tmp/standalone-app; \
|
||||
echo 'plugins { id("org.springframework.boot") version "3.2.0"; id("io.spring.dependency-management") version "1.1.4"; kotlin("jvm") version "2.2.0"; kotlin("plugin.spring") version "2.2.0" }' > build.gradle.kts; \
|
||||
echo 'group = "com.example"; version = "1.0.0"; java { sourceCompatibility = JavaVersion.VERSION_21 }' >> build.gradle.kts; \
|
||||
echo 'repositories { mavenCentral() }' >> build.gradle.kts; \
|
||||
echo 'dependencies { implementation("org.springframework.boot:spring-boot-starter-web"); testImplementation("org.springframework.boot:spring-boot-starter-test") }' >> build.gradle.kts; \
|
||||
echo 'package com.example; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.runApplication; @SpringBootApplication class Application; fun main(args: Array<String>) { runApplication<Application>(*args) }' > src/main/kotlin/com/example/Application.kt; \
|
||||
echo 'rootProject.name = "standalone-app"' > settings.gradle.kts; \
|
||||
cp /workspace/gradlew /workspace/gradlew.bat .; \
|
||||
cp -r /workspace/gradle .; \
|
||||
echo "Building standalone application..."; \
|
||||
./gradlew bootJar --no-daemon --info -Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}; \
|
||||
cp build/libs/*.jar /workspace/app.jar; \
|
||||
else \
|
||||
echo "Building specific service: ${SERVICE_NAME}"; \
|
||||
./gradlew :${SERVICE_NAME}:dependencies --no-daemon --info; \
|
||||
./gradlew :${SERVICE_NAME}:bootJar --no-daemon --info -Pspring.profiles.active=${SPRING_PROFILES_ACTIVE}; \
|
||||
cp ${SERVICE_PATH}/build/libs/*.jar /workspace/app.jar; \
|
||||
fi
|
||||
|
||||
# ===================================================================
|
||||
# Runtime Stage
|
||||
@@ -76,9 +99,14 @@ RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
|
||||
RUN mkdir -p /app/logs /app/tmp && \
|
||||
chown -R ${APP_USER}:${APP_GROUP} /app
|
||||
|
||||
# Copy JAR
|
||||
# Re-declare build arguments for runtime stage
|
||||
ARG SERVICE_PATH=.
|
||||
ARG SERVICE_NAME=spring-boot-service
|
||||
ARG SERVICE_PORT=8080
|
||||
|
||||
# Copy JAR (different locations for standalone vs service-specific builds)
|
||||
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} \
|
||||
/workspace/${SERVICE_PATH}/build/libs/*.jar app.jar
|
||||
/workspace/app.jar app.jar
|
||||
|
||||
USER ${APP_USER}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user