Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 31 additions & 96 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,107 +1,42 @@
name: Deploy to DigitalOcean
name: Deploy to VPS

on:
push:
branches:
- main
pull_request:
branches:
- main

env:
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: /root/CrackCode-Main/crackcode

jobs:
test:
runs-on: ubuntu-latest
name: Test Build

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies (Server)
working-directory: crackcode/server
run: npm ci --omit=dev

- name: Install dependencies (Client)
working-directory: crackcode/client
run: npm ci

- name: Build client
working-directory: crackcode/client
run: npm run build

- name: Lint check (Server)
working-directory: crackcode/server
run: npm run lint 2>/dev/null || echo "No lint script configured"

deploy:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
name: Deploy to Production


steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install SSH key
uses: shimataro/ssh-key-action@v2
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}

- name: Pull latest code
run: |
ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
"cd ${{ env.DEPLOY_PATH }} && git pull origin main"

- name: Rebuild and deploy containers
run: |
ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
"cd ${{ env.DEPLOY_PATH }} && \
docker compose down && \
docker system prune -f && \
docker compose up -d --build"

- name: Verify deployment
run: |
ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
"cd ${{ env.DEPLOY_PATH }} && \
docker compose ps && \
echo '--- Server Logs ---' && \
docker compose logs server | head -20"

- name: Health check
run: |
for i in {1..30}; do
if curl -f http://${{ env.DEPLOY_SERVER }}:4173 > /dev/null 2>&1; then
echo "✅ Application is UP"
exit 0
fi
echo "Checking... ($i/30)"
sleep 2
done
echo "❌ Application failed to start"
exit 1

- name: Deployment Success Notification
if: success()
run: |
echo "🚀 Deployment successful!"
echo "Application: http://${{ env.DEPLOY_SERVER }}:4173"

- name: Deployment Failure Notification
if: failure()
run: |
echo "❌ Deployment failed - Check logs above"
exit 1
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
port: 22
script: |
echo "🚀 Starting deployment..."
cd ~/CrackCode-Main/crackcode

echo "📥 Pulling latest code from main..."
git fetch origin main
git reset --hard origin/main

echo "🔨 Rebuilding Docker containers..."
docker compose down
docker compose up -d --build

echo "⏳ Waiting for services to start..."
sleep 60

echo "✅ Verifying deployment..."
docker compose ps

echo "📋 Server logs:"
docker logs crackcode-server-1 | tail -20

echo "🎉 Deployment complete!"
echo "App live at: http://64.227.140.199:4173"