1- name : Deploy to DigitalOcean
1+ name : Deploy to VPS
22
33on :
44 push :
55 branches :
66 - main
7- pull_request :
8- branches :
9- - main
10-
11- env :
12- DEPLOY_SERVER : ${{ secrets.DEPLOY_SERVER }}
13- DEPLOY_USER : ${{ secrets.DEPLOY_USER }}
14- DEPLOY_PATH : /root/CrackCode-Main/crackcode
157
168jobs :
17- test :
18- runs-on : ubuntu-latest
19- name : Test Build
20-
21- steps :
22- - name : Checkout code
23- uses : actions/checkout@v4
24-
25- - name : Setup Node.js
26- uses : actions/setup-node@v4
27- with :
28- node-version : ' 20'
29- cache : ' npm'
30-
31- - name : Install dependencies (Server)
32- working-directory : crackcode/server
33- run : npm ci --omit=dev
34-
35- - name : Install dependencies (Client)
36- working-directory : crackcode/client
37- run : npm ci
38-
39- - name : Build client
40- working-directory : crackcode/client
41- run : npm run build
42-
43- - name : Lint check (Server)
44- working-directory : crackcode/server
45- run : npm run lint 2>/dev/null || echo "No lint script configured"
46-
479 deploy :
48- needs : test
49- if : github.ref == 'refs/heads/main' && github.event_name == 'push'
5010 runs-on : ubuntu-latest
51- name : Deploy to Production
52-
11+
5312 steps :
54- - name : Checkout code
55- uses : actions/checkout@v4
56-
57- - name : Install SSH key
58- uses : shimataro/ssh-key-action@v2
13+ - name : Deploy via SSH
14+ uses : appleboy/ssh-action@master
5915 with :
60- key : ${{ secrets.SSH_PRIVATE_KEY }}
61- known_hosts : ${{ secrets.KNOWN_HOSTS }}
62-
63- - name : Pull latest code
64- run : |
65- ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
66- "cd ${{ env.DEPLOY_PATH }} && git pull origin main"
67-
68- - name : Rebuild and deploy containers
69- run : |
70- ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
71- "cd ${{ env.DEPLOY_PATH }} && \
72- docker compose down && \
73- docker system prune -f && \
74- docker compose up -d --build"
75-
76- - name : Verify deployment
77- run : |
78- ssh -p 22 ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_SERVER }} \
79- "cd ${{ env.DEPLOY_PATH }} && \
80- docker compose ps && \
81- echo '--- Server Logs ---' && \
82- docker compose logs server | head -20"
83-
84- - name : Health check
85- run : |
86- for i in {1..30}; do
87- if curl -f http://${{ env.DEPLOY_SERVER }}:4173 > /dev/null 2>&1; then
88- echo "✅ Application is UP"
89- exit 0
90- fi
91- echo "Checking... ($i/30)"
92- sleep 2
93- done
94- echo "❌ Application failed to start"
95- exit 1
96-
97- - name : Deployment Success Notification
98- if : success()
99- run : |
100- echo "🚀 Deployment successful!"
101- echo "Application: http://${{ env.DEPLOY_SERVER }}:4173"
102-
103- - name : Deployment Failure Notification
104- if : failure()
105- run : |
106- echo "❌ Deployment failed - Check logs above"
107- exit 1
16+ host : ${{ secrets.DEPLOY_HOST }}
17+ username : ${{ secrets.DEPLOY_USER }}
18+ key : ${{ secrets.DEPLOY_SSH_KEY }}
19+ port : 22
20+ script : |
21+ echo "🚀 Starting deployment..."
22+ cd ~/CrackCode-Main/crackcode
23+
24+ echo "📥 Pulling latest code from main..."
25+ git fetch origin main
26+ git reset --hard origin/main
27+
28+ echo "🔨 Rebuilding Docker containers..."
29+ docker compose down
30+ docker compose up -d --build
31+
32+ echo "⏳ Waiting for services to start..."
33+ sleep 60
34+
35+ echo "✅ Verifying deployment..."
36+ docker compose ps
37+
38+ echo "📋 Server logs:"
39+ docker logs crackcode-server-1 | tail -20
40+
41+ echo "🎉 Deployment complete!"
42+ echo "App live at: http://64.227.140.199:4173"
0 commit comments