69 lines
2.2 KiB
Bash
69 lines
2.2 KiB
Bash
#!/bin/bash
|
|
# Dev-only setup (runs via postCreateCommand in the attached `api` container).
|
|
# Production needs none of this: images carry their dependencies and the
|
|
# api entrypoint migrates on every start.
|
|
set -e
|
|
|
|
REPO=/srv/kirche-einfach
|
|
|
|
echo "=== Setting up kirche-einfach ==="
|
|
|
|
# Backend deps into the venv volume (setup runs via sudo; handed to vscode below).
|
|
echo "--- Installing Python dependencies ---"
|
|
cd "$REPO/backend"
|
|
uv sync
|
|
|
|
# opencode CLI (dev tooling; intentionally not baked into the image).
|
|
if [ ! -x /home/vscode/.opencode/bin/opencode ]; then
|
|
echo "--- Installing opencode ---"
|
|
su vscode -c "curl -fsSL https://opencode.ai/install | bash"
|
|
ln -sf /home/vscode/.opencode/bin/opencode /usr/local/bin/opencode
|
|
fi
|
|
|
|
# Compose services (langflow, lfx) must be up; fail loudly otherwise.
|
|
# (api/frontend are starting alongside this script.)
|
|
echo "--- Waiting for compose services ---"
|
|
if [ ! -f "$REPO/.env" ]; then
|
|
echo "ERROR: $REPO/.env is missing. Copy .env.example to .env and fill in secrets." >&2
|
|
exit 1
|
|
fi
|
|
python3 - <<'EOF'
|
|
import socket
|
|
import sys
|
|
import time
|
|
|
|
targets = [("langflow", 7860), ("lfx", 6004)]
|
|
deadline = time.time() + 180
|
|
pending = dict(targets)
|
|
while pending and time.time() < deadline:
|
|
for host, port in list(pending):
|
|
s = socket.socket()
|
|
s.settimeout(2)
|
|
try:
|
|
s.connect((host, port))
|
|
print(f"OK {host}:{port}", flush=True)
|
|
del pending[(host, port)]
|
|
except OSError:
|
|
pass
|
|
finally:
|
|
s.close()
|
|
if pending:
|
|
time.sleep(2)
|
|
if pending:
|
|
sys.exit(f"ERROR: compose services not ready: {sorted(pending)}")
|
|
EOF
|
|
|
|
# Reconcile backend/flows into the DB + LFX (schema is migrated by the api
|
|
# entrypoint on every start).
|
|
echo "--- Syncing canonical flows ---"
|
|
cd "$REPO/backend"
|
|
uv run python scripts/sync_flows.py --sync || echo "WARN: flow sync failed (check backend/flows and LFX)"
|
|
|
|
echo ""
|
|
echo "=== Setup complete ==="
|
|
echo "Forgejo username: $FORGEJO_USERNAME"
|
|
|
|
# Hand dirs back to vscode (this script runs via sudo; uv creates caches as root)
|
|
chown -R vscode:vscode "$REPO/backend/.venv" \
|
|
"$REPO/frontend/node_modules" \
|
|
/home/vscode/.cache 2>/dev/null || true
|