f6fc356c76
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Run Tests on Branches / Detect Changes (push) Successful in 11s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
- Change CORS_ORIGIN from localhost:4000 to farmacias.hacecalor.net in docker-compose.yml
- Add postgres and parapharmacy-api healthchecks
- Add n8n-init service that runs BEFORE n8n starts:
- Imports workflows via n8n CLI
- Activates all workflows via publish:workflow
- Seeds parapharmacy DB with 20 test products
- Fix parapharmacy-api healthcheck to use node instead of wget (not available in image)
- Fix seed.json to use {products: [...]} format with required source_url field
- Remove activate-workflows.js (replaced by CLI approach)
54 lines
2.1 KiB
Bash
Executable File
54 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# One-shot init: import + activate workflows (before n8n starts), then seed DB.
|
|
# Runs BEFORE n8n so it reads the activated state from DB on startup.
|
|
# Skips if already done (flag file in shared n8n_data volume).
|
|
set -e
|
|
|
|
FLAG="/home/node/.n8n/.workflows-imported"
|
|
|
|
if [ -f "$FLAG" ]; then
|
|
echo "[n8n-init] Already initialized, skipping."
|
|
exit 0
|
|
fi
|
|
|
|
# ── 1. Import workflows via CLI (writes to DB) ───────────────────────
|
|
echo "[n8n-init] Importing workflows..."
|
|
n8n import:workflow --separate --input=/home/node/workflows/ 2>/dev/null
|
|
|
|
# ── 3. Activate all workflows via CLI ────────────────────────────────
|
|
echo "[n8n-init] Activating workflows..."
|
|
TMPFILE=$(mktemp)
|
|
n8n export:workflow --all --output="$TMPFILE" 2>/dev/null
|
|
|
|
node -e "
|
|
const fs = require('fs');
|
|
const wfs = JSON.parse(fs.readFileSync('$TMPFILE', 'utf8'));
|
|
wfs.forEach(w => console.log(w.id));
|
|
" | while read -r WF_ID; do
|
|
n8n publish:workflow --id="$WF_ID" 2>/dev/null
|
|
echo "[n8n-init] Activated $WF_ID"
|
|
done
|
|
|
|
rm -f "$TMPFILE"
|
|
echo "[n8n-init] Workflows activated."
|
|
|
|
# ── 4. Seed parapharmacy DB ──────────────────────────────────────────
|
|
echo "[n8n-init] Waiting for parapharmacy-api..."
|
|
until wget -qO /dev/null http://parapharmacy-api:3002/api/health 2>/dev/null; do
|
|
sleep 2
|
|
done
|
|
|
|
if [ -f /home/node/seed.json ]; then
|
|
echo "[n8n-init] Seeding parapharmacy products..."
|
|
SEED_RESP=$(wget -qO- --post-file=/home/node/seed.json \
|
|
--header="Content-Type: application/json" \
|
|
http://parapharmacy-api:3002/api/products/bulk 2>&1)
|
|
echo "[n8n-init] Seed result: $SEED_RESP"
|
|
else
|
|
echo "[n8n-init] WARNING: seed.json not found, skipping seed."
|
|
fi
|
|
|
|
# ── Done ─────────────────────────────────────────────────────────────
|
|
touch "$FLAG"
|
|
echo "[n8n-init] Initialization complete."
|