Aktualisiere Produktions-Deployment-Dokumentation und entferne das veraltete Deploy-Skript
All checks were successful
Deploy production / deploy (push) Successful in 30s

This commit is contained in:
Torsten Schulz (local)
2026-08-26 15:52:42 +02:00
parent 51acff261e
commit 4e6eeb470d
3 changed files with 9 additions and 83 deletions

View File

@@ -1,8 +1,10 @@
# Automatisches Produktions-Deployment # Automatisches Produktions-Deployment
Der Workflow `workflows/deploy-production.yml` aktualisiert bei jedem Push auf Der Workflow `workflows/deploy-production.yml` aktualisiert bei jedem Push auf
`main` zunächst den Produktions-Checkout `/var/www/timeclock` per `main` den Git-Checkout `~/stechuhr3` auf dem Produktionsserver und startet
Fast-forward und startet dann `deploy-production.sh`. 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: 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 `~/.ssh/authorized_keys` des Deploy-Benutzers hinterlegt sein. Der Gitea
Actions-Runner benötigt außerdem Netzwerkzugang per SSH zum Server. Actions-Runner benötigt außerdem Netzwerkzugang per SSH zum Server.
Vor dem ersten Push muss `/var/www/timeclock` bereits der Checkout dieses Vor dem ersten Push muss `~/stechuhr3` bereits der Checkout dieses Repositories
Repositories sein und die ausführbare Datei `deploy-production.sh` enthalten. sein. Das Deploy-Skript benötigt die Rechte, nach `/var/www/timeclock` zu
kopieren und den PM2-Prozess neu zu laden.

View File

@@ -34,5 +34,5 @@ jobs:
echo "Deploy-Key-Fingerprint: $(ssh-keygen -y -f "$HOME/.ssh/id_ed25519" | ssh-keygen -lf - | awk '{print $2}')" 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")" echo "known_hosts-Zeilen: $(wc -l < "$HOME/.ssh/known_hosts")"
ssh -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \ ssh -o BatchMode=yes -o ConnectTimeout=20 "$DEPLOY_USER@$DEPLOY_HOST" \
'cd /var/www/timeclock && git pull --ff-only origin main && ./deploy-production.sh' 'cd "$HOME/stechuhr3" && GIT_TERMINAL_PROMPT=0 git pull --ff-only origin main && ./deploy.sh update no-backup'

View File

@@ -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."