Repository navigation
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
137 lines (128 loc) · 5.45 KB
/
Copy pathcloudbuild.yaml
File metadata and controls
137 lines (128 loc) · 5.45 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
# Release hackbot-ui: build it and deploy it to one environment.
#
# Two triggers (webservices-infra, hackbot/tf/modules/resources/build.tf) run
# this, telling it which environment in _ENV:
# stage-hackbot-ui a push to the default branch touching
# services/hackbot-ui/VERSION. Deploys only
# if its version isn't the one stage runs; run by hand, it
# deploys regardless.
# dev-hackbot-ui a push to dev/services/hackbot-ui or
# dev/services/hackbot-ui/<anything>. Deploys to dev,
# always.
# Prod is a separate, approved promotion; nothing here reaches it.
# services/cloudbuild.yaml is hackbot-dev's older config and goes away at
# cutover.
#
# `release-plan` decides whether to release and `release` deploys it. The
# Sentry release is hackbot-ui@<version> (dev builds add +<commit>), with the
# commits since what the environment ran before, and a deploy in its
# environment; prod's deploy is marked by the prod workflow.
#
# The Console bakes its Sentry DSN and release into the bundle at build time
# (_SENTRY_DSN) and uploads its source maps then, which needs the Sentry token
# as a build secret. It picks its Sentry environment at runtime from its
# hostname, so one image serves every environment.
#
# Cloud Build reads every `$NAME` as a substitution, and MUST_MATCH fails the
# build on unknown ones, so shell variables below are written `$$name`.
steps:
# Builds of one trigger deploy to one environment: take turns. The wait
# allows for an older build's own work; the timeout is that plus this one's.
- id: Wait
name: ghcr.io/astral-sh/uv:python3.14-bookworm-slim
entrypoint: bash
args:
- -c
- uv run --frozen --package hackbot-deploy python -m hackbot_deploy wait-turn "$BUILD_ID" --project "$PROJECT_ID" --location "$LOCATION" --timeout 3600
# /workspace/plan.txt: "name version previous-commit - -", or empty when
# there is nothing to release (every step below then does nothing).
- id: Plan
name: ghcr.io/astral-sh/uv:python3.14-bookworm-slim
entrypoint: bash
# The tool reads these from the environment: in a command, a run by hand's
# unresolved pusher ("$(push.pusher.name)") would run as a command.
env:
- BRANCH_NAME=$BRANCH_NAME
- PUSHER=${_PUSHER}
args:
- -c
- uv run --frozen --package hackbot-deploy python -m hackbot_deploy release-plan services/hackbot-ui --env "${_ENV}" --output /workspace/plan.txt
- id: Build
name: gcr.io/cloud-builders/docker
entrypoint: bash
env:
- DOCKER_BUILDKIT=1
secretEnv:
- SENTRY_AUTH_TOKEN
args:
- -c
- |
set -euo pipefail
read -r _ version _ < /workspace/plan.txt || exit 0
release="hackbot-ui@$$version"
sha="$COMMIT_SHA"
if [ "${_ENV}" = dev ]; then release="$$release+$${sha:0:12}"; fi
image="${_AR_HOSTNAME}/${_AR_PROJECT_ID}/${_AR_REPOSITORY}/hackbot-ui:$COMMIT_SHA"
docker build --no-cache -f services/hackbot-ui/Dockerfile \
--secret id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \
--build-arg "SENTRY_DSN=${_SENTRY_DSN}" \
--build-arg "SENTRY_RELEASE=$$release" \
--label "org.opencontainers.image.version=$$version" \
--label "org.opencontainers.image.revision=$COMMIT_SHA" \
--label "org.opencontainers.image.created=$$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-t "$$image" .
docker push "$$image"
docker inspect --format='{{index .RepoDigests 0}}' "$$image" > /workspace/hackbot-ui.digest
# Services have no shape gate: their infrastructure is written by hand in
# webservices-infra and changes there first.
- id: Deploy
name: ghcr.io/astral-sh/uv:python3.14-bookworm-slim
entrypoint: bash
# Recorded as deployed_by: whoever pushed, or the build when the trigger
# is run by hand. Substitutions aren't in a step's environment otherwise.
env:
- GITHUB_ACTOR=${_PUSHER}
- BUILD_ID=$BUILD_ID
args:
- -c
- uv run --frozen --package hackbot-deploy python -m hackbot_deploy release --env "${_ENV}" --plan /workspace/plan.txt --digests /workspace
# After the deploy, so a Sentry outage can't hold one up.
- id: Sentry
name: getsentry/sentry-cli
entrypoint: sh
secretEnv:
- SENTRY_AUTH_TOKEN
args:
- -c
- |
set -eu
read -r _ version previous _ < /workspace/plan.txt || exit 0
release="hackbot-ui@$$version"
environment=staging
sha="$COMMIT_SHA"
if [ "${_ENV}" = dev ]; then
release="$$release+$$(echo "$$sha" | cut -c1-12)"
environment=development
fi
commits="mozilla/ai-dev@$COMMIT_SHA"
if [ "$$previous" != - ]; then commits="mozilla/ai-dev@$$previous..$COMMIT_SHA"; fi
sentry-cli releases new "$$release"
sentry-cli releases set-commits "$$release" --commit "$$commits"
sentry-cli releases finalize "$$release"
sentry-cli deploys new --release "$$release" -e "$$environment"
# _ENV is set by each trigger; _PUSHER from the push event, empty when run
# any other way.
substitutions:
_ENV: stage
_PUSHER: ""
timeout: 5400s
options:
substitutionOption: MUST_MATCH
logging: CLOUD_LOGGING_ONLY
env:
- SENTRY_ORG=mozilla
- SENTRY_PROJECT=hackbot-ui
availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/${_SENTRY_AUTH_TOKEN_SECRET}/versions/latest
env: SENTRY_AUTH_TOKEN