-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
188 lines (168 loc) · 6.46 KB
/
Copy pathcloudbuild.yaml
File metadata and controls
188 lines (168 loc) · 6.46 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
# =============================================================================
# Cloud Build CI/CD Pipeline — cloudbuild.yaml
# =============================================================================
# Triggered on push to main branch (configure in Cloud Build UI or via trigger TF resource).
#
# Pipeline stages:
# 1. Run unit tests for all 3 services
# 2a. Build inventory Docker image
# 2b. Build order Docker image
# 2c. Build fulfillment Docker image
# 3a. Push inventory image to Artifact Registry
# 3b. Push order image to Artifact Registry
# 3c. Push fulfillment image to Artifact Registry
# 4a. Deploy inventory to Cloud Run
# 4b. Deploy order to Cloud Run
# 4c. Deploy fulfillment to Cloud Run
#
# Substitutions (set in trigger config):
# _REGION — GCP region (default: me-central1)
# _REGISTRY_URL — Artifact Registry URL
# _ENVIRONMENT — Deployment environment (default: prod)
# =============================================================================
substitutions:
_REGION: "me-central1"
_REGISTRY_URL: "${_REGION}-docker.pkg.dev/${PROJECT_ID}/scf-services"
_ENVIRONMENT: "prod"
options:
machineType: "E2_HIGHCPU_8"
logging: CLOUD_LOGGING_ONLY
dynamic_substitutions: true
steps:
# ── Stage 1: Tests ─────────────────────────────────────────────────────────
- id: "test-inventory"
name: "python:3.11-slim"
dir: "supplychainforge"
entrypoint: "bash"
args:
- "-c"
- |
pip install --quiet -r services/inventory/requirements.txt -r services/inventory/requirements-dev.txt
export PYTHONPATH=/workspace/supplychainforge:/workspace/supplychainforge/shared/..
python -m pytest services/inventory/tests -q --tb=short
waitFor: ["-"] # run immediately
- id: "test-order"
name: "python:3.11-slim"
dir: "supplychainforge"
entrypoint: "bash"
args:
- "-c"
- |
pip install --quiet -r services/order/requirements.txt -r services/order/requirements-dev.txt
export PYTHONPATH=/workspace/supplychainforge:/workspace/supplychainforge/shared/..
python -m pytest services/order/tests -q --tb=short
waitFor: ["-"]
- id: "test-fulfillment"
name: "python:3.11-slim"
dir: "supplychainforge"
entrypoint: "bash"
args:
- "-c"
- |
pip install --quiet -r services/fulfillment/requirements.txt -r services/fulfillment/requirements-dev.txt
export PYTHONPATH=/workspace/supplychainforge:/workspace/supplychainforge/shared/..
python -m pytest services/fulfillment/tests -q --tb=short
waitFor: ["-"]
# ── Stage 2: Build images ──────────────────────────────────────────────────
- id: "build-inventory"
name: "gcr.io/cloud-builders/docker"
dir: "supplychainforge"
args:
- "build"
- "--platform", "linux/amd64"
- "--target", "runtime"
- "--tag", "${_REGISTRY_URL}/inventory:${SHORT_SHA}"
- "--tag", "${_REGISTRY_URL}/inventory:latest"
- "--cache-from", "${_REGISTRY_URL}/inventory:latest"
- "--build-arg", "BUILDKIT_INLINE_CACHE=1"
- "-f", "services/inventory/Dockerfile"
- "."
waitFor: ["test-inventory"]
- id: "build-order"
name: "gcr.io/cloud-builders/docker"
dir: "supplychainforge"
args:
- "build"
- "--platform", "linux/amd64"
- "--target", "runtime"
- "--tag", "${_REGISTRY_URL}/order:${SHORT_SHA}"
- "--tag", "${_REGISTRY_URL}/order:latest"
- "--cache-from", "${_REGISTRY_URL}/order:latest"
- "--build-arg", "BUILDKIT_INLINE_CACHE=1"
- "-f", "services/order/Dockerfile"
- "."
waitFor: ["test-order"]
- id: "build-fulfillment"
name: "gcr.io/cloud-builders/docker"
dir: "supplychainforge"
args:
- "build"
- "--platform", "linux/amd64"
- "--target", "runtime"
- "--tag", "${_REGISTRY_URL}/fulfillment:${SHORT_SHA}"
- "--tag", "${_REGISTRY_URL}/fulfillment:latest"
- "--cache-from", "${_REGISTRY_URL}/fulfillment:latest"
- "--build-arg", "BUILDKIT_INLINE_CACHE=1"
- "-f", "services/fulfillment/Dockerfile"
- "."
waitFor: ["test-fulfillment"]
# ── Stage 3: Push images ───────────────────────────────────────────────────
- id: "push-inventory"
name: "gcr.io/cloud-builders/docker"
args: ["push", "--all-tags", "${_REGISTRY_URL}/inventory"]
waitFor: ["build-inventory"]
- id: "push-order"
name: "gcr.io/cloud-builders/docker"
args: ["push", "--all-tags", "${_REGISTRY_URL}/order"]
waitFor: ["build-order"]
- id: "push-fulfillment"
name: "gcr.io/cloud-builders/docker"
args: ["push", "--all-tags", "${_REGISTRY_URL}/fulfillment"]
waitFor: ["build-fulfillment"]
# ── Stage 4: Deploy to Cloud Run ──────────────────────────────────────────
- id: "deploy-inventory"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: "gcloud"
args:
- "run"
- "services"
- "update"
- "scf-inventory"
- "--image=${_REGISTRY_URL}/inventory:${SHORT_SHA}"
- "--region=${_REGION}"
- "--platform=managed"
- "--quiet"
waitFor: ["push-inventory"]
- id: "deploy-order"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: "gcloud"
args:
- "run"
- "services"
- "update"
- "scf-order"
- "--image=${_REGISTRY_URL}/order:${SHORT_SHA}"
- "--region=${_REGION}"
- "--platform=managed"
- "--quiet"
waitFor: ["push-order", "deploy-inventory"]
- id: "deploy-fulfillment"
name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: "gcloud"
args:
- "run"
- "services"
- "update"
- "scf-fulfillment"
- "--image=${_REGISTRY_URL}/fulfillment:${SHORT_SHA}"
- "--region=${_REGION}"
- "--platform=managed"
- "--quiet"
waitFor: ["push-fulfillment", "deploy-order"]
images:
- "${_REGISTRY_URL}/inventory:${SHORT_SHA}"
- "${_REGISTRY_URL}/inventory:latest"
- "${_REGISTRY_URL}/order:${SHORT_SHA}"
- "${_REGISTRY_URL}/order:latest"
- "${_REGISTRY_URL}/fulfillment:${SHORT_SHA}"
- "${_REGISTRY_URL}/fulfillment:latest"