LXC-Start: docker compose pull + up ohne -d per systemd verankern
This commit is contained in:
@@ -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 <path>` Option hinzugefügt (default: `RAGKI-BotPGVector.json`)
|
||||
- [x] `--ollama-model <model>` Option hinzugefügt (default: `ministral-3:3b`)
|
||||
- [x] `--embedding-model <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.
|
||||
|
||||
+6
-4
@@ -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.
|
||||
|
||||
@@ -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 <<EOF
|
||||
[Unit]
|
||||
Description=Customer Stack Docker Compose Startup (pull + up)
|
||||
After=network-online.target docker.service
|
||||
Wants=network-online.target
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=${stack_dir}
|
||||
ExecStart=/usr/local/bin/customer-stack-start.sh
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
)"
|
||||
|
||||
pct_exec "${ctid}" "systemctl daemon-reload"
|
||||
pct_exec "${ctid}" "systemctl enable ${service_name}"
|
||||
|
||||
info "Compose-Startup-Service aktiviert: ${service_name}"
|
||||
}
|
||||
|
||||
# ----- n8n API helpers -----
|
||||
# These functions interact with n8n REST API inside a container
|
||||
|
||||
|
||||
Reference in New Issue
Block a user