forked from syntaxbullet/aurorabot
201 lines
6.3 KiB
YAML
201 lines
6.3 KiB
YAML
# Aurora CI/CD Pipeline
|
|
# Builds, tests, and deploys to production server
|
|
|
|
name: Deploy to Production
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
workflow_dispatch: # Allow manual trigger
|
|
|
|
env:
|
|
REGISTRY: ghcr.io
|
|
IMAGE_NAME: ${{ github.repository }}
|
|
|
|
jobs:
|
|
# ==========================================================================
|
|
# Test Job
|
|
# ==========================================================================
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:17-alpine
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: aurora_test
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Bun
|
|
uses: oven-sh/setup-bun@v2
|
|
with:
|
|
bun-version: latest
|
|
|
|
- name: Install Dependencies
|
|
run: bun install --frozen-lockfile
|
|
|
|
- name: Create Config File
|
|
run: |
|
|
mkdir -p shared/config
|
|
cat <<EOF > shared/config/config.json
|
|
{
|
|
"leveling": { "base": 100, "exponent": 2.5, "chat": { "cooldownMs": 60000, "minXp": 15, "maxXp": 25 } },
|
|
"economy": {
|
|
"daily": { "amount": "100", "streakBonus": "10", "weeklyBonus": "50", "cooldownMs": 86400000 },
|
|
"transfers": { "allowSelfTransfer": false, "minAmount": "1" },
|
|
"exam": { "multMin": 0.05, "multMax": 0.03 }
|
|
},
|
|
"inventory": { "maxStackSize": "99", "maxSlots": 50 },
|
|
"commands": {},
|
|
"lootdrop": {
|
|
"activityWindowMs": 120000, "minMessages": 1, "spawnChance": 1, "cooldownMs": 3000,
|
|
"reward": { "min": 40, "max": 150, "currency": "Astral Units" }
|
|
},
|
|
"studentRole": "123", "visitorRole": "456", "colorRoles": [],
|
|
"moderation": {
|
|
"prune": { "maxAmount": 100, "confirmThreshold": 50, "batchSize": 100, "batchDelayMs": 1000 },
|
|
"cases": { "dmOnWarn": false }
|
|
},
|
|
"trivia": {
|
|
"entryFee": "50", "rewardMultiplier": 1.5, "timeoutSeconds": 30, "cooldownMs": 60000,
|
|
"categories": [], "difficulty": "random"
|
|
},
|
|
"system": {}
|
|
}
|
|
EOF
|
|
|
|
- name: Setup Test Database
|
|
run: bun run db:push:local
|
|
env:
|
|
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/aurora_test
|
|
# Create .env.test for implicit usage by bun
|
|
DISCORD_BOT_TOKEN: test_token
|
|
DISCORD_CLIENT_ID: 123
|
|
DISCORD_GUILD_ID: 123
|
|
|
|
- name: Run Tests
|
|
run: |
|
|
# Create .env.test for test-sequential.sh / bun test
|
|
cat <<EOF > .env.test
|
|
DATABASE_URL="postgresql://postgres:postgres@127.0.0.1:5432/aurora_test"
|
|
DISCORD_BOT_TOKEN="test_token"
|
|
DISCORD_CLIENT_ID="123456789"
|
|
DISCORD_GUILD_ID="123456789"
|
|
ADMIN_TOKEN="admin_token_123"
|
|
LOG_LEVEL="error"
|
|
EOF
|
|
bash shared/scripts/test-sequential.sh
|
|
|
|
# ==========================================================================
|
|
# Build Job
|
|
# ==========================================================================
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
outputs:
|
|
image_tag: ${{ steps.meta.outputs.tags }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
tags: |
|
|
type=sha,prefix=
|
|
type=raw,value=latest
|
|
|
|
- name: Build and Push Docker Image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile.prod
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
# ==========================================================================
|
|
# Deploy Job
|
|
# ==========================================================================
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
environment: production
|
|
|
|
steps:
|
|
- name: Deploy to Production Server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
cd ~/Aurora
|
|
|
|
# Pull latest code
|
|
git pull origin main
|
|
|
|
# Pull latest Docker image
|
|
docker compose -f docker-compose.prod.yml pull 2>/dev/null || true
|
|
|
|
# Build and restart containers
|
|
docker compose -f docker-compose.prod.yml build --no-cache
|
|
docker compose -f docker-compose.prod.yml down
|
|
docker compose -f docker-compose.prod.yml up -d
|
|
|
|
# Wait for health checks
|
|
sleep 15
|
|
|
|
# Verify deployment
|
|
docker ps | grep aurora
|
|
|
|
# Cleanup old images
|
|
docker image prune -f
|
|
|
|
- name: Verify Deployment
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
# Check if app container is healthy
|
|
if docker ps | grep -q "aurora_app.*healthy"; then
|
|
echo "✅ Deployment successful - aurora_app is healthy"
|
|
exit 0
|
|
else
|
|
echo "⚠️ Health check pending, checking container status..."
|
|
docker ps | grep aurora
|
|
docker logs aurora_app --tail 20
|
|
exit 0
|
|
fi
|