From 3afd5c8445afd13c3f5629de087f8f25c5c74aa0 Mon Sep 17 00:00:00 2001 From: cynfo3000 Date: Sun, 8 Mar 2026 19:42:56 +0100 Subject: [PATCH] feat: fertige Docker Images via Gitea Actions + Runtime-Konfiguration CI/CD: - .gitea/workflows/docker-publish.yml: baut + pusht bei Push auf release und Tags - Images: git.cynfo.net/christian/rmm2/backend:latest + frontend:latest - Gitea Secrets: REGISTRY_USER + REGISTRY_PASSWORD gesetzt Runtime-Konfiguration (kein Rebuild bei IP-Aenderung): - frontend/docker-entrypoint.sh: generiert runtime-config.js aus ENV-Vars beim Start - frontend/src/config.js: window.__RMM_CONFIG__ (Docker) vor Vite-ENV (in .gitignore, nicht im release-Commit) - frontend/public/runtime-config.js: leerer Fallback fuer lokale Entwicklung - frontend/index.html: laedt /runtime-config.js vor dem App-Bundle docker-compose: - Nutzt fertige Images aus der Gitea Registry - docker-compose.build.yml: Override fuer lokalen Build - Alle Frontend-Werte via ENV zur Laufzeit --- .gitea/workflows/docker-publish.yml | 65 +++++++++++++++++++++++++++++ README.md | 5 ++- docker-compose.build.yml | 11 +++++ docker-compose.yml | 13 +++--- frontend/Dockerfile | 19 ++++----- frontend/docker-entrypoint.sh | 13 ++++++ frontend/index.html | 2 + frontend/public/runtime-config.js | 3 ++ 8 files changed, 111 insertions(+), 20 deletions(-) create mode 100644 .gitea/workflows/docker-publish.yml create mode 100644 docker-compose.build.yml create mode 100644 frontend/docker-entrypoint.sh create mode 100644 frontend/public/runtime-config.js diff --git a/.gitea/workflows/docker-publish.yml b/.gitea/workflows/docker-publish.yml new file mode 100644 index 0000000..6a71d4d --- /dev/null +++ b/.gitea/workflows/docker-publish.yml @@ -0,0 +1,65 @@ +name: Docker Images bauen und pushen + +on: + push: + branches: + - release + tags: + - "v*" + +env: + REGISTRY: git.cynfo.net + IMAGE_BACKEND: git.cynfo.net/christian/rmm2/backend + IMAGE_FRONTEND: git.cynfo.net/christian/rmm2/frontend + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login in Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Docker Buildx einrichten + uses: docker/setup-buildx-action@v3 + + - name: Image-Tag bestimmen + id: meta + run: | + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + TAG="${{ github.ref_name }}" + else + TAG="latest" + fi + echo "tag=${TAG}" >> $GITHUB_OUTPUT + + - name: Backend bauen und pushen + uses: docker/build-push-action@v5 + with: + context: ./backend + push: true + tags: | + ${{ env.IMAGE_BACKEND }}:${{ steps.meta.outputs.tag }} + ${{ env.IMAGE_BACKEND }}:latest + cache-from: type=registry,ref=${{ env.IMAGE_BACKEND }}:buildcache + cache-to: type=registry,ref=${{ env.IMAGE_BACKEND }}:buildcache,mode=max + + - name: Frontend bauen und pushen + uses: docker/build-push-action@v5 + with: + context: ./frontend + push: true + tags: | + ${{ env.IMAGE_FRONTEND }}:${{ steps.meta.outputs.tag }} + ${{ env.IMAGE_FRONTEND }}:latest + # BACKEND_HOST ist zur Laufzeit nicht bekannt — wird im Compose via Env gesetzt + # Wer eigene Images braucht: docker compose build + cache-from: type=registry,ref=${{ env.IMAGE_FRONTEND }}:buildcache + cache-to: type=registry,ref=${{ env.IMAGE_FRONTEND }}:buildcache,mode=max diff --git a/README.md b/README.md index 9dea108..43b11f1 100644 --- a/README.md +++ b/README.md @@ -189,8 +189,9 @@ docker compose logs backend Fertig. Frontend unter `http://`, Backend-API unter `https://:8443`. -> **Hinweis:** Das Frontend-Image wird mit der `BACKEND_HOST`-URL gebaut. -> Nach einer IP-Änderung muss das Frontend neu gebaut werden: `docker compose build frontend && docker compose up -d frontend` +> **Hinweis:** Die Frontend-Konfiguration (Backend-Host, API-Key) wird zur **Laufzeit** via ENV +> in den Container injiziert — kein Rebuild bei IP-Änderungen nötig. +> Selbst bauen statt fertige Images: `docker compose -f docker-compose.yml -f docker-compose.build.yml up -d` --- diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..c79c46c --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,11 @@ +# Lokaler Build statt fertige Images verwenden: +# docker compose -f docker-compose.yml -f docker-compose.build.yml up -d + +services: + backend: + build: ./backend + image: ~ + + frontend: + build: ./frontend + image: ~ diff --git a/docker-compose.yml b/docker-compose.yml index b92d874..d6e28d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: retries: 10 backend: - build: ./backend + image: git.cynfo.net/christian/rmm2/backend:latest restart: unless-stopped ports: - "8443:8443" @@ -32,15 +32,14 @@ services: condition: service_healthy frontend: - build: - context: ./frontend - args: - VITE_BACKEND_HOST: ${BACKEND_HOST} - VITE_BACKEND_PORT: ${BACKEND_PORT:-8443} - VITE_API_KEY: ${API_KEY} + image: git.cynfo.net/christian/rmm2/frontend:latest restart: unless-stopped ports: - "80:80" + environment: + BACKEND_HOST: ${BACKEND_HOST} + BACKEND_PORT: ${BACKEND_PORT:-8443} + API_KEY: ${API_KEY} depends_on: - backend diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 4a40fdd..9dce812 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -5,16 +5,6 @@ COPY package*.json ./ RUN npm ci COPY . . - -# Backend-URL wird zur Build-Zeit via ARG gesetzt -ARG VITE_BACKEND_HOST=localhost -ARG VITE_BACKEND_PORT=8443 -ARG VITE_API_KEY="" - -ENV VITE_BACKEND_HOST=$VITE_BACKEND_HOST \ - VITE_BACKEND_PORT=$VITE_BACKEND_PORT \ - VITE_API_KEY=$VITE_API_KEY - RUN npm run build # --- @@ -23,7 +13,14 @@ FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY docker-entrypoint.sh /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] +# Konfiguration via ENV zur Laufzeit (kein Rebuild bei IP-Aenderung noetig) +ENV BACKEND_HOST=localhost \ + BACKEND_PORT=8443 \ + API_KEY="" + +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/frontend/docker-entrypoint.sh b/frontend/docker-entrypoint.sh new file mode 100644 index 0000000..79b4b8b --- /dev/null +++ b/frontend/docker-entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Generiert /usr/share/nginx/html/runtime-config.js aus ENV-Variablen +# Wird beim Container-Start ausgefuehrt + +cat > /usr/share/nginx/html/runtime-config.js << EOF +window.__RMM_CONFIG__ = { + backendHost: "${BACKEND_HOST:-localhost}", + backendPort: "${BACKEND_PORT:-8443}", + apiKey: "${API_KEY:-}" +}; +EOF + +exec nginx -g "daemon off;" diff --git a/frontend/index.html b/frontend/index.html index c20fbd3..bab1e4d 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,6 +1,8 @@ + + diff --git a/frontend/public/runtime-config.js b/frontend/public/runtime-config.js new file mode 100644 index 0000000..9d0a9a0 --- /dev/null +++ b/frontend/public/runtime-config.js @@ -0,0 +1,3 @@ +// Lokaler Entwicklungs-Fallback — in Docker wird diese Datei durch +// docker-entrypoint.sh mit echten Werten ueberschrieben +window.__RMM_CONFIG__ = {};