-
Notifications
You must be signed in to change notification settings - Fork 1
209 lines (196 loc) · 8.14 KB
/
Copy pathdeploy-gcp.yml
File metadata and controls
209 lines (196 loc) · 8.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Deploy to GCP VM
on:
workflow_dispatch:
inputs:
reason:
description: "Deployment reason (optional)"
required: false
type: string
push:
branches: [main]
paths:
- backend/**
- frontend/**
- orchestrator/**
- stt-service/**
- nmt-service/**
- tts-service/**
- media-service/**
- libs/dablja-worker/**
- libs/dablja-segments/**
- libs/docker-torch/**
- docker-compose.microservices.prod.yml
- docker-compose.microservices.gpu.yml
- docker-compose.gpu.yml
- docker-compose.observability.yml
- infra/terraform/**
- infra/observability/**
- infra/rabbitmq/enabled_plugins
- infra/scripts/deploy-production.sh
- infra/scripts/validate-gpu-deploy.sh
- infra/scripts/lib/**
- infra/terraform/env-production.gpu.snippet
- .env.production.example
- Caddyfile.production
- .github/workflows/deploy-gcp.yml
permissions:
contents: read
concurrency:
group: production-deploy
# Never cancel an in-progress deployment — a cancelled deploy mid-run can
# leave the VM in a partial state (some containers on new images, others not,
# migrations half-applied). Subsequent runs queue instead of clobbering.
cancel-in-progress: false
jobs:
deploy:
name: deploy-gcp
runs-on: ubuntu-latest
timeout-minutes: 120
environment: production
env:
TARGET_BRANCH: main
APP_DIR: ~/web
ENV_FILE: .env.production
BOOTSTRAP_MARKER: /var/lib/vm-bootstrap.done
REQUIRE_BOOTSTRAP_MARKER: "true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure SSH
env:
VM_HOST: ${{ secrets.GCP_VM_HOST }}
VM_USER: ${{ secrets.GCP_VM_USER }}
VM_PORT: ${{ secrets.GCP_VM_PORT }}
VM_SSH_KEY: ${{ secrets.GCP_VM_SSH_KEY }}
run: |
set -euo pipefail
if [ -z "$VM_HOST" ] || [ -z "$VM_USER" ] || [ -z "$VM_SSH_KEY" ]; then
echo "Missing required secrets: GCP_VM_HOST, GCP_VM_USER, GCP_VM_SSH_KEY"
exit 1
fi
VM_PORT="${VM_PORT:-22}"
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s\n' "$VM_SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -p "$VM_PORT" -H "$VM_HOST" >> ~/.ssh/known_hosts
- name: Deploy on VM
env:
VM_HOST: ${{ secrets.GCP_VM_HOST }}
VM_USER: ${{ secrets.GCP_VM_USER }}
VM_PORT: ${{ secrets.GCP_VM_PORT }}
TARGET_BRANCH: ${{ env.TARGET_BRANCH }}
APP_DIR: ${{ env.APP_DIR }}
ENV_FILE: ${{ env.ENV_FILE }}
BOOTSTRAP_MARKER: ${{ env.BOOTSTRAP_MARKER }}
REQUIRE_BOOTSTRAP_MARKER: ${{ env.REQUIRE_BOOTSTRAP_MARKER }}
DEPLOY_SHA: ${{ github.sha }}
DEPLOY_REASON: ${{ github.event.inputs.reason || github.event.head_commit.message || 'push' }}
REPO_SSH_URL: ${{ secrets.GIT_REPO_SSH_URL }}
REPO_FALLBACK: git@github.com:${{ github.repository }}.git
run: |
set -euo pipefail
VM_PORT="${VM_PORT:-22}"
# Pipe git-sync helpers then deploy script — on first boot the repo is not
# on the VM yet, so the runner checkout is the only source for these files.
{
cat infra/scripts/lib/git-sync.sh
cat infra/scripts/deploy-production.sh
} | ssh -p "$VM_PORT" "$VM_USER@$VM_HOST" env \
"TARGET_BRANCH=$(printf '%q' "$TARGET_BRANCH")" \
"APP_DIR=$(printf '%q' "$APP_DIR")" \
"ENV_FILE=$(printf '%q' "$ENV_FILE")" \
"BOOTSTRAP_MARKER=$(printf '%q' "$BOOTSTRAP_MARKER")" \
"REQUIRE_BOOTSTRAP_MARKER=$(printf '%q' "$REQUIRE_BOOTSTRAP_MARKER")" \
"DEPLOY_SHA=$(printf '%q' "$DEPLOY_SHA")" \
"DEPLOY_REASON=$(printf '%q' "$DEPLOY_REASON")" \
"REPO_SSH_URL=$(printf '%q' "$REPO_SSH_URL")" \
"REPO_FALLBACK=$(printf '%q' "$REPO_FALLBACK")" \
bash -s
- name: GPU deploy smoke (optional)
if: success()
env:
VM_HOST: ${{ secrets.GCP_VM_HOST }}
VM_USER: ${{ secrets.GCP_VM_USER }}
VM_PORT: ${{ secrets.GCP_VM_PORT }}
GCP_GPU_ENABLED: ${{ secrets.GCP_GPU_ENABLED }}
run: |
set -euo pipefail
if [ "${GCP_GPU_ENABLED:-}" != "true" ]; then
echo "Skipping GPU smoke (set repository secret GCP_GPU_ENABLED=true to enable)"
exit 0
fi
VM_PORT="${VM_PORT:-22}"
GPU_SMOKE_LOG="$(mktemp)"
ssh -p "$VM_PORT" "$VM_USER@$VM_HOST" bash -se <<'REMOTE_EOF' | tee "$GPU_SMOKE_LOG"
set -euo pipefail
cd "$HOME/web"
bash infra/scripts/validate-gpu-deploy.sh || true
REMOTE_EOF
{
echo "### GPU smoke (optional)"
echo ""
if grep -q 'GPU validation passed' "$GPU_SMOKE_LOG"; then
echo "- Status: passed"
elif grep -q 'GPU validation completed with warnings' "$GPU_SMOKE_LOG"; then
echo "- Status: warnings (deploy not failed — lenient policy)"
else
echo "- Status: incomplete or skipped"
fi
if grep -q 'COMPOSE_ENABLE_GPU is not true' "$GPU_SMOKE_LOG"; then
echo "- Warning: \`COMPOSE_ENABLE_GPU\` is not true in VM \`.env.production\`"
fi
if grep -q 'STT service reports CPU device' "$GPU_SMOKE_LOG"; then
echo "- Warning: STT service is on CPU"
fi
if grep -q 'TTS service reports torch.cuda.is_available()=False' "$GPU_SMOKE_LOG"; then
echo "- Warning: TTS service does not see CUDA"
fi
echo ""
echo "<details><summary>Full GPU smoke log</summary>"
echo ""
echo '```'
cat "$GPU_SMOKE_LOG"
echo '```'
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
rm -f "$GPU_SMOKE_LOG"
- name: Deployment summary
if: always()
env:
DEPLOY_STATUS: ${{ job.status }}
VM_HOST: ${{ secrets.GCP_VM_HOST }}
VM_USER: ${{ secrets.GCP_VM_USER }}
VM_PORT: ${{ secrets.GCP_VM_PORT }}
run: |
GPU_OVERLAY_STATUS="unknown"
if [ -n "${VM_HOST:-}" ] && [ -n "${VM_USER:-}" ]; then
VM_PORT="${VM_PORT:-22}"
GPU_OVERLAY_STATUS="$(ssh -p "$VM_PORT" -o ConnectTimeout=10 "$VM_USER@$VM_HOST" \
"grep -E '^COMPOSE_ENABLE_GPU=' \"\$HOME/web/.env.production\" 2>/dev/null | tail -1 || echo 'COMPOSE_ENABLE_GPU not set'" \
2>/dev/null || echo 'unavailable (SSH failed)')"
fi
{
if [ "$DEPLOY_STATUS" = "success" ]; then
echo "## ✅ Production Deployment Succeeded"
else
echo "## ❌ Production Deployment Failed"
fi
echo ""
echo "| Field | Value |"
echo "|-------|-------|"
echo "| Workflow | deploy-gcp |"
echo "| Trigger | ${{ github.event_name }} |"
echo "| Repository SHA | \`${{ github.sha }}\` |"
echo "| Target branch | \`${{ env.TARGET_BRANCH }}\` |"
echo "| Target VM path | \`${{ env.APP_DIR }}\` |"
echo "| Compose file | \`docker-compose.microservices.prod.yml\` + optional GPU (\`COMPOSE_ENABLE_GPU\`) / observability (\`COMPOSE_PROFILES=observability\`) overlays |"
echo "| GPU overlay (VM env) | \`${GPU_OVERLAY_STATUS}\` |"
echo "| GPU smoke | optional — set repo secret \`GCP_GPU_ENABLED=true\` (warn-only; does not fail deploy) |"
echo "| Deploy script | \`infra/scripts/deploy-production.sh\` |"
echo "| Deploy log on VM | \`${{ env.APP_DIR }}/deploy.log\` |"
echo "| Grafana (when enabled) | \`https://grafana.\$DOMAIN\` — see VM \`.env.production\` |"
echo ""
echo "> Timing breakdown (frontend_build / compose_up / health_gates) is emitted"
echo "> to the VM deploy log: \`tail -20 ~/web/deploy.log\`"
} >> "$GITHUB_STEP_SUMMARY"