From 218c0f0debb8150cc79e14f605a91f37881e1ea7 Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Fri, 20 Mar 2026 23:19:27 +0100 Subject: [PATCH] fix: broad permissions, git-based deploy, correct workflow order - settings.local.json: wildcard permissions for git, ssh, curl, npm, docker to eliminate constant confirmation prompts - ssh-deploy: git clone/pull as primary deploy method, rsync as fallback - workflow provision: git-push before ssh-deploy (push to Gitea first, then git clone on LXC) - all workflows: deploy steps now explicitly git-based Co-Authored-By: Claude Opus 4.6 (1M context) --- .claude/settings.local.json | 21 ++++++++ .claude/skills/ssh-deploy.md | 102 +++++++++++++++++++++++------------ .claude/skills/workflow.md | 18 +++---- 3 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 .claude/settings.local.json diff --git a/.claude/settings.local.json b/.claude/settings.local.json new file mode 100644 index 0000000..384e7c6 --- /dev/null +++ b/.claude/settings.local.json @@ -0,0 +1,21 @@ +{ + "permissions": { + "allow": [ + "Bash(git *)", + "Bash(ssh *)", + "Bash(scp *)", + "Bash(rsync *)", + "Bash(curl *)", + "Bash(npm *)", + "Bash(npx *)", + "Bash(node *)", + "Bash(docker *)", + "Bash(docker compose *)", + "Bash(mkdir *)", + "Bash(ls *)", + "Bash(cat *)", + "Bash(tar *)", + "Bash(chmod *)" + ] + } +} diff --git a/.claude/skills/ssh-deploy.md b/.claude/skills/ssh-deploy.md index 1c579e4..ef9dec4 100644 --- a/.claude/skills/ssh-deploy.md +++ b/.claude/skills/ssh-deploy.md @@ -8,25 +8,70 @@ Du bist ein SSH-Deploy-Agent für Remote-Testing und Deployment auf Linux-Server ## KONFIGURATION ``` -SSH_HOST=$SSH_HOST # IP oder Hostname - wird automatisch von /proxmox-lxc gesetzt wenn LXC erstellt wurde +SSH_HOST=$SSH_HOST # wird automatisch von /proxmox-lxc gesetzt SSH_PORT=$SSH_PORT # default: 22 SSH_USER=$SSH_USER # default: deploy SSH_KEY_PATH=$SSH_KEY_PATH # default: ~/.ssh/id_rsa DEPLOY_PATH=$DEPLOY_PATH # default: /var/www/app +GITEA_URL=$GITEA_URL # default: https://git.cynfo.net +GITEA_USER=$GITEA_USER +GITEA_TOKEN=$GITEA_TOKEN ``` -**Hinweis:** Wenn vorher `/proxmox-lxc` ausgeführt wurde, ist `SSH_HOST` bereits mit der LXC-IP belegt. Kein manueller Eintrag in `project.env` nötig. +**SSH_HOST wird automatisch aus LXC-IP belegt wenn `/proxmox-lxc` vorher lief.** -## DEPLOYMENT-PROZESS -1. SSH-Verbindung testen: `ssh -i $SSH_KEY_PATH -p $SSH_PORT $SSH_USER@$SSH_HOST "echo ok"` -2. Backup erstellen: `tar -czf backup_$(date +%Y%m%d_%H%M%S).tar.gz $DEPLOY_PATH` -3. Code synchronisieren (rsync oder git pull) -4. Dependencies installieren: `npm ci --production` -5. Build ausführen: `npm run build` -6. Service neu starten -7. Health-Check durchführen +## DEPLOYMENT-METHODEN (Priorität) -### Rsync-Deploy +### 1. Git-Clone Deploy (BEVORZUGT) +Der saubere Weg: Code liegt auf Gitea, wird per git clone/pull auf den Server geholt. + +#### Erstmaliges Deployment +```bash +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST << EOF + # Git mit Token konfigurieren (einmalig) + git config --global credential.helper store + echo "https://$GITEA_USER:$GITEA_TOKEN@$(echo $GITEA_URL | sed 's|https://||')" > ~/.git-credentials + chmod 600 ~/.git-credentials + + # Repo klonen + cd /var/www + git clone $GITEA_URL/$GITEA_USER/$REPO_NAME.git app + cd app + + # Dependencies & Build + npm ci --production + npm run build + + # Service starten + pm2 start dist/index.js --name app + pm2 save +EOF +``` + +#### Update-Deployment (git pull) +```bash +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST << 'EOF' + cd $DEPLOY_PATH + git pull origin main + npm ci --production + npm run build + pm2 restart app +EOF +``` + +#### Docker-Variante (git pull + docker compose) +```bash +ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST << 'EOF' + cd $DEPLOY_PATH + git pull origin main + docker compose down + docker compose up -d --build + docker compose ps +EOF +``` + +### 2. Rsync-Deploy (Fallback) +Nur wenn kein Git auf dem Server verfügbar oder gewünscht: ```bash rsync -avz --delete \ --exclude 'node_modules' \ @@ -37,20 +82,17 @@ rsync -avz --delete \ ./ $SSH_USER@$SSH_HOST:$DEPLOY_PATH/ ``` -### Docker-Deploy -```bash -ssh -i $SSH_KEY_PATH $SSH_USER@$SSH_HOST << 'EOF' - cd $DEPLOY_PATH - docker compose pull - docker compose up -d --build - docker compose ps -EOF -``` +## DEPLOYMENT-ABLAUF +1. SSH-Verbindung testen +2. Snapshot erstellen (wenn Proxmox LXC): `pct snapshot $VMID snap-before-deploy` +3. `git pull origin main` auf dem Server +4. `npm ci --production && npm run build` +5. Service neu starten (`pm2 restart` oder `docker compose up -d --build`) +6. Health-Check: `curl -sf http://localhost:3000/health` ## DEBUGGING-BEFEHLE ```bash # Logs -ssh ... "tail -100 $DEPLOY_PATH/logs/error.log" ssh ... "pm2 logs --lines 100" ssh ... "journalctl -u myapp --since '1 hour ago'" ssh ... "docker logs --tail 100 container_name" @@ -69,20 +111,12 @@ ssh ... "curl -sf http://localhost:3000/health" ``` ## ROLLBACK -Bei fehlgeschlagenem Deployment: -1. Letztes Backup finden: `ls -la backup_*.tar.gz` -2. Wiederherstellen: `tar -xzf backup_.tar.gz -C /` -3. Service neu starten -4. Health-Check - -## PROXMOX-LXC INTEGRATION -Wenn die Zielmaschine ein Proxmox LXC-Container ist: -- Nutze `/proxmox-lxc` um einen neuen Container zu erstellen -- Danach diesen Skill (`/ssh-deploy`) mit der LXC-IP als SSH_HOST nutzen -- Snapshots statt tar-Backups: `pct snapshot $VMID snap-before-deploy` +- **Proxmox LXC**: `pct rollback $VMID snap-before-deploy` (schnellste Methode) +- **Git**: `git checkout ` auf dem Server +- **Docker**: `docker compose down && git checkout && docker compose up -d --build` ## SICHERHEIT - SSH-Key niemals im Repository -- Key-Permissions: `chmod 600 ~/.ssh/id_rsa` +- Git-Credentials auf dem Server: `chmod 600 ~/.git-credentials` - Nur auf Test/Staging deployen - NICHT Produktion ohne explizite Bestätigung -- Vor Deployment immer Backup erstellen +- Vor Deployment immer Snapshot/Backup erstellen diff --git a/.claude/skills/workflow.md b/.claude/skills/workflow.md index 1d93004..8f000c7 100644 --- a/.claude/skills/workflow.md +++ b/.claude/skills/workflow.md @@ -25,8 +25,8 @@ Du bist der Workflow-Orchestrator. Du koordinierst alle verfügbaren Skills für 1. [code-gen] → Feature implementieren 2. [test-runner] → Tests schreiben und ausführen 3. [security] → Code auf Sicherheit prüfen -4. [git-push] → Feature-Branch, Commit, PR -5. [ssh-deploy] → Auf Staging deployen (optional) +4. [git-push] → Feature-Branch, Commit, Push auf Gitea +5. [ssh-deploy] → git pull + rebuild auf Staging (optional) ``` ### Bug fixen (`/workflow bugfix "Beschreibung"`) @@ -52,8 +52,8 @@ Du bist der Workflow-Orchestrator. Du koordinierst alle verfügbaren Skills für 1. [test-runner] → Alle Tests (Unit, Integration) 2. [security] → Final Security-Check 3. [dep-check] → Dependency-Check -4. [git-push] → Release-Branch, Tag, Changelog -5. [ssh-deploy] → Deploy auf Staging für finalen Test +4. [git-push] → Release-Branch, Tag, Changelog, Push auf Gitea +5. [ssh-deploy] → git pull + rebuild auf Staging für finalen Test ``` ### Neues Projekt (`/workflow init "Projektname"`) @@ -66,11 +66,11 @@ Du bist der Workflow-Orchestrator. Du koordinierst alle verfügbaren Skills für ### Neue Umgebung auf Proxmox (`/workflow provision "Projektname"`) ``` -1. [proxmox-lxc] → LXC-Container erstellen -2. [proxmox-lxc] → LXC-IP automatisch ermitteln → SSH_HOST setzen -3. [proxmox-lxc] → Basis-Setup (Node.js/Docker, Firewall, Nginx) -4. [docker-build] → Docker-Compose für die App -5. [ssh-deploy] → App in den LXC deployen (nutzt LXC-IP als SSH_HOST) +1. [proxmox-lxc] → LXC-Container erstellen + IP ermitteln → SSH_HOST +2. [proxmox-lxc] → Basis-Setup (Node.js/Docker, Git, Firewall, Nginx) +3. [git-push] → Code auf Gitea pushen (Repo muss existieren) +4. [ssh-deploy] → git clone $GITEA_URL/$USER/$REPO auf LXC +5. [ssh-deploy] → npm ci, build, Service starten 6. [log-analyzer] → Health-Check & Logs prüfen ```