Files
noc/deploy/entrypoint.sh
Fam Zheng dbd729ecb8 add Gitea Bot interface: webhook server, API tool, Caddy ingress
- Add src/gitea.rs: axum webhook server on :9800, handles @mention in
  issues and PRs, spawns claude -p for review, posts result as comment
- Add call_gitea_api tool: LLM can directly call Gitea REST API with
  pre-configured admin token (noc_bot identity)
- Add Caddy to Docker image as ingress layer (subdomain/path routing)
- Config: add gitea section with token_file support for auto-provisioned token
- Update suite.md: VPS-first deployment, SubAgent architecture, Caddy role
2026-04-10 21:09:15 +01:00

103 lines
3.6 KiB
Bash

#!/bin/bash
set -euo pipefail
GITEA_DATA="/data/gitea"
NOC_DATA="/data/noc"
CADDY_DATA="/data/caddy"
GITEA_DB="$GITEA_DATA/gitea.db"
GITEA_INI="$GITEA_DATA/app.ini"
GITEA_TOKEN_FILE="$NOC_DATA/gitea-token"
CADDYFILE="$CADDY_DATA/Caddyfile"
GITEA_ADMIN_USER="${GITEA_ADMIN_USER:-noc}"
GITEA_ADMIN_PASS="${GITEA_ADMIN_PASS:-noc-admin-changeme}"
GITEA_ADMIN_EMAIL="${GITEA_ADMIN_EMAIL:-noc@localhost}"
GITEA_HTTP_PORT="${GITEA_HTTP_PORT:-3000}"
mkdir -p "$GITEA_DATA" "$NOC_DATA" "$CADDY_DATA" /data/www
# ── caddy config ───────────────────────────────────────────────────
if [ ! -f "$CADDYFILE" ]; then
cp /opt/noc/Caddyfile "$CADDYFILE"
echo "[caddy] created $CADDYFILE"
fi
# ── gitea config ────────────────────────────────────────────────────
if [ ! -f "$GITEA_INI" ]; then
cat > "$GITEA_INI" <<EOF
[server]
HTTP_PORT = ${GITEA_HTTP_PORT}
ROOT_URL = http://localhost:${GITEA_HTTP_PORT}/
LFS_START_SERVER = false
[database]
DB_TYPE = sqlite3
PATH = ${GITEA_DB}
[security]
INSTALL_LOCK = true
[service]
DISABLE_REGISTRATION = true
[log]
MODE = console
LEVEL = Warn
EOF
echo "[gitea] created $GITEA_INI"
fi
# ── start caddy ────────────────────────────────────────────────────
echo "[suite] starting caddy..."
caddy run --config "$CADDYFILE" --adapter caddyfile &
# ── start gitea in background ──────────────────────────────────────
echo "[suite] starting gitea..."
gitea web --config "$GITEA_INI" --custom-path "$GITEA_DATA/custom" &
GITEA_PID=$!
# wait for gitea to be ready
for i in $(seq 1 30); do
if curl -sf "http://localhost:${GITEA_HTTP_PORT}/api/v1/version" > /dev/null 2>&1; then
echo "[suite] gitea ready"
break
fi
if [ "$i" -eq 30 ]; then
echo "[suite] ERROR: gitea failed to start"
exit 1
fi
sleep 1
done
# ── create admin user + token ──────────────────────────────────────
if ! gitea admin user list --config "$GITEA_INI" 2>/dev/null | grep -q "$GITEA_ADMIN_USER"; then
gitea admin user create \
--config "$GITEA_INI" \
--username "$GITEA_ADMIN_USER" \
--password "$GITEA_ADMIN_PASS" \
--email "$GITEA_ADMIN_EMAIL" \
--admin
echo "[suite] created admin user: $GITEA_ADMIN_USER"
fi
if [ ! -f "$GITEA_TOKEN_FILE" ]; then
TOKEN=$(curl -sf -X POST \
"http://localhost:${GITEA_HTTP_PORT}/api/v1/users/${GITEA_ADMIN_USER}/tokens" \
-u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASS}" \
-H "Content-Type: application/json" \
-d "{\"name\":\"noc-suite\",\"scopes\":[\"all\"]}" \
| jq -r '.sha1')
echo "$TOKEN" > "$GITEA_TOKEN_FILE"
echo "[suite] admin token saved to $GITEA_TOKEN_FILE"
fi
# ── copy default noc config if missing ─────────────────────────────
if [ ! -f "$NOC_DATA/config.yaml" ]; then
cp /opt/noc/config.example.yaml "$NOC_DATA/config.yaml"
echo "[suite] copied default config to $NOC_DATA/config.yaml — edit before use"
fi
# ── start noc ──────────────────────────────────────────────────────
echo "[suite] starting noc..."
exec noc