86 lines
3 KiB
Bash
86 lines
3 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
|
|
|
|
# Venv lives outside the bind-mount (see backend/Dockerfile).
|
|
export UV_PYTHON_INSTALL_DIR=/opt/python UV_PROJECT_ENVIRONMENT=/opt/venv
|
|
|
|
echo "=== Setting up kirche-einfach ==="
|
|
|
|
# Writable dirs first: this script runs via sudo as root, but the editor and
|
|
# most commands run as vscode. (A root-created backend/data/ or venv used to
|
|
# break the DB and the interpreter for vscode.)
|
|
mkdir -p "$REPO/backend/data" \
|
|
"$REPO/frontend/node_modules" \
|
|
/opt/python /opt/venv \
|
|
/home/vscode/.cache \
|
|
/home/vscode/.local/share/uv \
|
|
/home/vscode/.local/share/opencode \
|
|
/home/vscode/.config/opencode
|
|
chown -R vscode:vscode "$REPO/backend/data" \
|
|
"$REPO/frontend/node_modules" \
|
|
/opt/python /opt/venv \
|
|
/home/vscode/.cache \
|
|
/home/vscode/.local/share/uv \
|
|
/home/vscode/.local/share/opencode \
|
|
/home/vscode/.config/opencode 2>/dev/null || true
|
|
|
|
# Backend deps into /opt/venv, as vscode (a root-owned venv is unusable for
|
|
# the editor; uv resolves at setup time, no lockfile is committed).
|
|
echo "--- Installing Python dependencies ---"
|
|
cd "$REPO/backend"
|
|
su vscode -c "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"
|
|
su vscode -c "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"
|