#!/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 [deployment-directory]" >&2 exit 2 fi compose_file="$deployment_directory/compose.staging.yml" deploy_environment="$deployment_directory/.env.deploy" compose() { docker compose --env-file "$deploy_environment" -f "$compose_file" "$@" } restart_services() { compose up -d --no-build app scheduler } trap restart_services EXIT echo "Stopping staging before the one-time database bootstrap." compose stop scheduler app || true compose run --rm --no-deps \ -e ALLOW_STAGING_BOOTSTRAP=true \ -v "$bundle_path:/import/staging-bootstrap.json:ro" \ app node scripts/stage-bootstrap-import.mjs \ /import/staging-bootstrap.json --confirm-empty-staging-replace echo "Staging bootstrap completed."