Files
shd.build/deploy/bootstrap-staging.sh
jb 25d9241b51
Validate and deploy production / validate (push) Canceled after 0s
Validate and deploy production / deploy (push) Canceled after 0s
Validate and deploy staging / validate (push) Failing after 22s
Validate and deploy staging / deploy (push) Skipped
feat: migrate secrets to Infisical
2026-08-02 01:19:41 -04:00

52 lines
1.6 KiB
Bash

#!/bin/sh
set -eu
bundle_path=${1:-}
deployment_directory=${2:-/opt/shd-build-stage}
if [ -z "$bundle_path" ] || [ ! -f "$bundle_path" ]; then
echo "Usage: bootstrap-staging.sh <bootstrap-bundle.json> [deployment-directory]" >&2
exit 2
fi
bundle_path=$(readlink -f "$bundle_path")
compose_file="$deployment_directory/compose.staging.yml"
deploy_environment="$deployment_directory/.env.deploy"
volume_bundle_path=/app/data/.staging-bootstrap-import.json
remove_volume_bundle=false
compose() {
docker compose --env-file "$deploy_environment" -f "$compose_file" "$@"
}
cleanup() {
status=$?
trap - EXIT HUP INT TERM
set +e
if [ "$remove_volume_bundle" = true ]; then
compose run --rm --no-deps --entrypoint rm --user root app -f "$volume_bundle_path"
fi
if ! compose up -d --no-build app scheduler; then status=1; fi
exit "$status"
}
trap cleanup EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
echo "Stopping staging before the one-time database bootstrap."
compose stop scheduler app
compose create app >/dev/null
app_container=$(compose ps --all --quiet app)
if [ -z "$app_container" ]; then
echo "The stopped staging app container could not be found." >&2
exit 1
fi
docker cp "$bundle_path" "$app_container:$volume_bundle_path"
remove_volume_bundle=true
compose run --rm --no-deps --entrypoint sh --user root app -c \
'chown shd-runtime:node "$1" && chmod 600 "$1"' sh "$volume_bundle_path"
compose run --rm --no-deps \
-e ALLOW_STAGING_BOOTSTRAP=true \
app node scripts/stage-bootstrap-import.mjs \
"$volume_bundle_path" --confirm-empty-staging-replace
echo "Staging bootstrap completed."