#!/usr/bin/env bash # Register/re-register Gitea act_runner on a Proxmox LXC (5700 heavy pool or 5701 standard pool). # # Env (required unless noted): # GITEA_TOKEN — admin token (root .env) # DEV_VM_VMID — default 5700 # GITEA_RUNNER_INSTANCE — URL passed to act_runner register --instance (5700: http://127.0.0.1:3000) # RUNNER_LABELS — comma-separated labels (docker image refs); default set by wrappers # Optional: # GITEA_URL — default https://gitea.d-bis.org # RUNNER_FORCE_REREGISTER=1 — remove .runner before register # # Usage: # bash scripts/dev-vm/bootstrap-gitea-act-runner-site-wide.sh # bash scripts/dev-vm/bootstrap-gitea-act-runner-secondary-lan.sh set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" [[ -f "${PROJECT_ROOT}/.env" ]] && set -a && source "${PROJECT_ROOT}/.env" && set +a [[ -f "${PROJECT_ROOT}/config/ip-addresses.conf" ]] && source "${PROJECT_ROOT}/config/ip-addresses.conf" PROXMOX_HOST_R630_04="${PROXMOX_HOST_R630_04:-192.168.11.14}" PROXMOX_HOST_R630_01="${PROXMOX_R630_01:-${PROXMOX_HOST_R630_01:-192.168.11.11}}" PROXMOX_HOST_R630_02="${PROXMOX_R630_02:-${PROXMOX_HOST_R630_02:-192.168.11.12}}" get_host_for_vmid() { local vmid="$1" case "$vmid" in 5700|5701) echo "${PROXMOX_HOST_R630_04}";; 5000|7810|2201|2303|2401|6200|6201|10234|10237|5800|5801) echo "${PROXMOX_HOST_R630_02}";; *) echo "${PROXMOX_HOST_R630_01}";; esac } GITEA_URL="${GITEA_URL:-https://gitea.d-bis.org}" GITEA_URL="${GITEA_URL%/}" VMID="${DEV_VM_VMID:-5700}" GITEA_RUNNER_INSTANCE="${GITEA_RUNNER_INSTANCE:-http://127.0.0.1:3000}" if [[ -z "${RUNNER_LABELS:-}" ]]; then echo "ERROR: RUNNER_LABELS must be set (use a wrapper script or export explicitly)." >&2 exit 1 fi if [[ -z "${GITEA_TOKEN:-}" ]]; then echo "ERROR: GITEA_TOKEN not set (root .env)." >&2 exit 1 fi REG_JSON="$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" \ "${GITEA_URL}/api/v1/admin/runners/registration-token")" REG_TOKEN="$(printf '%s' "$REG_JSON" | sed -n 's/.*"token"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')" if [[ -z "$REG_TOKEN" || "$REG_TOKEN" == "null" ]]; then echo "ERROR: Could not get admin registration token. Response:" >&2 printf '%s\n' "$REG_JSON" >&2 exit 1 fi PROXMOX_HOST="$(get_host_for_vmid "$VMID")" echo "Using Proxmox host ${PROXMOX_HOST} for VMID ${VMID}." TB64="$(printf '%s' "$REG_TOKEN" | base64 | tr -d '\n')" LB64="$(printf '%s' "$RUNNER_LABELS" | base64 | tr -d '\n')" IB64="$(printf '%s' "$GITEA_RUNNER_INSTANCE" | base64 | tr -d '\n')" if [[ "${RUNNER_FORCE_REREGISTER:-0}" == "1" ]]; then ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new "root@${PROXMOX_HOST}" \ "pct exec ${VMID} -- bash -lc 'rm -f /opt/act_runner/.runner; systemctl stop act-runner 2>/dev/null || true'" fi ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new "root@${PROXMOX_HOST}" \ "pct exec ${VMID} -- bash -c 'export GITEA_RUNNER_REGISTRATION_TOKEN=\$(printf %s \"${TB64}\" | base64 -d); export RUNNER_LABELS=\$(printf %s \"${LB64}\" | base64 -d); export INSTANCE=\$(printf %s \"${IB64}\" | base64 -d); bash -s'" \ < "${SCRIPT_DIR}/setup-act-runner.sh" ACT_RUNNER_CONFIG="${ACT_RUNNER_CONFIG:-/etc/act_runner/config.yaml}" ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new "root@${PROXMOX_HOST}" \ "pct exec ${VMID} -- env ACT_RUNNER_CONFIG=${ACT_RUNNER_CONFIG} GITEA_ACTION_URL=${GITEA_RUNNER_INSTANCE} bash -s" \ < "${SCRIPT_DIR}/install-act-runner-systemd.sh" echo "Done. VMID ${VMID} — labels: ${RUNNER_LABELS}"