From 4e6eeb470d214bbc97917c43648ea0a72f9e25ba Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 26 Aug 2026 15:52:42 +0200 Subject: [PATCH] Aktualisiere Produktions-Deployment-Dokumentation und entferne das veraltete Deploy-Skript --- .gitea/DEPLOYMENT.md | 11 ++-- .gitea/workflows/deploy-production.yml | 4 +- deploy-production.sh | 77 -------------------------- 3 files changed, 9 insertions(+), 83 deletions(-) delete mode 100755 deploy-production.sh diff --git a/.gitea/DEPLOYMENT.md b/.gitea/DEPLOYMENT.md index da8f7fa..a6ea326 100644 --- a/.gitea/DEPLOYMENT.md +++ b/.gitea/DEPLOYMENT.md @@ -1,8 +1,10 @@ # Automatisches Produktions-Deployment Der Workflow `workflows/deploy-production.yml` aktualisiert bei jedem Push auf -`main` zunächst den Produktions-Checkout `/var/www/timeclock` per -Fast-forward und startet dann `deploy-production.sh`. +`main` den Git-Checkout `~/stechuhr3` auf dem Produktionsserver und startet +dort `./deploy.sh update no-backup`. Dieses vorhandene Deploy-Skript kopiert +den aktualisierten Code nach `/var/www/timeclock`, baut das Frontend und lädt +den PM2-Prozess neu. Einmalig im Gitea-Repository konfigurieren: @@ -19,5 +21,6 @@ Der öffentliche Teil des Deploy-Schlüssels muss auf dem Produktionsserver in `~/.ssh/authorized_keys` des Deploy-Benutzers hinterlegt sein. Der Gitea Actions-Runner benötigt außerdem Netzwerkzugang per SSH zum Server. -Vor dem ersten Push muss `/var/www/timeclock` bereits der Checkout dieses -Repositories sein und die ausführbare Datei `deploy-production.sh` enthalten. +Vor dem ersten Push muss `~/stechuhr3` bereits der Checkout dieses Repositories +sein. Das Deploy-Skript benötigt die Rechte, nach `/var/www/timeclock` zu +kopieren und den PM2-Prozess neu zu laden. diff --git a/.gitea/workflows/deploy-production.yml b/.gitea/workflows/deploy-production.yml index ef0205d..3ba2a67 100644 --- a/.gitea/workflows/deploy-production.yml +++ b/.gitea/workflows/deploy-production.yml @@ -34,5 +34,5 @@ jobs: echo "Deploy-Key-Fingerprint: $(ssh-keygen -y -f "$HOME/.ssh/id_ed25519" | ssh-keygen -lf - | awk '{print $2}')" echo "known_hosts-Zeilen: $(wc -l < "$HOME/.ssh/known_hosts")" - ssh -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \ - 'cd /var/www/timeclock && git pull --ff-only origin main && ./deploy-production.sh' + ssh -o BatchMode=yes -o ConnectTimeout=20 "$DEPLOY_USER@$DEPLOY_HOST" \ + 'cd "$HOME/stechuhr3" && GIT_TERMINAL_PROMPT=0 git pull --ff-only origin main && ./deploy.sh update no-backup' diff --git a/deploy-production.sh b/deploy-production.sh deleted file mode 100755 index aa3472d..0000000 --- a/deploy-production.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash -# Automatisches Produktions-Deployment für TimeClock. -# Dieses Script wird nach einem Push auf main im Checkout auf dem Server ausgeführt. - -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" - -REMOTE_NAME="${DEPLOY_REMOTE:-origin}" -BRANCH_NAME="${DEPLOY_BRANCH:-main}" -PM2_APP="${PM2_APP:-timeclock-backend}" -CACHE_DIR=".deploy-cache" - -fail() { - echo "ERROR: $*" >&2 - exit 1 -} - -install_dependencies_if_needed() { - local directory="$1" - local cache_key="$2" - local lockfile="$directory/package-lock.json" - local hash_file="$CACHE_DIR/${cache_key}-package-lock.sha256" - local current_hash="" - local previous_hash="" - - if [ ! -f "$lockfile" ]; then - echo "[$directory] package-lock.json fehlt, führe npm install aus" - (cd "$directory" && npm install --no-audit --no-fund) - return - fi - - current_hash="$(sha256sum "$lockfile" | awk '{print $1}')" - previous_hash="$(cat "$hash_file" 2>/dev/null || true)" - - if [ ! -d "$directory/node_modules" ] || [ "$current_hash" != "$previous_hash" ]; then - echo "[$directory] installiere Abhängigkeiten" - (cd "$directory" && npm ci --no-audit --no-fund) - else - echo "[$directory] Abhängigkeiten unverändert" - fi - - printf '%s\n' "$current_hash" > "$hash_file" -} - -echo "=== TimeClock Produktions-Deployment ===" -echo "Arbeitsverzeichnis: $SCRIPT_DIR" - -git rev-parse --is-inside-work-tree >/dev/null 2>&1 \ - || fail "Das Script muss im TimeClock-Git-Checkout ausgeführt werden." - -if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - fail "Der Deployment-Checkout enthält lokale Änderungen. Deployment abgebrochen." -fi - -mkdir -p "$CACHE_DIR" - -echo "Aktualisiere $REMOTE_NAME/$BRANCH_NAME …" -git fetch "$REMOTE_NAME" "$BRANCH_NAME" -git merge --ff-only "$REMOTE_NAME/$BRANCH_NAME" - -install_dependencies_if_needed "backend" "backend" -install_dependencies_if_needed "frontend" "frontend" - -echo "Baue Frontend …" -(cd frontend && npm run build) - -echo "Lade PM2-Prozess neu …" -if pm2 describe "$PM2_APP" >/dev/null 2>&1; then - pm2 reload ecosystem.config.js --only "$PM2_APP" --env production --update-env -else - pm2 start ecosystem.config.js --only "$PM2_APP" --env production -fi -pm2 save - -echo "Deployment erfolgreich abgeschlossen."