From 64c257f050eb26bbc018c335ed4641cc8eb595e5 Mon Sep 17 00:00:00 2001 From: Daniel S Date: Sun, 9 Aug 2026 22:05:48 +0200 Subject: [PATCH] feat(docker): add automatic container entrypoint seeding script --- Dockerfile | 9 ++++-- docker-compose.yml | 18 ++++++----- docker-entrypoint.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 19211d5..ff8aaec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,16 +18,18 @@ ENV HOST=0.0.0.0 ENV PORT=3000 ENV DATA_DIR=/app/data -# Erstelle Kunden-Volume Ordner -RUN mkdir -p /app/data && chown -R node:node /app +# Ordner anlegen & Schreibrechte vorbereiten +RUN mkdir -p /app/data COPY package*.json ./ RUN npm ci --only=production COPY --from=builder /app/dist ./dist COPY --from=builder /app/public ./public +COPY docker-entrypoint.sh /app/docker-entrypoint.sh -USER node +# Ausführungsrechte für das Entrypoint-Skript setzen +RUN chmod +x /app/docker-entrypoint.sh EXPOSE 3000 @@ -35,4 +37,5 @@ EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1 +ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["node", "./dist/server/entry.mjs"] diff --git a/docker-compose.yml b/docker-compose.yml index 9a982e3..249aa09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,25 @@ version: '3.8' services: - kunden_app: - build: - context: . - dockerfile: Dockerfile + app: image: nd-waas-engine:latest - container_name: kunden_instanz_app + container_name: waas_${CUSTOMER_SLUG:-kunden_app} restart: always environment: - NODE_ENV=production - PORT=3000 - DATA_DIR=/app/data volumes: - # Kunden-Konfigurationsdaten & Uploads bleiben bei Updates persistent + # Hier werden site.config.json, sqlite.db, uploads etc. automatisch vom Container angelegt - ./data:/app/data ports: - # Interne Port-Anbindung für den händischen Nginx Reverse Proxy - - "127.0.0.1:8080:3000" + # Anbindung an deinen händischen Nginx Reverse Proxy auf dem Host + - "127.0.0.1:${PORT:-8080}:3000" + healthcheck: + test: ["CMD", "wget", "--spider", "http://localhost:3000/api/health"] + interval: 10s + timeout: 3s + retries: 3 logging: driver: "json-file" options: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..ffa1fcd --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,73 @@ +#!/bin/sh +set -e + +DATA_DIR=${DATA_DIR:-/app/data} + +echo "🚀 [WaaS Container Entrypoint] Prüfe Daten-Volume unter ${DATA_DIR}..." + +# 1. Sicherstellen, dass das Volume-Verzeichnis existiert +mkdir -p "$DATA_DIR" + +# 2. site.config.json Seeding +if [ ! -f "$DATA_DIR/site.config.json" ]; then + echo "📄 Keine site.config.json gefunden. Erstelle Standard-Konfiguration..." + cat < "$DATA_DIR/site.config.json" +{ + "site_info": { + "title": "N&D IT Solutions Kunden-Website", + "company_name": "Mein Unternehmen", + "homepage_id": "page_home_01" + }, + "navigation": [ + { "label": "Startseite", "page_id": "page_home_01" } + ], + "pages": [ + { + "id": "page_home_01", + "slug": "/", + "title": "Startseite", + "is_published": true, + "sections": [ + { + "id": "sec_hero_init", + "type": "HeroSection", + "settings": { + "title": "Herzlich Willkommen", + "subtitle": "Ihre neue Website ist erfolgreich gestartet." + } + } + ] + } + ] +} +EOF +fi + +# 3. theme.config.json Seeding +if [ ! -f "$DATA_DIR/theme.config.json" ]; then + echo "🎨 Keine theme.config.json gefunden. Erstelle Standard-Theme..." + cat < "$DATA_DIR/theme.config.json" +{ + "presetKey": "corporate-dark", + "mode": "dark" +} +EOF +fi + +# 4. smtp.config.json Seeding +if [ ! -f "$DATA_DIR/smtp.config.json" ]; then + echo "✉️ Keine smtp.config.json gefunden. Erstelle Standard-SMTP Config..." + cat < "$DATA_DIR/smtp.config.json" +{ + "host": "localhost", + "port": 1025, + "from": "noreply@kunden-domain.de", + "recipient": "info@kunden-domain.de" +} +EOF +fi + +echo "✅ All-in-One Initialisierung abgeschlossen. Starte Astro SSR Node Server..." + +# Führe den eigentlichen Befehl aus (CMD aus Dockerfile) +exec "$@"