-
Notifications
You must be signed in to change notification settings - Fork 7
119 lines (104 loc) · 4.27 KB
/
deploy-prod.yml
File metadata and controls
119 lines (104 loc) · 4.27 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 Prod
on:
workflow_dispatch:
jobs:
deploy-prod:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version-file: go.mod
cache-key-suffix: deploy-prod
- name: Get go binaries path
id: go-bin-path
run: echo "PATH=$(go env GOPATH)/bin" >> "$GITHUB_OUTPUT"
- name: Cache atlas
id: cache
uses: actions/cache@v4
with:
path: ${{ steps.go-bin-path.outputs.PATH }}
key: ${{ runner.os }}-atlas-bin5-v1.1.0
- name: Install atlas
if: steps.cache.outputs.cache-hit != 'true'
run: make install-atlas
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d-%s')"
- name: Enable maintenance mode
uses: appleboy/ssh-action@v1
with:
host: 62.210.92.144
username: root
key: ${{ secrets.PROD_SSH_KEY }}
script: |
set -xe
cd zenao
git fetch
git checkout ${{ github.sha }}
yq -iy 'del(.services.backend.command)' prod.backend.docker-compose.yml
yq -iy '.services.backend |= ({"command": "--maintenance"} + .)' prod.backend.docker-compose.yml
docker compose -f prod.backend.docker-compose.yml up -d backend
- name: Backup DB
shell: bash
run: |
RESPONSE=$(curl -s -f -X POST \
-H "Authorization: Bearer ${{ secrets.TURSO_API_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"name": "zenao-prod-backup-${{ steps.date.outputs.date }}", "group": "zenao", "seed": {"type": "database", "name": "zenao-prod"} }' \
"https://api.turso.tech/v1/organizations/samourai-coop/databases")
if [ $? -ne 0 ]; then
echo "API call failed"
exit 1
fi
- name: Migrate DB
id: migrate
run: TURSO_TOKEN=${{ secrets.PROD_TURSO_TOKEN }} atlas migrate apply --dir "file://migrations" --env prod
- name: Rollback maintenance on migration failure
if: failure() && steps.migrate.outcome == 'failure'
uses: appleboy/ssh-action@v1
with:
host: 62.210.92.144
username: root
key: ${{ secrets.PROD_SSH_KEY }}
script: |
set -xe
cd zenao
git restore prod.backend.docker-compose.yml
docker compose -f prod.backend.docker-compose.yml up -d --build backend
- name: Upgrade backend
uses: appleboy/ssh-action@v1
with:
host: 62.210.92.144
username: root
key: ${{ secrets.PROD_SSH_KEY }}
# git restore is there to disable maintenance mode
script: |
set -xe
cd zenao
# Inject Stripe env vars into backend.env (idempotent)
grep -q '^ZENAO_STRIPE_SECRET_KEY=' backend.env 2>/dev/null && \
sed -i 's|^ZENAO_STRIPE_SECRET_KEY=.*|ZENAO_STRIPE_SECRET_KEY=${{ secrets.STRIPE_LIVE_SECRET_KEY }}|' backend.env || \
echo 'ZENAO_STRIPE_SECRET_KEY=${{ secrets.STRIPE_LIVE_SECRET_KEY }}' >> backend.env
grep -q '^ZENAO_PAID_EVENTS_ENABLED=' backend.env 2>/dev/null && \
sed -i 's|^ZENAO_PAID_EVENTS_ENABLED=.*|ZENAO_PAID_EVENTS_ENABLED=true|' backend.env || \
echo 'ZENAO_PAID_EVENTS_ENABLED=true' >> backend.env
docker compose -f prod.backend.docker-compose.yml up -d --wait otel-collector jaeger
git restore prod.backend.docker-compose.yml
docker compose -f prod.backend.docker-compose.yml up -d --build backend
- name: Post-deploy smoke test
run: |
echo "⏳ Waiting 60s for services to stabilize..."
sleep 60
for i in 1 2 3 4 5; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 15 https://zenao.io/)
if [ "$STATUS" = "200" ]; then
echo "✅ Smoke test passed (HTTP $STATUS)"
exit 0
fi
echo "⏳ Attempt $i/5: HTTP $STATUS — retrying in 30s..."
sleep 30
done
echo "❌ Smoke test FAILED after 5 attempts"
exit 1