Add tools.go to pin staticcheck as a module dependency so CI installs it from the module cache instead of re-downloading on every run.
77 lines
3.2 KiB
Bash
Executable File
77 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ── usage ─────────────────────────────────────────────────────────────────────
|
|
usage() {
|
|
echo "Usage: $0 <runner-name>"
|
|
echo " runner-name: runner-node-1 | runner-node-2 | runner-node-3"
|
|
exit 1
|
|
}
|
|
|
|
[[ $# -ne 1 ]] && usage
|
|
|
|
RUNNER_NAME="$1"
|
|
|
|
# validate
|
|
case "$RUNNER_NAME" in
|
|
runner-node-1|runner-node-2|runner-node-3) ;;
|
|
*) echo "ERROR: unknown runner name '$RUNNER_NAME'"; usage ;;
|
|
esac
|
|
|
|
# ── config ────────────────────────────────────────────────────────────────────
|
|
CACHE_PORT=8088
|
|
GITEA_URL="https://gitea.kalekber.cc/"
|
|
REGISTRATION_TOKEN="AboxpDKWx7gizwJ9xeheHVqKjj9J9N9BgyX96wvu"
|
|
IMAGE="docker.io/gitea/act_runner:latest"
|
|
DATA_DIR="$PWD/data/$RUNNER_NAME"
|
|
CFG_PATH="$DATA_DIR/config.yaml"
|
|
|
|
# ── detect THIS machine's LAN IP ──────────────────────────────────────────────
|
|
HOST_IP=$(ip route get 1.1.1.1 | awk '{for(i=1;i<=NF;i++) if($i=="src") print $(i+1); exit}')
|
|
if [[ -z "$HOST_IP" ]]; then
|
|
echo "ERROR: could not detect host LAN IP" >&2
|
|
exit 1
|
|
fi
|
|
echo "Host LAN IP: $HOST_IP"
|
|
|
|
# ── generate config.yaml ──────────────────────────────────────────────────────
|
|
mkdir -p "$DATA_DIR"
|
|
|
|
docker run --rm --entrypoint="" "$IMAGE" \
|
|
act_runner generate-config > "$CFG_PATH"
|
|
|
|
awk -v host="$HOST_IP" -v port="$CACHE_PORT" '
|
|
/^cache:/ { in_cache=1 }
|
|
in_cache && /enabled:/ { $0 = " enabled: true" }
|
|
in_cache && /dir:/ { $0 = " dir: \"/data/cache\"" }
|
|
in_cache && /host:/ { $0 = " host: \"" host "\"" }
|
|
in_cache && /port:/ { $0 = " port: " port; in_cache=0 }
|
|
{ print }
|
|
' "$CFG_PATH" > "${CFG_PATH}.tmp" && mv "${CFG_PATH}.tmp" "$CFG_PATH"
|
|
|
|
echo "Config written to $CFG_PATH (cache $HOST_IP:$CACHE_PORT)"
|
|
|
|
# ── stop + remove old container if exists ────────────────────────────────────
|
|
if docker inspect "$RUNNER_NAME" &>/dev/null; then
|
|
echo "Removing existing $RUNNER_NAME..."
|
|
docker stop "$RUNNER_NAME" || true
|
|
docker rm "$RUNNER_NAME" || true
|
|
fi
|
|
|
|
# ── start runner ──────────────────────────────────────────────────────────────
|
|
docker run \
|
|
-v "$DATA_DIR:/data" \
|
|
-v "$CFG_PATH:/config.yaml" \
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
|
-e CONFIG_FILE=/config.yaml \
|
|
-e GITEA_INSTANCE_URL="$GITEA_URL" \
|
|
-e GITEA_RUNNER_REGISTRATION_TOKEN="$REGISTRATION_TOKEN" \
|
|
-e GITEA_RUNNER_NAME="$RUNNER_NAME" \
|
|
-p "${CACHE_PORT}:${CACHE_PORT}" \
|
|
--restart unless-stopped \
|
|
--name "$RUNNER_NAME" \
|
|
-d "$IMAGE"
|
|
|
|
echo "Runner $RUNNER_NAME started"
|
|
docker ps --filter "name=$RUNNER_NAME" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
|