cloud / internal-packages / installer / container / prove-local.shmain at aacbc74
#!/bin/sh
# prove-local.sh — RUNS THE DEPLOY IMAGE ON THIS MACHINE AS THE DEPLOYER RUNS IT (worker/deploy-run.js):
# the token in the process environment alone, the stack's config as a file. With `plan` or
# `deploy` as the last argument it is THE TAKEOVER instead: a fresh container that has the stack's
# source and a Cloudflare token for the account, and nothing else of the first deploy, runs the
# stack's own command. `plan` with no change planned means it inherited the stack, keys included.
#
# docker build --platform linux/amd64 -t installer-deploy container/ (after ./pack-stack.sh)
# CLOUDFLARE_API_TOKEN=… CLOUDFLARE_ACCOUNT_ID=… container/prove-local.sh <config file | -> <zone> <zone id> [plan|deploy|config]
#
# `-` in place of the config file gives none: the stack then reads the config it keeps beside its
# state, which is all a fork needs. `config` prints that stored config.
set -eu
CONFIG="$1"; ZONE="$2"; ZONE_ID="$3"; TAKEOVER="${4:-}"
NAME=$(printf %s "$ZONE" | tr . -)
# docker forwards the two variables by name: the token is in no argument
set -- docker run --rm --platform linux/amd64 -e CLOUDFLARE_API_TOKEN -e CLOUDFLARE_ACCOUNT_ID \
-e CI=1 -e NO_COLOR=1
[ "$CONFIG" = - ] || set -- "$@" -v "$CONFIG:/work/mind.config.json:ro" -e TAKEOVER_CONFIG=/work/mind.config.json
if [ -z "$TAKEOVER" ]; then
exec "$@" -e ITERATE_ZONE="$ZONE" -e ITERATE_ZONE_ID="$ZONE_ID" -e ITERATE_NAME="$NAME" \
"${IMAGE:-installer-deploy}" bash /stack/run.sh
fi
exec "$@" -w /stack/core/alchemy "${IMAGE:-installer-deploy}" sh -c \
'[ -z "${TAKEOVER_CONFIG:-}" ] || export ITERATE_MIND_CONFIG="$TAKEOVER_CONFIG"; exec pnpm run "$@"' \
takeover "$TAKEOVER" --stage "$NAME" $([ "$TAKEOVER" = deploy ] && echo --yes)