Deployment Workflow
Complete guide to Hyperscape’s automated deployment pipeline.Overview
Hyperscape uses GitHub Actions for automated deployment to three targets:- Cloudflare Pages - Static client hosting (https://hyperscape.gg)
- Railway - Game server (dev/prod environments)
- Vast.ai - GPU streaming and duel arena
Deployment Targets
Cloudflare Pages (Client)
Workflow:.github/workflows/deploy-pages.yml
Triggers:
- Push to
mainbranch - Changes to
packages/client/**orpackages/shared/**
- Build shared package first (
bun run buildin packages/shared) - Build client package (
bun run buildin packages/client) - Deploy to Cloudflare Pages via Wrangler
- Configure R2 CORS for asset loading
- Production: https://hyperscape.gg
- Preview: https://[commit-hash].hyperscape.pages.dev
CLOUDFLARE_API_TOKEN- Cloudflare API token with Pages permissionsCLOUDFLARE_ACCOUNT_ID- Cloudflare account IDR2_ACCESS_KEY_ID- R2 access key for CORS configurationR2_SECRET_ACCESS_KEY- R2 secret key
Railway (Game Server)
Workflow:.github/workflows/deploy-railway.yml
Branch Mapping:
main→prodenvironmentdevelop→devenvironment
- Detect which environment based on branch
- Deploy to Railway using railway CLI
- Railway builds and deploys automatically
RAILWAY_TOKEN- Railway API tokenRAILWAY_PROD_ENV_ID- Production environment IDRAILWAY_DEV_ENV_ID- Development environment ID
Vast.ai (GPU Streaming)
Workflow:.github/workflows/deploy-vast.yml
Triggers:
- Push to
mainbranch (after CI passes) - Manual trigger via
workflow_dispatch
-
Enter Maintenance Mode (300s timeout)
- Pauses new duel cycles
- Waits for pending markets to resolve
- Prevents interrupting active duels
-
Deploy via SSH:
- Write secrets to
/tmp/hyperscape-secrets.env - Run
scripts/deploy-vast.sh - Script handles:
- Git pull and reset
- GPU rendering setup (Xorg/Xvfb)
- PulseAudio configuration
- Chrome installation
- Dependency installation
- Build process
- Database migration
- PM2 restart
- Write secrets to
-
Health Check (120s timeout, 5s interval):
- Wait for server to respond to
/healthendpoint - Verify streaming is active
- Check RTMP connections
- Wait for server to respond to
-
Exit Maintenance Mode:
- Resume duel cycles
- Resume normal operations
VAST_SSH_HOST- SSH hostname (e.g., ssh6.vast.ai)VAST_SSH_PORT- SSH port for your instanceVAST_SSH_KEY- SSH private keyDATABASE_URL- PostgreSQL connection stringTWITCH_STREAM_KEY- Twitch stream keyKICK_STREAM_KEY- Kick stream keyKICK_RTMP_URL- Kick RTMP URLX_STREAM_KEY- X/Twitter stream keyX_RTMP_URL- X/Twitter RTMP URLSOLANA_DEPLOYER_PRIVATE_KEY- Solana keypair (base58)JWT_SECRET- JWT signing secretARENA_EXTERNAL_BET_WRITE_KEY- External betting API key
Maintenance Mode
Purpose
Maintenance mode allows graceful deployments without interrupting active duels or betting markets.How It Works
-
Enter Maintenance:
- Sets
maintenanceMode.active = true - Pauses new duel cycle starts
- Allows current duels to complete
- Waits for pending markets to resolve
- Sets
-
Deploy:
- Code is updated
- Dependencies installed
- Database migrated
- Processes restarted
-
Exit Maintenance:
- Sets
maintenanceMode.active = false - Resumes duel cycles
- Resumes normal operations
- Sets
API Endpoints
Enter Maintenance:Deployment Checklist
Before Deploying
- All tests passing (
npm test) - Linting passes (
npm run lint) - Type checking passes (
npm run typecheck) - Build succeeds locally (
bun run build) - Database migrations tested locally
- Breaking changes documented in CHANGELOG.md
- Environment variables updated in GitHub secrets
Cloudflare Pages
-
PUBLIC_PRIVY_APP_IDmatches server -
PUBLIC_API_URLpoints to production server -
PUBLIC_WS_URLpoints to production WebSocket -
PUBLIC_CDN_URLpoints to R2 bucket - R2 CORS configured for hyperscape.gg
Railway
-
DATABASE_URLconfigured -
JWT_SECRETset (32+ characters) -
ADMIN_CODEset -
PRIVY_APP_IDandPRIVY_APP_SECRETconfigured - Environment variables match client
Vast.ai
- NVIDIA GPU instance selected
- SSH access configured
- All streaming secrets configured
-
SOLANA_DEPLOYER_PRIVATE_KEYset - Maintenance mode API tested
- Health check endpoint working
Rollback Procedures
Cloudflare Pages
Cloudflare Pages keeps deployment history:- Go to Cloudflare Dashboard → Pages → hyperscape
- Click “View build” on previous successful deployment
- Click “Rollback to this deployment”
Railway
Railway keeps deployment history:- Go to Railway Dashboard → Project → Environment
- Click “Deployments” tab
- Find previous successful deployment
- Click “Redeploy”
Vast.ai
Manual rollback via SSH:Monitoring Deployments
GitHub Actions
Monitor deployment progress:- Go to GitHub → Actions tab
- Click on running workflow
- View logs for each step
Cloudflare Pages
Monitor build progress:- Go to Cloudflare Dashboard → Pages → hyperscape
- Click “View build” on latest deployment
- View build logs
Railway
Monitor deployment:- Go to Railway Dashboard → Project → Environment
- Click “Deployments” tab
- View deployment logs
Vast.ai
Monitor via SSH:Troubleshooting
Deployment Fails at Build
Symptoms:- GitHub Actions shows build errors
- “Module not found” errors
- Check build order (physx-js-webidl → procgen → shared → others)
- Verify all dependencies in package.json
- Clear caches:
bun run clean && bun install - Check for circular dependencies
Deployment Succeeds but Site Broken
Symptoms:- Deployment completes but site shows errors
- Assets fail to load (404s)
- Check
PUBLIC_CDN_URLis correct - Verify R2 CORS is configured
- Check browser console for errors
- Verify environment variables match between client and server
Vast.ai Deployment Fails
Symptoms:- SSH connection fails
- GPU setup fails
- Health check times out
- Verify SSH credentials in GitHub secrets
- Check Vast.ai instance is running
- Review deploy-vast.sh logs in GitHub Actions
- SSH manually and check GPU:
nvidia-smi - Check Xorg logs:
cat /var/log/Xorg.99.log
Maintenance Mode Stuck
Symptoms:- Maintenance mode doesn’t exit
- Duels don’t resume
- Check maintenance status:
curl .../admin/maintenance/status - Force exit:
curl -X POST .../admin/maintenance/exit - Restart PM2:
bunx pm2 restart hyperscape-duel - Check for pending markets in database
Best Practices
- Test Locally First: Always test changes locally before deploying
- Use Maintenance Mode: For production deployments, always use maintenance mode
- Monitor Deployments: Watch GitHub Actions and server logs during deployment
- Verify Health: Check health endpoints after deployment
- Have Rollback Plan: Know how to rollback before deploying
- Update Secrets Securely: Rotate secrets regularly, never commit to git
- Document Breaking Changes: Update CHANGELOG.md for breaking changes
- Coordinate Deployments: Client and server should deploy together for breaking changes
See Also
- docs/vast-deployment.md - Vast.ai deployment guide
- docs/railway-dev-prod.md - Railway deployment
- docs/maintenance-mode-api.md - Maintenance mode API
- docs/streaming-configuration.md - Streaming configuration
- scripts/deploy-vast.sh - Deployment script