Repository navigation
Expand file tree
/
Copy pathcloudbuild-webapp.yaml
More file actions
101 lines (101 loc) · 3.47 KB
/
Copy pathcloudbuild-webapp.yaml
File metadata and controls
101 lines (101 loc) · 3.47 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
# Cloud Build config for webapp. Reused by per-environment triggers (dev, qa, staging, prod).
# Each trigger sets _REGION, _ENVIRONMENT, and _SERVICE (Cloud Run service name).
# Alembic: runs ${_ENVIRONMENT}-api-migrate before deploy only when _SKIP_API_MIGRATE=false.
# Default skip is anything other than "false" so QA/unstamped envs are safe. Set
# _SKIP_API_MIGRATE=false only on stamped env triggers (e.g. edvise-api-web-dev after
# alembic stamp), and only when that trigger's _ENVIRONMENT matches the intended DB/job
# (QA must not reuse _ENVIRONMENT=dev while skip is false). See docs/ALEMBIC_CUTOVER.md.
substitutions:
_REGION: us-east4
_SERVICE: edvise-api
_ENVIRONMENT: dev
_SKIP_API_MIGRATE: "true"
steps:
- name: ghcr.io/astral-sh/uv:debian
id: upgrade-edvise-lock
entrypoint: bash
args:
- -c
- |
set -e
apt-get update && apt-get install -y --no-install-recommends git
uv lock --upgrade-package edvise
- name: gcr.io/cloud-builders/docker
id: build-webapp
waitFor: ["upgrade-edvise-lock"]
args:
- build
- "-f"
- src/webapp/Dockerfile
- "-t"
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:$COMMIT_SHA"
- "-t"
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:latest"
- .
- name: gcr.io/cloud-builders/docker
id: push-webapp-sha
waitFor: ["build-webapp"]
args:
- push
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:$COMMIT_SHA"
- name: gcr.io/cloud-builders/docker
id: push-webapp-latest
waitFor: ["build-webapp"]
args:
- push
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:latest"
- name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
id: RUN api-migrate job
waitFor: ["push-webapp-sha"]
entrypoint: bash
args:
- -c
- |
set -e
# Fail-closed toward skip: only run migrate when explicitly "false".
if [ "${_SKIP_API_MIGRATE}" != "false" ]; then
echo "Skipping api-migrate (_SKIP_API_MIGRATE=${_SKIP_API_MIGRATE})"
exit 0
fi
IMAGE="${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:$COMMIT_SHA"
JOB="${_ENVIRONMENT}-api-migrate"
echo "Updating and executing Cloud Run job $${JOB} with $${IMAGE}"
# Prefer update+execute so a missing job fails closed (deploy would create a
# minimal job whose CMD is FastAPI, not alembic).
gcloud run jobs update "$${JOB}" \
--project="${PROJECT_ID}" \
--image="$${IMAGE}" \
--region="${_REGION}"
gcloud run jobs execute "$${JOB}" \
--project="${PROJECT_ID}" \
--region="${_REGION}" \
--wait
- name: gcr.io/cloud-builders/gcloud
id: deploy-webapp
waitFor: ["RUN api-migrate job"]
args:
- run
- deploy
- "${_SERVICE}"
- "--image"
- "${_REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO_NAME}/webapp:$COMMIT_SHA"
- "--region"
- "${_REGION}"
- name: curlimages/curl
id: notify-slack
waitFor: ["deploy-webapp"]
args:
- "-X"
- POST
- "-H"
- "Content-Type: application/json"
- "-f"
- "-d"
- >-
{"text":"🚀 $TRIGGER_NAME → *$REPO_NAME* deployed · `$BRANCH_NAME`"}
- >-
https://hooks.slack.com/triggers/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
timeout: 600s
options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true