add staging environment
This commit is contained in:
79
docker-compose.staging.yml
Normal file
79
docker-compose.staging.yml
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Staging environment — runs alongside production on the same VM.
|
||||||
|
# Completely independent: own database, own app container, different ports.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# docker compose -f docker-compose.staging.yml -p esports-staging up -d --build
|
||||||
|
#
|
||||||
|
# Prerequisites (one-time server setup):
|
||||||
|
# 1. DNS: A record for staging.esports.vash.software → VM IP
|
||||||
|
# 2. SSL: sudo certbot certonly --nginx -d staging.esports.vash.software
|
||||||
|
# 3. nginx: reverse proxy staging.esports.vash.software → 127.0.0.1:3002
|
||||||
|
# 4. osu! OAuth: register a separate app at https://osu.ppy.sh/home/account/edit
|
||||||
|
# with callback URL: https://staging.esports.vash.software/api/auth/oauth2/callback/osu
|
||||||
|
# 5. osu! IRC: get a separate IRC password from https://osu.ppy.sh/p/irc
|
||||||
|
# 6. Copy .env.staging.example → .env.staging and fill in values
|
||||||
|
|
||||||
|
services:
|
||||||
|
staging-db:
|
||||||
|
image: postgres:17
|
||||||
|
container_name: esports-staging-db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: vash_staging
|
||||||
|
POSTGRES_USER: vash_staging
|
||||||
|
POSTGRES_PASSWORD: ${STAGING_DB_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- pgdata-staging:/var/lib/postgresql/data
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:5433:5432"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U vash_staging -d vash_staging"]
|
||||||
|
interval: 2s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 10
|
||||||
|
start_period: 2s
|
||||||
|
|
||||||
|
staging-app:
|
||||||
|
build: .
|
||||||
|
container_name: esports-staging-app
|
||||||
|
restart: unless-stopped
|
||||||
|
stop_grace_period: 2s
|
||||||
|
depends_on:
|
||||||
|
staging-db:
|
||||||
|
condition: service_healthy
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:3002:3000"
|
||||||
|
environment:
|
||||||
|
DATABASE_URL: postgresql://vash:***REMOVED***@db:5432/vash_staging
|
||||||
|
ORIGIN: https://staging.esports.vash.software
|
||||||
|
BETTER_AUTH_SECRET: ${BETTER_AUTH_SECRET}
|
||||||
|
OSU_CLIENT_ID: ${OSU_CLIENT_ID}
|
||||||
|
OSU_CLIENT_SECRET: ${OSU_CLIENT_SECRET}
|
||||||
|
OSU_IRC_USERNAME: ${OSU_IRC_USERNAME}
|
||||||
|
OSU_IRC_PASSWORD: ${OSU_IRC_PASSWORD}
|
||||||
|
DISCORD_BOT_TOKEN: ${DISCORD_BOT_TOKEN}
|
||||||
|
DISCORD_MATCH_CHANNEL_ID: ${DISCORD_MATCH_CHANNEL_ID}
|
||||||
|
R2_ACCOUNT_ID: ${R2_ACCOUNT_ID}
|
||||||
|
R2_ACCESS_KEY_ID: ${R2_ACCESS_KEY_ID}
|
||||||
|
R2_SECRET_ACCESS_KEY: ${R2_SECRET_ACCESS_KEY}
|
||||||
|
R2_BUCKET: ${R2_BUCKET:-vash-esports-images}
|
||||||
|
R2_PUBLIC_URL: ${R2_PUBLIC_URL:-https://cdn.esports.vash.software}
|
||||||
|
ROOT_ADMIN_EMAIL: ${ROOT_ADMIN_EMAIL}
|
||||||
|
NODE_ENV: production
|
||||||
|
env_file:
|
||||||
|
- .env.staging
|
||||||
|
healthcheck:
|
||||||
|
test:
|
||||||
|
[
|
||||||
|
"CMD",
|
||||||
|
"bun",
|
||||||
|
"-e",
|
||||||
|
"fetch('http://localhost:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))",
|
||||||
|
]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 3s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pgdata-staging:
|
||||||
@@ -38,7 +38,13 @@ services:
|
|||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "bun", "-e", "fetch('http://localhost:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"]
|
test:
|
||||||
|
[
|
||||||
|
"CMD",
|
||||||
|
"bun",
|
||||||
|
"-e",
|
||||||
|
"fetch('http://localhost:3000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))",
|
||||||
|
]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 3s
|
timeout: 3s
|
||||||
retries: 3
|
retries: 3
|
||||||
@@ -72,7 +78,11 @@ services:
|
|||||||
DATABASE_URL: postgresql://umami:${UMAMI_DB_PASSWORD}@umami-db:5432/umami
|
DATABASE_URL: postgresql://umami:${UMAMI_DB_PASSWORD}@umami-db:5432/umami
|
||||||
APP_SECRET: ${UMAMI_APP_SECRET}
|
APP_SECRET: ${UMAMI_APP_SECRET}
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "wget -q -O /dev/null http://localhost:3000/api/heartbeat || exit 1"]
|
test:
|
||||||
|
[
|
||||||
|
"CMD-SHELL",
|
||||||
|
"wget -q -O /dev/null http://localhost:3000/api/heartbeat || exit 1",
|
||||||
|
]
|
||||||
interval: 15s
|
interval: 15s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|||||||
79
scripts/deploy-staging.sh
Executable file
79
scripts/deploy-staging.sh
Executable file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Deploy the staging environment.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# ./scripts/deploy-staging.sh # deploy current branch
|
||||||
|
# ./scripts/deploy-staging.sh v1 # deploy a specific branch
|
||||||
|
# ./scripts/deploy-staging.sh main --seed # deploy + seed data
|
||||||
|
#
|
||||||
|
# Prerequisites:
|
||||||
|
# - .env.staging exists with all values filled in
|
||||||
|
# - Docker is running
|
||||||
|
# - DNS, SSL, and nginx are configured (see docker-compose.staging.yml header)
|
||||||
|
|
||||||
|
COMPOSE_FILE="docker-compose.staging.yml"
|
||||||
|
PROJECT="esports-staging"
|
||||||
|
BRANCH="${1:-}"
|
||||||
|
SEED=false
|
||||||
|
|
||||||
|
# Parse args
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
--seed) SEED=true ;;
|
||||||
|
*) BRANCH="$arg" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "=== Deploying staging ==="
|
||||||
|
|
||||||
|
# Checkout branch if specified
|
||||||
|
if [ -n "$BRANCH" ] && [ "$BRANCH" != "--seed" ]; then
|
||||||
|
echo "Switching to branch: $BRANCH"
|
||||||
|
git fetch origin
|
||||||
|
git checkout "$BRANCH"
|
||||||
|
git pull origin "$BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check .env.staging exists
|
||||||
|
if [ ! -f .env.staging ]; then
|
||||||
|
echo "ERROR: .env.staging not found. Copy .env.staging.example and fill in values."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build and restart
|
||||||
|
echo "Building containers..."
|
||||||
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT" build
|
||||||
|
|
||||||
|
echo "Starting containers..."
|
||||||
|
docker compose -f "$COMPOSE_FILE" -p "$PROJECT" up -d
|
||||||
|
|
||||||
|
# Wait for DB
|
||||||
|
echo "Waiting for staging DB to be ready..."
|
||||||
|
until docker compose -f "$COMPOSE_FILE" -p "$PROJECT" exec staging-db pg_isready -U vash_staging -d vash_staging 2>/dev/null; do
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "DB ready."
|
||||||
|
|
||||||
|
# Run schema push (reads DATABASE_URL from the staging DB exposed on host port 5433)
|
||||||
|
echo "Pushing schema to staging DB..."
|
||||||
|
source .env.staging
|
||||||
|
export DATABASE_URL="postgresql://vash_staging:${STAGING_DB_PASSWORD}@127.0.0.1:5433/vash_staging"
|
||||||
|
bun run db:push
|
||||||
|
|
||||||
|
# Optionally seed
|
||||||
|
if [ "$SEED" = true ]; then
|
||||||
|
echo "Seeding staging database..."
|
||||||
|
bun scripts/seed-staging.ts --fresh
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Staging deployed ==="
|
||||||
|
echo "URL: https://staging.esports.vash.software"
|
||||||
|
echo "DB: postgresql://vash_staging:***@127.0.0.1:5433/vash_staging"
|
||||||
|
echo ""
|
||||||
|
echo "Useful commands:"
|
||||||
|
echo " docker compose -f $COMPOSE_FILE -p $PROJECT logs -f staging-app"
|
||||||
|
echo " docker compose -f $COMPOSE_FILE -p $PROJECT ps"
|
||||||
|
echo " docker compose -f $COMPOSE_FILE -p $PROJECT down"
|
||||||
1016
scripts/seed-staging.ts
Normal file
1016
scripts/seed-staging.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user