-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild-multiregion.yaml
More file actions
220 lines (198 loc) · 6.42 KB
/
Copy pathcloudbuild-multiregion.yaml
File metadata and controls
220 lines (198 loc) · 6.42 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
210
211
212
213
214
215
216
217
218
219
220
# Multi-Region Cloud Build Configuration
# Phase 4: Multi-Region & Performance
#
# Deploys to us-central1 and europe-west1 with Global HTTPS Load Balancer
steps:
# Install dependencies
- name: "node:24"
id: "install"
entrypoint: npm
args: ["ci"]
# Verify Technical Integrity
- name: "node:24"
id: "tech-integrity"
entrypoint: npm
args: ["run", "verify:tech-integrity"]
# Build the container image
- name: "gcr.io/cloud-builders/docker"
id: "build"
args: ["build", "-t", "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA", "."]
# Push the container image to Container Registry
- name: "gcr.io/cloud-builders/docker"
id: "push"
args: ["push", "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"]
# Upload static assets to GCS for CDN
- name: "gcr.io/cloud-builders/gsutil"
id: "upload-assets"
args: ["-m", "rsync", "-r", "-c", "dist/public", "gs://$PROJECT_ID-assets"]
# ===========================================
# REGION 1: US-CENTRAL1 (Primary)
# ===========================================
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "deploy-us-canary"
entrypoint: gcloud
args:
- "run"
- "deploy"
- "run-remix"
- "--image"
- "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"
- "--region"
- "us-central1"
- "--platform"
- "managed"
- "--allow-unauthenticated"
- "--tag"
- "canary"
- "--no-traffic"
- "--min-instances"
- "1"
- "--max-instances"
- "10"
- "--memory"
- "1Gi"
- "--cpu"
- "1"
- "--set-env-vars"
- "NODE_ENV=production,REGION=us-central1"
# Health check US region
- name: "gcr.io/cloud-builders/curl"
id: "health-check-us"
entrypoint: bash
args:
- "-c"
- |
CANARY_URL=$(gcloud run services describe run-remix --region=us-central1 --format='value(status.url)' 2>/dev/null || echo "")
if [ -z "$CANARY_URL" ]; then
echo "Could not get US canary URL, proceeding..."
exit 0
fi
echo "Health checking US canary at: $CANARY_URL/api/health"
for i in 1 2 3 4 5; do
if curl -sf "$CANARY_URL/api/health" > /dev/null; then
echo "US health check passed!"
exit 0
fi
echo "Attempt $i failed, retrying..."
sleep 5
done
echo "US health check failed after 5 attempts"
exit 1
# ===========================================
# REGION 2: EUROPE-WEST1 (Secondary)
# ===========================================
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "deploy-eu-canary"
entrypoint: gcloud
args:
- "run"
- "deploy"
- "run-remix"
- "--image"
- "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"
- "--region"
- "europe-west1"
- "--platform"
- "managed"
- "--allow-unauthenticated"
- "--tag"
- "canary"
- "--no-traffic"
- "--min-instances"
- "1"
- "--max-instances"
- "10"
- "--memory"
- "1Gi"
- "--cpu"
- "1"
- "--set-env-vars"
- "NODE_ENV=production,REGION=europe-west1"
# Health check EU region
- name: "gcr.io/cloud-builders/curl"
id: "health-check-eu"
entrypoint: bash
args:
- "-c"
- |
CANARY_URL=$(gcloud run services describe run-remix --region=europe-west1 --format='value(status.url)' 2>/dev/null || echo "")
if [ -z "$CANARY_URL" ]; then
echo "Could not get EU canary URL, proceeding..."
exit 0
fi
echo "Health checking EU canary at: $CANARY_URL/api/health"
for i in 1 2 3 4 5; do
if curl -sf "$CANARY_URL/api/health" > /dev/null; then
echo "EU health check passed!"
exit 0
fi
echo "Attempt $i failed, retrying..."
sleep 5
done
echo "EU health check failed after 5 attempts"
exit 1
# ===========================================
# PROGRESSIVE ROLLOUT (Both Regions)
# ===========================================
# Shift 10% traffic to canary (both regions)
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "traffic-10"
entrypoint: bash
args:
- "-c"
- |
gcloud run services update-traffic run-remix --region=us-central1 --to-tags=canary=10
gcloud run services update-traffic run-remix --region=europe-west1 --to-tags=canary=10
echo "Shifted 10% traffic to canary in both regions"
# Wait and verify (30 seconds)
- name: "gcr.io/cloud-builders/curl"
id: "verify-10"
entrypoint: bash
args:
- "-c"
- "echo 'Monitoring canary at 10% in both regions...' && sleep 30"
# Shift 50% traffic to canary (both regions)
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "traffic-50"
entrypoint: bash
args:
- "-c"
- |
gcloud run services update-traffic run-remix --region=us-central1 --to-tags=canary=50
gcloud run services update-traffic run-remix --region=europe-west1 --to-tags=canary=50
echo "Shifted 50% traffic to canary in both regions"
# Wait and verify (30 seconds)
- name: "gcr.io/cloud-builders/curl"
id: "verify-50"
entrypoint: bash
args:
- "-c"
- "echo 'Monitoring canary at 50% in both regions...' && sleep 30"
# Full rollout - migrate all traffic to new revision (both regions)
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "full-rollout"
entrypoint: bash
args:
- "-c"
- |
gcloud run services update-traffic run-remix --region=us-central1 --to-latest
gcloud run services update-traffic run-remix --region=europe-west1 --to-latest
echo "Full rollout complete in both regions"
# ===========================================
# GLOBAL LOAD BALANCER UPDATE
# ===========================================
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "update-neg"
entrypoint: bash
args:
- "-c"
- |
echo "Verifying NEG (Network Endpoint Groups) are healthy..."
gcloud compute network-endpoint-groups list --filter="name~run-remix" || echo "NEGs configured via Terraform/Console"
echo "Global Load Balancer will automatically route to healthy regions"
images:
- "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"
options:
logging: CLOUD_LOGGING_ONLY
machineType: "E2_HIGHCPU_8"
timeout: "1800s" # 30 minutes for multi-region deployment