| 1 | #!/usr/bin/env bash |
| 2 | # (Re)start the anvil container on hagrid from an ALREADY-LOADED image. |
| 3 | # |
| 4 | # Build and ship the image first with deploy/build.sh on a capable machine |
| 5 | # (the VPS can't compile it). This script only runs docker — no build — so it's |
| 6 | # safe on the low-RAM box. Standalone: needs only docker + the loaded image. |
| 7 | set -euo pipefail |
| 8 | |
| 9 | IMAGE="${ANVIL_IMAGE:-anvil:latest}" |
| 10 | NETWORK="${ANVIL_NETWORK:-hagrid}" |
| 11 | SSH_PORT="${ANVIL_SSH_PORT:-2222}" |
| 12 | DOCKER_SOCK="${ANVIL_DOCKER_SOCK:-/var/run/docker.sock}" |
| 13 | |
| 14 | # The CI runner drives Docker via the host socket. Mount it in, and add the |
| 15 | # socket's group to the non-root `anvil` user so it can actually open it. |
| 16 | # NOTE: socket access = root-equivalent on the host. We accept this because |
| 17 | # anvil is a single-tenant, owner-operated forge; CI only runs code the owner |
| 18 | # pushed. Do not expose this instance to untrusted users. |
| 19 | SOCK_GID="$(stat -c '%g' "$DOCKER_SOCK")" |
| 20 | |
| 21 | docker rm -f anvil 2>/dev/null || true |
| 22 | docker run -d \ |
| 23 | --name anvil \ |
| 24 | --network "$NETWORK" \ |
| 25 | --restart unless-stopped \ |
| 26 | -p "${SSH_PORT}:2222" \ |
| 27 | -v anvil-data:/data \ |
| 28 | -v "${DOCKER_SOCK}:/var/run/docker.sock" \ |
| 29 | --group-add "$SOCK_GID" \ |
| 30 | "$IMAGE" |
| 31 | |
| 32 | echo "==> anvil (re)started from $IMAGE (web: anvil:3000 via Caddy, ssh: host :${SSH_PORT}, docker.sock gid ${SOCK_GID})" |