anvilsign in

collin/anvil

1#!/usr/bin/env bash
2# One-shot build + deploy from the Mac: cross-compile, ship the image to
3# hagrid, and (re)start the container there — over a single multiplexed SSH
4# connection, so the key passphrase is asked at most once.
5#
6# Usage: ./deploy/deploy.sh (env overrides: ANVIL_REMOTE, ANVIL_IMAGE, ...)
7set -euo pipefail
8
9REMOTE="${ANVIL_REMOTE:-hagrid}"
10SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11
12# Master connection socket. Everything below reuses it via `ssh -S`.
13CTL="${TMPDIR:-/tmp}/anvil-deploy-$$.sock"
14cleanup() { ssh -S "$CTL" -O exit "$REMOTE" 2>/dev/null || true; }
15trap cleanup EXIT
16
17echo "==> opening SSH master connection to $REMOTE (passphrase asked once)"
18ssh -MNf -S "$CTL" "$REMOTE"
19
20# build.sh ships the image with `ssh $ANVIL_SSH_OPTS`, riding the master.
21export ANVIL_SSH_OPTS="-S $CTL"
22"$SCRIPT_DIR/build.sh"
23
24echo "==> (re)starting anvil on $REMOTE"
25# run.sh is standalone (docker only), so pipe it over — no checkout needed.
26ssh -S "$CTL" "$REMOTE" 'bash -s' < "$SCRIPT_DIR/run.sh"