fixing client
This commit is contained in:
@@ -1,186 +1,90 @@
|
||||
# Multi-stage build for Meldestelle Compose Desktop Application
|
||||
# Builds Kotlin/JVM (Compose Desktop) client and serves via VNC with noVNC web interface
|
||||
# ===================================================================
|
||||
# Multi-Stage Dockerfile für Meldestelle Desktop-App (VNC)
|
||||
# ===================================================================
|
||||
|
||||
# ===================================================================
|
||||
# CENTRALIZED BUILD ARGUMENTS
|
||||
# Values sourced from docker/versions.toml and docker/build-args/
|
||||
# Stage 1: Build Stage - Kotlin Desktop-App kompilieren
|
||||
# ===================================================================
|
||||
# Global arguments (docker/build-args/global.env)
|
||||
ARG GRADLE_VERSION
|
||||
ARG JAVA_VERSION
|
||||
ARG BUILD_DATE
|
||||
ARG VERSION
|
||||
FROM gradle:8-jdk21-alpine AS builder
|
||||
|
||||
# Client-specific arguments (docker/build-args/clients.env)
|
||||
ARG NODE_VERSION
|
||||
WORKDIR /app
|
||||
|
||||
# Desktop-specific arguments
|
||||
ARG UBUNTU_VERSION=22.04
|
||||
# Kopiere Gradle-Konfiguration
|
||||
COPY build.gradle.kts settings.gradle.kts gradle.properties ./
|
||||
COPY gradle ./gradle
|
||||
|
||||
# Kopiere alle notwendigen Module für Multi-Modul-Projekt
|
||||
COPY client ./client
|
||||
COPY core ./core
|
||||
COPY platform ./platform
|
||||
COPY infrastructure ./infrastructure
|
||||
COPY temp ./temp
|
||||
COPY docs ./docs
|
||||
|
||||
# Dependencies downloaden (für besseres Caching)
|
||||
RUN gradle :client:dependencies --no-configure-on-demand
|
||||
|
||||
# Desktop-App kompilieren (createDistributable für native Distribution)
|
||||
RUN gradle :client:createDistributable --no-configure-on-demand
|
||||
|
||||
# ===================================================================
|
||||
# Build Arguments for Client Configuration
|
||||
# Stage 2: Runtime Stage - Ubuntu mit VNC + noVNC
|
||||
# ===================================================================
|
||||
ARG CLIENT_PATH=client
|
||||
ARG CLIENT_MODULE=client
|
||||
FROM ubuntu:22.04
|
||||
|
||||
# ===================================================================
|
||||
# Build Stage - Kotlin/JVM (Compose Desktop) Compilation
|
||||
# ===================================================================
|
||||
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION} AS builder
|
||||
|
||||
ARG CLIENT_PATH=client
|
||||
ARG CLIENT_MODULE=client
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /build
|
||||
|
||||
# Set build labels
|
||||
LABEL service=desktop-app
|
||||
LABEL stage=build
|
||||
|
||||
# Copy Gradle files first for better layer caching
|
||||
COPY gradle/ gradle/
|
||||
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
|
||||
COPY build.gradle.kts ./
|
||||
|
||||
# Copy version catalog
|
||||
COPY gradle/libs.versions.toml gradle/libs.versions.toml
|
||||
|
||||
# Copy all source files needed for the build
|
||||
# Core and platform modules (dependencies)
|
||||
COPY core/ core/
|
||||
COPY platform/ platform/
|
||||
|
||||
# Infrastructure modules (if needed)
|
||||
COPY infrastructure/ infrastructure/
|
||||
|
||||
# Client modules
|
||||
COPY client/ client/
|
||||
|
||||
# Copy any additional required directories
|
||||
COPY temp/ temp/
|
||||
COPY docs/ docs/
|
||||
|
||||
# Make Gradle wrapper executable
|
||||
RUN chmod +x gradlew
|
||||
|
||||
# Build client application for JVM
|
||||
# Create distribution package for desktop application
|
||||
RUN echo "Building ${CLIENT_MODULE} module for JVM..." && \
|
||||
./gradlew ${CLIENT_MODULE}:createDistributable --no-daemon --stacktrace --info
|
||||
|
||||
# ===================================================================
|
||||
# Production Stage - VNC Desktop Environment
|
||||
# ===================================================================
|
||||
FROM ubuntu:${UBUNTU_VERSION} AS production
|
||||
|
||||
ARG CLIENT_PATH=client
|
||||
|
||||
# Set production labels
|
||||
LABEL service="desktop-app" \
|
||||
environment="production" \
|
||||
description="Meldestelle Compose Desktop Application with VNC"
|
||||
|
||||
# Set non-interactive mode and timezone for package installations
|
||||
# Verhindere interaktive Installationen
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Etc/UTC
|
||||
|
||||
# Install system dependencies
|
||||
# Installiere System-Dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
openjdk-21-jre-headless \
|
||||
openjdk-21-jdk \
|
||||
xvfb \
|
||||
x11vnc \
|
||||
fluxbox \
|
||||
websockify \
|
||||
novnc \
|
||||
websockify \
|
||||
xfce4 \
|
||||
xfce4-goodies \
|
||||
curl \
|
||||
wget \
|
||||
unzip \
|
||||
supervisor \
|
||||
tigervnc-common \
|
||||
tigervnc-standalone-server \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create application user
|
||||
RUN useradd -m -s /bin/bash appuser && \
|
||||
mkdir -p /home/appuser/.vnc
|
||||
# Arbeitsverzeichnis
|
||||
WORKDIR /app
|
||||
|
||||
# Set up VNC password using a separate RUN command
|
||||
RUN echo "meldestelle" | vncpasswd -f > /home/appuser/.vnc/passwd && \
|
||||
chmod 600 /home/appuser/.vnc/passwd && \
|
||||
chown -R appuser:appuser /home/appuser/.vnc
|
||||
# Kopiere kompilierte Desktop-App von Build-Stage
|
||||
COPY --from=builder /app/client/build/compose/binaries/main/desktop/ ./desktop-app/
|
||||
|
||||
# Copy built application from builder stage
|
||||
COPY --from=builder /build/${CLIENT_PATH}/build/compose/binaries/main/app/ /opt/meldestelle/
|
||||
# Kopiere Scripts
|
||||
COPY dockerfiles/clients/desktop-app/entrypoint.sh /entrypoint.sh
|
||||
COPY dockerfiles/clients/desktop-app/health-check.sh /opt/health-check.sh
|
||||
COPY dockerfiles/clients/desktop-app/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Ensure launcher script has execution permissions
|
||||
RUN chmod +x /opt/meldestelle/at.mocode/bin/at.mocode
|
||||
# Setze Permissions
|
||||
RUN chmod +x /entrypoint.sh /opt/health-check.sh
|
||||
|
||||
# Create VNC startup script
|
||||
RUN echo '#!/bin/bash' > /opt/start-vnc.sh && \
|
||||
echo 'export DISPLAY=:99' >> /opt/start-vnc.sh && \
|
||||
echo 'export VNC_PORT=5901' >> /opt/start-vnc.sh && \
|
||||
echo 'export NOVNC_PORT=6080' >> /opt/start-vnc.sh && \
|
||||
echo '' >> /opt/start-vnc.sh && \
|
||||
echo '# Start Xvfb' >> /opt/start-vnc.sh && \
|
||||
echo 'Xvfb :99 -screen 0 1024x768x16 &' >> /opt/start-vnc.sh && \
|
||||
echo 'sleep 2' >> /opt/start-vnc.sh && \
|
||||
echo '' >> /opt/start-vnc.sh && \
|
||||
echo '# Start window manager' >> /opt/start-vnc.sh && \
|
||||
echo 'fluxbox &' >> /opt/start-vnc.sh && \
|
||||
echo 'sleep 2' >> /opt/start-vnc.sh && \
|
||||
echo '' >> /opt/start-vnc.sh && \
|
||||
echo '# Start VNC server' >> /opt/start-vnc.sh && \
|
||||
echo 'x11vnc -display :99 -rfbauth /home/appuser/.vnc/passwd -listen localhost -xkb -ncache 10 -ncache_cr -rfbport $VNC_PORT &' >> /opt/start-vnc.sh && \
|
||||
echo 'sleep 2' >> /opt/start-vnc.sh && \
|
||||
echo '' >> /opt/start-vnc.sh && \
|
||||
echo '# Start noVNC' >> /opt/start-vnc.sh && \
|
||||
echo 'websockify --web=/usr/share/novnc/ $NOVNC_PORT localhost:$VNC_PORT &' >> /opt/start-vnc.sh && \
|
||||
echo 'sleep 2' >> /opt/start-vnc.sh && \
|
||||
echo '' >> /opt/start-vnc.sh && \
|
||||
echo '# Start the Meldestelle application' >> /opt/start-vnc.sh && \
|
||||
echo 'cd /opt/meldestelle' >> /opt/start-vnc.sh && \
|
||||
echo 'exec ./at.mocode/bin/at.mocode' >> /opt/start-vnc.sh
|
||||
# Erstelle VNC-User
|
||||
RUN useradd -m -s /bin/bash vncuser && \
|
||||
mkdir -p /home/vncuser/.vnc && \
|
||||
chown -R vncuser:vncuser /home/vncuser && \
|
||||
chown -R vncuser:vncuser /app
|
||||
|
||||
RUN chmod +x /opt/start-vnc.sh
|
||||
# VNC und noVNC Ports
|
||||
EXPOSE 5901 6080
|
||||
|
||||
# Create supervisor configuration
|
||||
RUN echo '[supervisord]' > /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'nodaemon=true' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'user=root' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo '' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo '[program:vnc-app]' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'command=/opt/start-vnc.sh' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'user=appuser' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'autorestart=true' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'stdout_logfile=/var/log/meldestelle.log' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'stderr_logfile=/var/log/meldestelle_error.log' >> /etc/supervisor/conf.d/meldestelle.conf && \
|
||||
echo 'environment=HOME="/home/appuser",USER="appuser"' >> /etc/supervisor/conf.d/meldestelle.conf
|
||||
|
||||
# Create health check script
|
||||
RUN echo '#!/bin/bash' > /opt/health-check.sh && \
|
||||
echo '# Check if noVNC is responding' >> /opt/health-check.sh && \
|
||||
echo 'curl -f http://localhost:6080/vnc.html > /dev/null 2>&1' >> /opt/health-check.sh && \
|
||||
echo 'exit $?' >> /opt/health-check.sh
|
||||
|
||||
RUN chmod +x /opt/health-check.sh
|
||||
|
||||
# Switch to application user for file permissions
|
||||
USER appuser
|
||||
|
||||
# Set environment variables
|
||||
# Environment Variables
|
||||
ENV DISPLAY=:99
|
||||
ENV VNC_PORT=5901
|
||||
ENV NOVNC_PORT=6080
|
||||
ENV API_BASE_URL=http://api-gateway:8081
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 6080 5901
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||||
# Health-Check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /opt/health-check.sh
|
||||
|
||||
# Switch back to root to start supervisor
|
||||
USER root
|
||||
# User wechseln
|
||||
USER vncuser
|
||||
|
||||
# Start supervisor which manages all services
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
|
||||
# Entrypoint
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
#!/bin/bash
|
||||
# ===================================================================
|
||||
# Entrypoint-Script für Meldestelle Desktop-App (VNC)
|
||||
# ===================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Logging-Funktion
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
||||
}
|
||||
|
||||
log "Starting Meldestelle Desktop-App VNC Container..."
|
||||
|
||||
# Environment-Variablen setzen
|
||||
export DISPLAY=${DISPLAY:-:99}
|
||||
export VNC_PORT=${VNC_PORT:-5901}
|
||||
export NOVNC_PORT=${NOVNC_PORT:-6080}
|
||||
export API_BASE_URL=${API_BASE_URL:-http://api-gateway:8081}
|
||||
|
||||
log "Environment:"
|
||||
log " DISPLAY: $DISPLAY"
|
||||
log " VNC_PORT: $VNC_PORT"
|
||||
log " NOVNC_PORT: $NOVNC_PORT"
|
||||
log " API_BASE_URL: $API_BASE_URL"
|
||||
|
||||
# Erstelle .Xauthority wenn nicht vorhanden
|
||||
touch /home/vncuser/.Xauthority
|
||||
|
||||
# 1. Starte X11 Virtual Display (Xvfb)
|
||||
log "Starting Xvfb on display $DISPLAY..."
|
||||
Xvfb $DISPLAY -screen 0 1280x1024x24 -ac +extension GLX +render -noreset &
|
||||
XVFB_PID=$!
|
||||
|
||||
# Warte bis X11 bereit ist
|
||||
sleep 3
|
||||
|
||||
# 2. Starte Desktop Environment (XFCE4)
|
||||
log "Starting XFCE4 desktop environment..."
|
||||
startxfce4 &
|
||||
XFCE_PID=$!
|
||||
|
||||
# Warte bis Desktop bereit ist
|
||||
sleep 5
|
||||
|
||||
# 3. Starte VNC Server
|
||||
log "Starting VNC server on port $VNC_PORT..."
|
||||
x11vnc -display $DISPLAY -forever -usepw -create -rfbport $VNC_PORT -nopw -shared -bg
|
||||
VNC_PID=$!
|
||||
|
||||
# 4. Starte noVNC Web Interface
|
||||
log "Starting noVNC web interface on port $NOVNC_PORT..."
|
||||
websockify --web=/usr/share/novnc/ $NOVNC_PORT localhost:$VNC_PORT &
|
||||
NOVNC_PID=$!
|
||||
|
||||
# 5. Warte bis Services bereit sind
|
||||
sleep 10
|
||||
|
||||
# 6. Starte Desktop-App
|
||||
log "Starting Meldestelle Desktop-App..."
|
||||
cd /app/desktop-app
|
||||
export API_BASE_URL=$API_BASE_URL
|
||||
|
||||
# Finde die ausführbare Datei
|
||||
if [ -f "client/bin/client" ]; then
|
||||
DESKTOP_APP="client/bin/client"
|
||||
elif [ -f "bin/client" ]; then
|
||||
DESKTOP_APP="bin/client"
|
||||
elif [ -f "client" ]; then
|
||||
DESKTOP_APP="client"
|
||||
else
|
||||
log "ERROR: Desktop-App executable not found!"
|
||||
log "Contents of /app/desktop-app:"
|
||||
ls -la /app/desktop-app/
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Found desktop app: $DESKTOP_APP"
|
||||
chmod +x "$DESKTOP_APP"
|
||||
|
||||
# Starte Desktop-App
|
||||
./"$DESKTOP_APP" &
|
||||
APP_PID=$!
|
||||
|
||||
log "All services started successfully!"
|
||||
log "VNC: vnc://localhost:$VNC_PORT"
|
||||
log "noVNC: http://localhost:$NOVNC_PORT/vnc.html"
|
||||
|
||||
# Cleanup-Funktion
|
||||
cleanup() {
|
||||
log "Shutting down services..."
|
||||
kill $APP_PID 2>/dev/null || true
|
||||
kill $NOVNC_PID 2>/dev/null || true
|
||||
kill $VNC_PID 2>/dev/null || true
|
||||
kill $XFCE_PID 2>/dev/null || true
|
||||
kill $XVFB_PID 2>/dev/null || true
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Signal-Handler
|
||||
trap cleanup SIGTERM SIGINT
|
||||
|
||||
# Warten auf Prozesse
|
||||
wait $APP_PID
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# ===================================================================
|
||||
# Health-Check-Script für Meldestelle Desktop-App (VNC)
|
||||
# ===================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Environment-Variablen
|
||||
VNC_PORT=${VNC_PORT:-5901}
|
||||
NOVNC_PORT=${NOVNC_PORT:-6080}
|
||||
DISPLAY=${DISPLAY:-:99}
|
||||
|
||||
# Logging-Funktion
|
||||
log() {
|
||||
echo "[HEALTH] $1"
|
||||
}
|
||||
|
||||
# 1. Überprüfe X11 Display
|
||||
if ! xdpyinfo -display $DISPLAY >/dev/null 2>&1; then
|
||||
log "ERROR: X11 display $DISPLAY is not running"
|
||||
exit 1
|
||||
fi
|
||||
log "✓ X11 display $DISPLAY is running"
|
||||
|
||||
# 2. Überprüfe VNC Server
|
||||
if ! netstat -ln | grep -q ":$VNC_PORT "; then
|
||||
log "ERROR: VNC server is not listening on port $VNC_PORT"
|
||||
exit 1
|
||||
fi
|
||||
log "✓ VNC server is running on port $VNC_PORT"
|
||||
|
||||
# 3. Überprüfe noVNC Web Interface
|
||||
if ! curl -f -s "http://localhost:$NOVNC_PORT/" > /dev/null 2>&1; then
|
||||
log "ERROR: noVNC web interface is not responding on port $NOVNC_PORT"
|
||||
exit 1
|
||||
fi
|
||||
log "✓ noVNC web interface is running on port $NOVNC_PORT"
|
||||
|
||||
# 4. Überprüfe ob Desktop-App läuft (optional, da sie crashen könnte)
|
||||
if pgrep -f "client" >/dev/null 2>&1; then
|
||||
log "✓ Desktop-App is running"
|
||||
else
|
||||
log "⚠ Desktop-App is not running (may have crashed or not started yet)"
|
||||
# Nicht als Fehler behandeln, da die App crashen könnte
|
||||
fi
|
||||
|
||||
# 5. Überprüfe Xvfb
|
||||
if ! pgrep -f "Xvfb" >/dev/null 2>&1; then
|
||||
log "ERROR: Xvfb is not running"
|
||||
exit 1
|
||||
fi
|
||||
log "✓ Xvfb is running"
|
||||
|
||||
# 6. Überprüfe XFCE4
|
||||
if ! pgrep -f "xfce4" >/dev/null 2>&1; then
|
||||
log "WARNING: XFCE4 desktop might not be running"
|
||||
# Nicht als kritischer Fehler behandeln
|
||||
else
|
||||
log "✓ XFCE4 desktop environment is running"
|
||||
fi
|
||||
|
||||
log "All critical services are healthy"
|
||||
exit 0
|
||||
@@ -0,0 +1,54 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
pidfile=/var/run/supervisord.pid
|
||||
|
||||
[program:xvfb]
|
||||
command=Xvfb :99 -screen 0 1280x1024x24 -ac +extension GLX +render -noreset
|
||||
user=vncuser
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=100
|
||||
stdout_logfile=/var/log/supervisor/xvfb.log
|
||||
stderr_logfile=/var/log/supervisor/xvfb.log
|
||||
|
||||
[program:xfce4]
|
||||
command=startxfce4
|
||||
user=vncuser
|
||||
environment=DISPLAY=":99"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=200
|
||||
stdout_logfile=/var/log/supervisor/xfce4.log
|
||||
stderr_logfile=/var/log/supervisor/xfce4.log
|
||||
|
||||
[program:vnc]
|
||||
command=x11vnc -display :99 -forever -usepw -create -rfbport 5901 -nopw -shared
|
||||
user=vncuser
|
||||
environment=DISPLAY=":99"
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=300
|
||||
stdout_logfile=/var/log/supervisor/vnc.log
|
||||
stderr_logfile=/var/log/supervisor/vnc.log
|
||||
|
||||
[program:novnc]
|
||||
command=websockify --web=/usr/share/novnc/ 6080 localhost:5901
|
||||
user=vncuser
|
||||
autostart=true
|
||||
autorestart=true
|
||||
priority=400
|
||||
stdout_logfile=/var/log/supervisor/novnc.log
|
||||
stderr_logfile=/var/log/supervisor/novnc.log
|
||||
|
||||
[program:desktop-app]
|
||||
command=/app/desktop-app/client/bin/client
|
||||
user=vncuser
|
||||
environment=DISPLAY=":99",API_BASE_URL="http://api-gateway:8081"
|
||||
directory=/app/desktop-app
|
||||
autostart=true
|
||||
autorestart=false
|
||||
priority=500
|
||||
stdout_logfile=/var/log/supervisor/desktop-app.log
|
||||
stderr_logfile=/var/log/supervisor/desktop-app.log
|
||||
@@ -1,171 +1,56 @@
|
||||
# syntax=docker/dockerfile:1.8
|
||||
|
||||
# ===================================================================
|
||||
# Multi-stage Dockerfile for Meldestelle Compose for Web Application
|
||||
# Features: BuildKit cache mounts, security hardening, optimal layer caching
|
||||
# Version: 2.0.0 - Enhanced optimization and security
|
||||
# Multi-Stage Dockerfile für Meldestelle Web-App (Kotlin/JS)
|
||||
# ===================================================================
|
||||
|
||||
# === CENTRALIZED BUILD ARGUMENTS ===
|
||||
# Values sourced from docker/versions.toml and docker/build-args/
|
||||
# Global arguments (docker/build-args/global.env)
|
||||
ARG GRADLE_VERSION
|
||||
ARG JAVA_VERSION
|
||||
ARG BUILD_DATE
|
||||
ARG VERSION
|
||||
# ===================================================================
|
||||
# Stage 1: Build Stage - Kotlin/JS kompilieren
|
||||
# ===================================================================
|
||||
FROM gradle:8-jdk21-alpine AS builder
|
||||
|
||||
# Client-specific arguments (docker/build-args/clients.env)
|
||||
ARG NGINX_VERSION
|
||||
ARG NODE_VERSION
|
||||
WORKDIR /app
|
||||
|
||||
# Kopiere Gradle-Konfiguration und Wrapper
|
||||
COPY build.gradle.kts settings.gradle.kts gradle.properties ./
|
||||
COPY gradle ./gradle
|
||||
COPY gradlew ./
|
||||
|
||||
# Kopiere alle notwendigen Module für Multi-Modul-Projekt
|
||||
COPY client ./client
|
||||
COPY core ./core
|
||||
COPY platform ./platform
|
||||
COPY infrastructure ./infrastructure
|
||||
COPY temp ./temp
|
||||
COPY docs ./docs
|
||||
|
||||
# Setze Gradle-Wrapper Berechtigung
|
||||
RUN chmod +x ./gradlew
|
||||
|
||||
# Dependencies downloaden (für besseres Caching)
|
||||
RUN ./gradlew :client:dependencies --no-configure-on-demand
|
||||
|
||||
# Kotlin/JS Web-App kompilieren
|
||||
RUN ./gradlew :client:jsBrowserDistribution --no-configure-on-demand
|
||||
|
||||
# ===================================================================
|
||||
# Build Arguments for Client Configuration
|
||||
# Stage 2: Runtime Stage - Nginx für Static Files + API Proxy
|
||||
# ===================================================================
|
||||
ARG CLIENT_PATH=client
|
||||
ARG CLIENT_MODULE=client
|
||||
FROM nginx:1.25-alpine
|
||||
|
||||
# ===================================================================
|
||||
# Build Stage - Kotlin/JS (Compose for Web) Compilation
|
||||
# ===================================================================
|
||||
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
|
||||
# Installiere curl für Health-Checks
|
||||
RUN apk add --no-cache curl
|
||||
|
||||
ARG CLIENT_PATH=client
|
||||
ARG CLIENT_MODULE=client
|
||||
ARG BUILD_DATE
|
||||
ARG VERSION=1.0.0
|
||||
# Kopiere kompilierte Web-App von Build-Stage
|
||||
COPY --from=builder /app/client/build/dist/js/productionExecutable/ /usr/share/nginx/html/
|
||||
|
||||
# Enhanced metadata
|
||||
LABEL stage=builder \
|
||||
service="web-app" \
|
||||
maintainer="Meldestelle Development Team" \
|
||||
version="${VERSION}" \
|
||||
build.date="${BUILD_DATE}"
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /build
|
||||
|
||||
# Gradle optimizations for containerized builds
|
||||
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
|
||||
-Dorg.gradle.daemon=false \
|
||||
-Dorg.gradle.parallel=true \
|
||||
-Dorg.gradle.configureondemand=true \
|
||||
-Dorg.gradle.workers.max=2 \
|
||||
-Dorg.gradle.jvmargs=-Xmx2g \
|
||||
-XX:+UseParallelGC \
|
||||
-XX:MaxMetaspaceSize=512m"
|
||||
|
||||
# Set Gradle user home for better caching
|
||||
ENV GRADLE_USER_HOME=/home/gradle/.gradle
|
||||
|
||||
# Install Node.js for Kotlin/Wasm npm operations
|
||||
#ARG NODE_VERSION
|
||||
#RUN apk add --no-cache \
|
||||
# nodejs \
|
||||
# npm \
|
||||
# curl && \
|
||||
# # Verify installation \
|
||||
# node --version && \
|
||||
# npm --version && \
|
||||
# # Create Gradle Node.js directory structure and symlinks \
|
||||
# mkdir -p /home/gradle/.gradle/nodejs/node-v22.0.0-linux-x64/bin && \
|
||||
# ln -sf /usr/bin/node /home/gradle/.gradle/nodejs/node-v22.0.0-linux-x64/bin/node && \
|
||||
# ln -sf /usr/bin/npm /home/gradle/.gradle/nodejs/node-v22.0.0-linux-x64/bin/npm && \
|
||||
# chown -R gradle:gradle /home/gradle/.gradle
|
||||
|
||||
# Copy Gradle files first for better layer caching
|
||||
COPY gradle/ gradle/
|
||||
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
|
||||
COPY build.gradle.kts ./
|
||||
|
||||
# Copy version catalog
|
||||
COPY gradle/libs.versions.toml gradle/libs.versions.toml
|
||||
|
||||
# Copy all source files needed for the build
|
||||
# Core and platform modules (dependencies)
|
||||
COPY core/ core/
|
||||
COPY platform/ platform/
|
||||
|
||||
# Infrastructure modules (if needed)
|
||||
COPY infrastructure/ infrastructure/
|
||||
|
||||
# Client modules
|
||||
COPY client/ client/
|
||||
|
||||
# Copy any additional required directories
|
||||
COPY temp/ temp/
|
||||
COPY docs/ docs/
|
||||
|
||||
# Make Gradle wrapper executable
|
||||
RUN chmod +x gradlew
|
||||
|
||||
# Download and cache dependencies with BuildKit cache mount
|
||||
RUN --mount=type=cache,target=/home/gradle/.gradle/caches \
|
||||
--mount=type=cache,target=/home/gradle/.gradle/wrapper \
|
||||
./gradlew ${CLIENT_MODULE}:dependencies --no-daemon --info
|
||||
|
||||
# Build client application with BuildKit cache mount
|
||||
# For Compose Multiplatform Web (WASM), wasmJsBrowserDistribution produces static assets
|
||||
RUN --mount=type=cache,target=/home/gradle/.gradle/caches \
|
||||
--mount=type=cache,target=/home/gradle/.gradle/wrapper \
|
||||
echo "Building ${CLIENT_MODULE} module..." && \
|
||||
./gradlew ${CLIENT_MODULE}:wasmJsBrowserDistribution --no-daemon --stacktrace --info
|
||||
|
||||
# ===================================================================
|
||||
# Production Stage - Nginx Static File Server
|
||||
# ===================================================================
|
||||
FROM nginx:${NGINX_VERSION} AS production
|
||||
|
||||
ARG CLIENT_PATH=client
|
||||
ARG BUILD_DATE
|
||||
ARG VERSION=1.0.0
|
||||
|
||||
# Enhanced metadata
|
||||
LABEL service="web-app" \
|
||||
version="${VERSION}" \
|
||||
environment="production" \
|
||||
description="Meldestelle Compose for Web Application served via Nginx" \
|
||||
maintainer="Meldestelle Development Team" \
|
||||
build.date="${BUILD_DATE}" \
|
||||
org.opencontainers.image.title="Meldestelle Web App" \
|
||||
org.opencontainers.image.description="Kotlin Multiplatform Web application with WASM" \
|
||||
org.opencontainers.image.version="${VERSION}" \
|
||||
org.opencontainers.image.created="${BUILD_DATE}"
|
||||
|
||||
# Enhanced Alpine setup with security hardening
|
||||
RUN apk update && \
|
||||
apk upgrade && \
|
||||
apk add --no-cache \
|
||||
curl \
|
||||
tzdata && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
addgroup -g 1001 -S nginx-group && \
|
||||
adduser -S -D -H -u 1001 -h /var/cache/nginx -s /sbin/nologin -G nginx-group -g nginx nginx-user
|
||||
|
||||
# Copy built distribution files from builder stage (WASM build output)
|
||||
COPY --from=builder /build/${CLIENT_PATH}/build/dist/wasmJs/productionExecutable/ /usr/share/nginx/html/
|
||||
COPY --from=builder /build/${CLIENT_PATH}/src/wasmJsMain/resources/ /usr/share/nginx/html/
|
||||
|
||||
# Copy custom nginx configuration
|
||||
# Kopiere Nginx-Konfiguration
|
||||
COPY dockerfiles/clients/web-app/nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Create log directories and set permissions
|
||||
RUN mkdir -p /var/log/nginx && \
|
||||
chown -R nginx-user:nginx-group /var/log/nginx && \
|
||||
chown -R nginx-user:nginx-group /var/cache/nginx && \
|
||||
chown -R nginx-user:nginx-group /usr/share/nginx/html
|
||||
|
||||
# Health check endpoint
|
||||
RUN echo '{"status":"ok","service":"web-app"}' > /usr/share/nginx/html/health
|
||||
|
||||
# Switch to non-root user
|
||||
USER nginx-user
|
||||
|
||||
# Expose port
|
||||
# Exponiere Port 4000 (statt Standard 80)
|
||||
EXPOSE 4000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD curl --fail http://localhost:4000/health || exit 1
|
||||
# Health-Check für Container
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
||||
CMD curl -f http://localhost:4000/ || exit 1
|
||||
|
||||
# Start nginx
|
||||
# Starte Nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
@@ -1,33 +1,24 @@
|
||||
# Running as non-root user defined by container user; omit nginx "user" directive
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /tmp/nginx.pid;
|
||||
# ===================================================================
|
||||
# Nginx-Konfiguration für Meldestelle Web-App
|
||||
# Static Files + API Proxy zu Gateway
|
||||
# ===================================================================
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
# Logging
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 4096;
|
||||
|
||||
# Gzip Settings
|
||||
# Gzip Kompression für bessere Performance
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 10240;
|
||||
gzip_proxied expired no-cache no-store private auth;
|
||||
gzip_min_length 1024;
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
@@ -35,67 +26,55 @@ http {
|
||||
text/javascript
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/json
|
||||
image/svg+xml;
|
||||
application/json;
|
||||
|
||||
# Security Headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self';" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
# Upstream für API Gateway
|
||||
upstream api-gateway {
|
||||
server api-gateway:8081;
|
||||
}
|
||||
|
||||
# Server-Block für Web-App
|
||||
server {
|
||||
listen 4000;
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Main application route
|
||||
# Serve static files (Kotlin/JS compiled files)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
||||
# Cache static assets
|
||||
# Cache-Headers für statische Assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
|
||||
# Source maps - no cache for development
|
||||
location ~* \.map$ {
|
||||
expires off;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
}
|
||||
}
|
||||
|
||||
# Handle webpack development paths (return 404 gracefully)
|
||||
location ~* ^/webpack:// {
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Health check endpoint
|
||||
location /health {
|
||||
access_log off;
|
||||
add_header Content-Type application/json;
|
||||
return 200 '{"status":"ok","service":"web-app"}\n';
|
||||
}
|
||||
|
||||
# API proxy (if needed for backend communication)
|
||||
# Proxy API calls zu Gateway
|
||||
location /api/ {
|
||||
proxy_pass http://api-gateway:8081/;
|
||||
proxy_pass http://api-gateway;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# CORS Headers für API-Calls
|
||||
add_header Access-Control-Allow-Origin *;
|
||||
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Content-Type, Authorization";
|
||||
|
||||
# Handle preflight requests
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# Error pages
|
||||
error_page 404 /index.html;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
# Health-Check Endpoint
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "healthy\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user