N8N first run script #44
@@ -140,12 +140,36 @@ services:
|
||||
N8N_PROTOCOL: http
|
||||
# Webhook URL for external calls
|
||||
WEBHOOK_URL: http://localhost:5678/
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO", "/dev/null", "http://localhost:5678/healthz"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
volumes:
|
||||
- n8n_data:/home/node/.n8n
|
||||
- ./n8n/workflows:/home/node/workflows
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
# --- N8N Init: import workflows on first deploy ---
|
||||
n8n-init:
|
||||
image: n8nio/n8n:latest
|
||||
entrypoint: ["/bin/sh", "/home/node/init-import.sh"]
|
||||
environment:
|
||||
DB_TYPE: postgresdb
|
||||
DB_POSTGRESDB_HOST: postgres
|
||||
DB_POSTGRESDB_DATABASE: farmafinder
|
||||
DB_POSTGRESDB_USER: farmafinder
|
||||
DB_POSTGRESDB_PASSWORD: ${PG_PASSWORD:-change-me-in-production}
|
||||
volumes:
|
||||
- n8n_data:/home/node/.n8n
|
||||
- ./n8n/workflows:/home/node/workflows
|
||||
- ./n8n/init-import.sh:/home/node/init-import.sh:ro
|
||||
depends_on:
|
||||
n8n:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
backend_data:
|
||||
postgres_data:
|
||||
|
||||
+16
-7
@@ -11,27 +11,36 @@
|
||||
|
||||
### 1. Cuenta de Administrador
|
||||
|
||||
Al iniciar N8N por primera vez, se crea automáticamente:
|
||||
Al iniciar N8N por primera vez, se crea automáticamente con las variables de entorno:
|
||||
|
||||
| Campo | Valor |
|
||||
| Campo | Valor (por defecto) |
|
||||
|-------|-------|
|
||||
| **Email** | admin@farmafinder.com |
|
||||
| **Password** | change-me |
|
||||
|
||||
> **IMPORTANTE**: Cambia la contraseña después del primer login en http://localhost:5678/settings
|
||||
> **IMPORTANTE**: Cambia la contraseña después del primer login.
|
||||
|
||||
### 2. Variables de Entorno
|
||||
|
||||
```bash
|
||||
# En .env
|
||||
N8N_USER=admin
|
||||
N8N_PASSWORD=change-me
|
||||
# En .env (o en docker-compose.yml)
|
||||
N8N_EMAIL=admin@farmafinder.com
|
||||
N8N_PASSWORD=change-me
|
||||
```
|
||||
|
||||
### 3. Importar Workflows
|
||||
|
||||
Los workflows se importan automáticamente al iniciar el contenedor. Para importar manualmente:
|
||||
**Deploy automático (recomendado):**
|
||||
|
||||
El servicio `n8n-init` en docker-compose.yml ejecuta `n8n import:workflow` automáticamente después del primer arranque. Usa un flag file (`.workflows-imported`) para no re-importar en deploys siguientes.
|
||||
|
||||
**Importar manualmente:**
|
||||
|
||||
```bash
|
||||
docker compose exec n8n n8n import:workflow --separate --input=/home/node/workflows/
|
||||
```
|
||||
|
||||
O desde la UI:
|
||||
|
||||
1. Ir a http://localhost:5678/workflows
|
||||
2. Hacer clic en "Import from File"
|
||||
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# One-shot init: import workflows into n8n on first deploy.
|
||||
# Skips if already imported (flag file in shared volume).
|
||||
set -e
|
||||
|
||||
FLAG="/home/node/.n8n/.workflows-imported"
|
||||
|
||||
if [ -f "$FLAG" ]; then
|
||||
echo "[n8n-init] Workflows already imported, skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[n8n-init] Waiting for n8n to be ready..."
|
||||
until wget -qO /dev/null http://n8n:5678/healthz 2>/dev/null; do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "[n8n-init] Importing workflows from /home/node/workflows/..."
|
||||
n8n import:workflow --separate --input=/home/node/workflows/
|
||||
|
||||
touch "$FLAG"
|
||||
echo "[n8n-init] Import complete."
|
||||
Reference in New Issue
Block a user