-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (48 loc) · 1.66 KB
/
deploy.yml
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
name: Deploy to Production
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Copy files to server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
source: "."
target: "/opt/court-allocation"
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
cd /opt/court-allocation
# Pull latest changes and rebuild
docker-compose pull || true
docker-compose build --no-cache
# Bring down existing containers
docker-compose down
# Start new containers
docker-compose up -d
# Clean up
docker image prune -f
# Wait for the application to start
echo "Waiting for application to start..."
sleep 15
# Health check using Host header
response=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: courts.saurabhn.com" http://localhost)
if [ $response -eq 200 ]; then
echo "Application is healthy"
exit 0
else
echo "Health check failed with status: $response"
docker-compose logs
exit 1
fi