diff --git a/.gitea/DEPLOYMENT.md b/.gitea/DEPLOYMENT.md new file mode 100644 index 0000000..a851c3b --- /dev/null +++ b/.gitea/DEPLOYMENT.md @@ -0,0 +1,22 @@ +# Automatisches Produktions-Deployment + +Der Workflow `workflows/deploy-production.yml` startet bei jedem Push auf +`main` das Script `deploy-production.sh` im Produktions-Checkout +`/var/www/timeclock`. + +Einmalig im Gitea-Repository unter **Settings → Actions → Secrets** anlegen: + +- `TIMECLOCK_DEPLOY_HOST`: Hostname des Produktionsservers, z. B. + `stechuhr3.tsschulz.de` +- `TIMECLOCK_DEPLOY_USER`: Linux-Benutzer mit Zugriff auf den Checkout und PM2 +- `TIMECLOCK_DEPLOY_SSH_PRIVATE_KEY`: privater SSH-Schlüssel dieses Deploy- + Benutzers +- `TIMECLOCK_DEPLOY_SSH_KNOWN_HOSTS`: Ausgabe von + `ssh-keyscan -H stechuhr3.tsschulz.de` + +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. diff --git a/.gitea/workflows/deploy-production.yml b/.gitea/workflows/deploy-production.yml new file mode 100644 index 0000000..22046aa --- /dev/null +++ b/.gitea/workflows/deploy-production.yml @@ -0,0 +1,33 @@ +name: Deploy production + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy auf stechuhr3 + env: + DEPLOY_HOST: ${{ secrets.TIMECLOCK_DEPLOY_HOST }} + DEPLOY_USER: ${{ secrets.TIMECLOCK_DEPLOY_USER }} + DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.TIMECLOCK_DEPLOY_SSH_PRIVATE_KEY }} + DEPLOY_SSH_KNOWN_HOSTS: ${{ secrets.TIMECLOCK_DEPLOY_SSH_KNOWN_HOSTS }} + run: | + set -eu + + test -n "$DEPLOY_HOST" + test -n "$DEPLOY_USER" + test -n "$DEPLOY_SSH_PRIVATE_KEY" + test -n "$DEPLOY_SSH_KNOWN_HOSTS" + + install -d -m 700 "$HOME/.ssh" + printf '%s\n' "$DEPLOY_SSH_PRIVATE_KEY" > "$HOME/.ssh/id_ed25519" + chmod 600 "$HOME/.ssh/id_ed25519" + printf '%s\n' "$DEPLOY_SSH_KNOWN_HOSTS" > "$HOME/.ssh/known_hosts" + chmod 600 "$HOME/.ssh/known_hosts" + + ssh -o BatchMode=yes "$DEPLOY_USER@$DEPLOY_HOST" \ + 'cd /var/www/timeclock && ./deploy-production.sh'