-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
158 lines (143 loc) · 4.01 KB
/
Copy pathcloudbuild.yaml
File metadata and controls
158 lines (143 loc) · 4.01 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
steps:
# Install dependencies (required before any tsx-dependent scripts)
- 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"]
# Check Documentation Alignment
- name: "node:24"
id: "docs-alignment"
entrypoint: npm
args: ["run", "check:docs"]
# Build the container image
- name: "gcr.io/cloud-builders/docker:24.0.5"
args: ["build", "-t", "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA", "."]
# Push the container image to Container Registry
- name: "gcr.io/cloud-builders/docker:24.0.5"
id: "push-image"
args: ["push", "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"]
# Run Drizzle migrations before deploying
- name: "node:24"
id: "db-migrate"
entrypoint: npm
args: ["run", "migrate:deploy"]
secretEnv: ["DATABASE_URL"]
# Upload static assets to GCS for CDN
- name: "gcr.io/cloud-builders/gsutil:92"
args: ["-m", "rsync", "-r", "-c", "dist/public", "gs://$PROJECT_ID-assets"]
# Deploy canary revision (no traffic initially)
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:450.0.0"
id: "deploy-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"
# Health check on canary
- name: "gcr.io/cloud-builders/curl:7.87.0"
id: "health-check"
entrypoint: bash
args:
- "-c"
- |
CANARY_URL=$(gcloud run services describe run-remix --region=us-central1 --format='value(status.traffic[0].url)' 2>/dev/null || echo "")
if [ -z "$CANARY_URL" ]; then
echo "Could not get canary URL, proceeding..."
exit 0
fi
echo "Health checking 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 "Health check passed!"
exit 0
fi
echo "Attempt $i failed, retrying..."
sleep 5
done
echo "Health check failed after 5 attempts"
exit 1
# Shift 10% traffic to canary
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:450.0.0"
id: "traffic-10"
entrypoint: gcloud
args:
- "run"
- "services"
- "update-traffic"
- "run-remix"
- "--region"
- "us-central1"
- "--to-tags"
- "canary=10"
# Wait and verify (30 seconds)
- name: "gcr.io/cloud-builders/curl:7.87.0"
id: "verify-10"
entrypoint: bash
args:
- "-c"
- "echo 'Monitoring canary at 10%...' && sleep 30"
# Shift 50% traffic to canary
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:450.0.0"
id: "traffic-50"
entrypoint: gcloud
args:
- "run"
- "services"
- "update-traffic"
- "run-remix"
- "--region"
- "us-central1"
- "--to-tags"
- "canary=50"
# Wait and verify (30 seconds)
- name: "gcr.io/cloud-builders/curl:7.87.0"
id: "verify-50"
entrypoint: bash
args:
- "-c"
- "echo 'Monitoring canary at 50%...' && sleep 30"
# Full rollout - migrate all traffic to new revision
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:450.0.0"
id: "full-rollout"
entrypoint: gcloud
args:
- "run"
- "services"
- "update-traffic"
- "run-remix"
- "--region"
- "us-central1"
- "--to-latest"
images:
- "gcr.io/$PROJECT_ID/run-remix:$SHORT_SHA"
options:
logging: CLOUD_LOGGING_ONLY
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/DATABASE_URL/versions/latest
env: 'DATABASE_URL'