feat: refine ISAC design and prepare production deployment
Validate and deploy production / validate (push) Successful in 18s
Validate and deploy staging / validate (push) Successful in 18s
Validate and deploy production / deploy (push) Successful in 1m1s
Validate and deploy staging / deploy (push) Successful in 28s

This commit is contained in:
JB
2026-07-26 12:25:47 -04:00
parent 75faef50b8
commit 2e868d86ff
153 changed files with 64660 additions and 264 deletions
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
set -eu
bundle_path=${1:-}
deployment_directory=${2:-/opt/shd-build-production}
if [ -z "$bundle_path" ] || [ ! -f "$bundle_path" ]; then
echo "Usage: bootstrap-production.sh <bootstrap-bundle.json> [deployment-directory]" >&2
exit 2
fi
compose_file="$deployment_directory/compose.production.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 production before the one-time database bootstrap."
compose stop scheduler app || true
compose run --rm --no-deps \
-e ALLOW_PRODUCTION_BOOTSTRAP=true \
-v "$bundle_path:/import/production-bootstrap.json:ro" \
app node scripts/environment-bootstrap-import.mjs \
/import/production-bootstrap.json --target production --confirm-empty-target-replace
echo "Production bootstrap completed."
+55
View File
@@ -0,0 +1,55 @@
name: shd-build-production
services:
app:
image: ${SHD_IMAGE:-shd-build-production:local}
restart: unless-stopped
init: true
env_file:
- .env.production.runtime
environment:
HOST: 0.0.0.0
PORT: 3000
BODY_SIZE_LIMIT: 6M
SKIP_DEFAULT_USERS: "true"
TDR_DATABASE_PATH: /app/data/shd-build-production.db
TDR_AVATAR_STORAGE_PATH: /app/data/avatars
TDR_GAME_ICON_STORAGE_PATH: /app/data/game-icons
APP_ORIGIN: https://shd.build
ORIGIN: https://shd.build
PASSKEY_RP_ID: shd.build
DISCORD_REDIRECT_URI: https://shd.build/auth/discord/callback
ports:
- "0.0.0.0:${SHD_PRODUCTION_PORT:-3102}:3000"
volumes:
- shd_production_data:/app/data
healthcheck:
test:
- CMD
- node
- -e
- fetch('http://127.0.0.1:3000/api/health/database').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))
interval: 15s
timeout: 5s
retries: 8
start_period: 30s
stop_grace_period: 30s
scheduler:
image: ${SHD_IMAGE:-shd-build-production:local}
restart: unless-stopped
init: true
command:
- scheduler
env_file:
- .env.production.runtime
environment:
SCHEDULER_URL: http://app:3000/api/internal/scheduler
depends_on:
app:
condition: service_healthy
stop_grace_period: 30s
volumes:
shd_production_data:
name: shd-build-production-data
+51
View File
@@ -0,0 +1,51 @@
#!/bin/sh
set -eu
deployment_directory=${1:-/opt/shd-build-production}
source_directory=${2:-}
candidate_image=${3:-}
if [ -z "$source_directory" ] || [ ! -f "$source_directory/Dockerfile" ] || [ -z "$candidate_image" ]; then
echo "Usage: deploy-production.sh <deployment-directory> <source-directory> <candidate-image>" >&2
exit 2
fi
compose_file="$deployment_directory/compose.production.yml"
deploy_environment="$deployment_directory/.env.deploy"
compose() {
docker compose --env-file "$deploy_environment" -f "$compose_file" "$@"
}
echo "Building the candidate image while production remains online."
docker build --label org.opencontainers.image.title=shd-build -t "$candidate_image" "$source_directory"
echo "Stopping only SHD production processes before accessing the embedded database."
compose stop scheduler app || true
echo "Creating a timestamped production backup when the database exists."
compose run --rm --no-deps app sh -c \
'if [ -f "$TDR_DATABASE_PATH" ]; then node scripts/db-backup.mjs; else echo "No production database exists yet; skipping backup."; fi'
echo "Applying additive schema migrations."
compose run --rm --no-deps app node scripts/db-migrate.mjs
echo "Starting production."
compose up -d --no-build --remove-orphans app scheduler
container_id=$(compose ps -q app)
attempt=0
while [ "$attempt" -lt 30 ]; do
status=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id")
if [ "$status" = "healthy" ]; then
echo "SHD production deployment is healthy."
exit 0
fi
if [ "$status" = "unhealthy" ] || [ "$status" = "exited" ] || [ "$status" = "dead" ]; then
break
fi
attempt=$((attempt + 1))
sleep 2
done
echo "SHD production failed its health check."
compose logs --tail=150 app
exit 1
+43
View File
@@ -0,0 +1,43 @@
#!/bin/sh
set -eu
production_directory=${1:-/opt/shd-build-production}
staging_directory=${2:-/opt/shd-build-stage}
confirmation=${3:-}
if [ "$confirmation" != "--confirm-replace-staging-isac-data" ]; then
echo "Usage: sync-production-isac-to-staging.sh [production-dir] [staging-dir] --confirm-replace-staging-isac-data" >&2
exit 2
fi
production_compose_file="$production_directory/compose.production.yml"
production_environment="$production_directory/.env.deploy"
staging_compose_file="$staging_directory/compose.staging.yml"
staging_environment="$staging_directory/.env.deploy"
snapshot_name="isac-production-$(date -u +%Y-%m-%dT%H-%M-%SZ).json"
snapshot_path="/tmp/$snapshot_name"
production_compose() {
docker compose --env-file "$production_environment" -f "$production_compose_file" "$@"
}
staging_compose() {
docker compose --env-file "$staging_environment" -f "$staging_compose_file" "$@"
}
restart_services() {
production_compose up -d --no-build app scheduler || true
staging_compose up -d --no-build app scheduler || true
rm -f "$snapshot_path"
}
trap restart_services EXIT
echo "Stopping production writers for a consistent canonical export."
production_compose stop scheduler app
production_compose run --rm --no-deps -v "/tmp:/export" app \
node scripts/isac-data-export.mjs "/export/$snapshot_name"
production_compose up -d --no-build app scheduler
echo "Stopping staging writers before its automatic full and ISAC safety backups."
staging_compose stop scheduler app
staging_compose run --rm --no-deps -v "/tmp:/import:ro" app \
node scripts/isac-data-import.mjs "/import/$snapshot_name" --confirm-replace-isac-data
echo "Production ISAC data was safely synchronized into staging."