diff --git a/TODO.md b/TODO.md index a962c84..3e8b4d7 100644 --- a/TODO.md +++ b/TODO.md @@ -1,143 +1,7 @@ -# n8n Customer Provisioning System +# TODO – LXC Docker-Startverhalten auf pull + up (ohne -d) umstellen -## Status: ✅ Phase 1-4 Complete - ---- - -## Implementierte Features - -### Phase 1: n8n API Funktionen (libsupabase.sh) - -- [x] `n8n_api_login()` - Login mit `emailOrLdapLoginId` (nicht `email`) -- [x] `n8n_api_create_postgres_credential()` - PostgreSQL Credential erstellen -- [x] `n8n_api_create_ollama_credential()` - Ollama Credential erstellen -- [x] `n8n_api_import_workflow()` - Workflow importieren -- [x] `n8n_api_activate_workflow()` - Workflow aktivieren mit `versionId` -- [x] `n8n_generate_rag_workflow_json()` - Built-in Workflow Template -- [x] `n8n_setup_rag_workflow()` - Hauptfunktion für komplettes Setup - -### Phase 2: install.sh - Workflow Import - -- [x] Login durchführen -- [x] PostgreSQL Credential erstellen und ID speichern -- [x] Ollama Credential erstellen und ID speichern -- [x] Workflow JSON mit korrekten Credential-IDs generieren -- [x] Workflow importieren -- [x] Workflow aktivieren mit `POST /rest/workflows/{id}/activate` + `versionId` - -### Phase 3: Externe Workflow-Datei Support - -- [x] `--workflow-file ` Option hinzugefügt (default: `RAGKI-BotPGVector.json`) -- [x] `--ollama-model ` Option hinzugefügt (default: `ministral-3:3b`) -- [x] `--embedding-model ` Option hinzugefügt (default: `nomic-embed-text:latest`) -- [x] Python-Script für dynamische Credential-ID-Ersetzung -- [x] Entfernung von `id`, `versionId`, `meta`, `tags`, `active`, `pinData` beim Import -- [x] `RAGKI-BotPGVector.json` als Standard-Workflow-Template - -### Phase 4: Tests & Git - -- [x] Container sb-1769174647 - Workflow aktiviert ✅ -- [x] Container sb-1769180683 - Externe Workflow-Datei ✅ -- [x] Git Commits gepusht - ---- - -## Verwendung - -### Standard-Installation (mit Default-Workflow) - -```bash -bash install.sh --debug -``` - -### Mit benutzerdefiniertem Workflow - -```bash -bash install.sh --debug \ - --workflow-file /path/to/custom-workflow.json \ - --ollama-model "llama3.2:3b" \ - --embedding-model "nomic-embed-text:v1.5" -``` - -### Verfügbare Optionen - -| Option | Default | Beschreibung | -|--------|---------|--------------| -| `--workflow-file` | `RAGKI-BotPGVector.json` | Pfad zur n8n Workflow JSON-Datei | -| `--ollama-model` | `ministral-3:3b` | Ollama Chat-Modell | -| `--embedding-model` | `nomic-embed-text:latest` | Ollama Embedding-Modell | - ---- - -## Technische Details - -### n8n REST API Endpoints - -| Endpoint | Methode | Beschreibung | -|----------|---------|--------------| -| `/rest/login` | POST | Login (Feld: `emailOrLdapLoginId`, nicht `email`) | -| `/rest/credentials` | POST | Credential erstellen | -| `/rest/workflows` | POST | Workflow importieren | -| `/rest/workflows/{id}/activate` | POST | Workflow aktivieren (benötigt `versionId`) | - -### Credential Types - -- `postgres` - PostgreSQL Datenbank -- `ollamaApi` - Ollama API - -### Workflow-Verarbeitung - -Das Python-Script `/tmp/process_workflow.py` im Container: -1. Liest die Workflow-Template-Datei -2. Entfernt Felder: `id`, `versionId`, `meta`, `tags`, `active`, `pinData` -3. Ersetzt alle `postgres` Credential-IDs mit der neuen ID -4. Ersetzt alle `ollamaApi` Credential-IDs mit der neuen ID -5. Schreibt die verarbeitete Workflow-Datei - ---- - -## Git Commits - -1. `ff1526c` - feat: Auto-import n8n RAG workflow with credentials -2. `f663708` - fix: Workflow activation with versionId -3. `26f5a73` - feat: External workflow file support with dynamic credential replacement - ---- - -## Phase 5: Workflow Auto-Reload bei LXC-Neustart ✅ - -- [x] Systemd-Service für automatisches Workflow-Reload -- [x] Reload-Script mit vollständigem Logging -- [x] Workflow-Template persistent speichern -- [x] Integration in install.sh -- [x] Hilfsfunktionen in libsupabase.sh -- [x] Dokumentation (WORKFLOW_RELOAD_README.md) - -### Details - -Der Workflow wird jetzt bei jedem LXC-Neustart automatisch neu geladen: - -1. **Systemd-Service**: `/etc/systemd/system/n8n-workflow-reload.service` -2. **Reload-Script**: `/opt/customer-stack/reload-workflow.sh` -3. **Workflow-Template**: `/opt/customer-stack/workflow-template.json` -4. **Logs**: `/opt/customer-stack/logs/workflow-reload.log` - -**Funktionsweise**: -- Beim LXC-Start wird der Systemd-Service ausgeführt -- Service wartet auf Docker und n8n-Container -- Reload-Script löscht alten Workflow -- Importiert Workflow aus Template -- Aktiviert Workflow -- Loggt alle Aktionen - -**Siehe**: `WORKFLOW_RELOAD_README.md` für vollständige Dokumentation - ---- - -## Nächste Schritte (Optional) - -- [ ] Workflow-Validierung vor Import -- [ ] Mehrere Workflows unterstützen -- [ ] Workflow-Update bei bestehenden Containern -- [ ] Backup/Export von Workflows -- [ ] Tests für Auto-Reload-Feature durchführen +- [x] `libsupabase.sh`: Funktion ergänzt, die im LXC eine systemd-Unit für `docker compose pull` + `docker compose up` (ohne `-d`) installiert und aktiviert. +- [x] `install.sh`: direkte Starts mit `docker compose up -d` entfernt/umgestellt und neue Funktion aufgerufen. +- [x] `install.sh`: Hinweise/Logs für neues Verhalten ergänzt. +- [x] Syntaxprüfung: `bash -n install.sh libsupabase.sh`. +- [ ] Änderungen committen und nach `main` pushen. diff --git a/install.sh b/install.sh index e086f05..be02e14 100755 --- a/install.sh +++ b/install.sh @@ -560,10 +560,12 @@ pct_exec "$CTID" "systemctl is-active docker" pct_exec "$CTID" "docker info | grep -A2 -i 'Registry Mirrors'" fi -# Pull + up -pct_exec "${CTID}" "cd /opt/customer-stack && docker compose pull" -pct_exec "${CTID}" "cd /opt/customer-stack && docker compose up -d" -pct_exec "${CTID}" "cd /opt/customer-stack && docker compose ps" +# Startup-Verhalten im LXC fest verdrahten: +# bei jedem Neustart: pull + up (ohne -d) +install_lxc_compose_startup_mode "${CTID}" "/opt/customer-stack" + +# Service einmalig jetzt starten (führt pull + up ohne -d aus) +pct_exec "${CTID}" "systemctl start customer-stack-compose.service" # --- Owner account creation (robust way) --- # n8n shows the setup screen if no user exists. diff --git a/libsupabase.sh b/libsupabase.sh index 341caf8..e37aa9e 100755 --- a/libsupabase.sh +++ b/libsupabase.sh @@ -215,6 +215,56 @@ emit_json() { cat } +# Installiert ein systemd-Service im LXC, der bei jedem LXC-Start +# zuerst Images zieht und dann den Stack im Foreground startet. +# Gewünschtes Verhalten: +# docker compose pull +# docker compose up (ohne -d) +install_lxc_compose_startup_mode() { + local ctid="$1" + local stack_dir="${2:-/opt/customer-stack}" + local service_name="customer-stack-compose.service" + + info "Installiere Compose-Startup-Service im LXC ${ctid} (${service_name})" + + pct_push_text "${ctid}" "/usr/local/bin/customer-stack-start.sh" "$(cat <<'SCRIPT' +#!/usr/bin/env bash +set -Eeuo pipefail + +STACK_DIR="/opt/customer-stack" + +cd "${STACK_DIR}" +docker compose pull +exec docker compose up +SCRIPT +)" + pct_exec "${ctid}" "chmod +x /usr/local/bin/customer-stack-start.sh" + + pct_push_text "${ctid}" "/etc/systemd/system/${service_name}" "$(cat <