-
Notifications
You must be signed in to change notification settings - Fork 1
119 lines (93 loc) · 3.14 KB
/
deploy-staging.yml
File metadata and controls
119 lines (93 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Deploy to Staging
on:
push:
branches:
- main
workflow_dispatch: # Allow manual deployment
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
NODE_VERSION: "20.6.0"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
cache-dependency-path: |
server/package-lock.json
client/package-lock.json
- name: Install server dependencies
run: |
cd server
npm ci
- name: Install client dependencies
run: |
cd client
npm ci
- name: Validate build (optional)
run: |
cd client
npm run build:staging
echo "✅ Client build validation completed"
- name: Deploy to Lightsail instance
run: |
# Install SSH key
mkdir -p ~/.ssh
echo "${{ secrets.LIGHTSAIL_SSH_KEY }}" > ~/.ssh/lightsail_key
chmod 600 ~/.ssh/lightsail_key
# Deploy using git pull and rebuild
ssh -i ~/.ssh/lightsail_key -o StrictHostKeyChecking=no \
bitnami@${{ vars.LIGHTSAIL_HOST }} << 'ENDSSH'
set -e # Exit on any error
echo "🚀 Starting deployment..."
cd ~/bolt-gameserver-sample
echo "🔄 Fetching latest code..."
git fetch origin
git reset --hard origin/${{ github.ref_name }}
# Install server dependencies
echo "📦 Installing server dependencies..."
cd server
npm ci
# Build client
echo "🏗️ Building client..."
cd ../client
npm ci
npm run build:staging
echo "▶️ Starting client..."
sudo /opt/bitnami/ctlscript.sh restart nginx
echo "▶️ Starting nodejs service..."
sudo systemctl restart nodejs.service
echo "✅ Service start command executed"
echo "🎉 Deployment completed successfully!"
ENDSSH
- name: Health check
run: |
echo "Performing health checks..."
# Wait for service to be ready
sleep 15
# Check health endpoint
ENDPOINT="${{ vars.HOST_STAGING }}/api/health"
echo "Checking $ENDPOINT..."
if curl -f -s --max-time 10 "$ENDPOINT" > /dev/null; then
echo "✅ Health check passed for $ENDPOINT"
SUCCESS=true
else
echo "❌ Health check failed for $ENDPOINT"
SUCCESS=false
fi
if [ "$SUCCESS" = false ]; then
echo "❌ Health check failed"
exit 1
fi
- name: Notify deployment status
if: always()
run: |
if [ ${{ job.status }} == 'success' ]; then
echo "✅ Staging deployment successful!"
else
echo "❌ Staging deployment failed!"
fi