Repository navigation
296 lines (285 loc) · 12.1 KB
/
Copy pathdeploy.yaml
File metadata and controls
296 lines (285 loc) · 12.1 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Deploys lambda code and the agent image from an uploaded working tree: a version of source.zip, the
# dirs its deploy-dirs.txt names, to one gerp, a list or every active gerp — one job per gerp at once.
# From a session: `bash scripts/workflow.sh run deploy.yaml --dirs <src-dir>… [-f gerp=…] [-f image=build]`,
# which zips and uploads the tree, dispatches on that version and waits on the run. Every job runs the
# tree's own scripts.
#
# gerps the gerp list and the source's dirs, for the jobs after it
# bff the BFF, once: it lives in the operator account, and a push per gerp would race
# lambdas one job over the fleet: fleet.py push the dirs once, then the fleet pipe (scripts/fleet.py, the same
# pipe `deploy.sh fleet` runs on a laptop), ten gerps at a time through GNU parallel
# playbooks playbooks.yaml, the same gerps, after the pushes — with -f playbooks=true
# integ the deployed modules' integ tests, once the pushes are done
# build the agent image, on an arm64 runner (native, no emulation): docker.sh --build, upload.sh image
# runtimes one job per gerp: its runtime onto the tag build pushed (or the top of ECR, image: no-build)
#
# The fleet's lambdas are one job: the pipe moves every gerp's functions in about a minute. The fan-out is per
# gerp only where a runtime waits minutes for READY. Runners cost nothing on this public repo; a job's price is its
# minute of setup.
name: deploy
on:
workflow_dispatch:
inputs:
gerp:
description: a gerp id, a comma list, or all (every active gerp)
required: true
default: gradienterp
image:
description: the agent image — none, build (build, push the next tag, move the runtimes) or no-build (move the runtimes onto the top of ECR)
required: false
type: choice
default: none
options: [none, build, no-build]
playbooks:
description: after the pushes, ingest the playbooks (every modules/**/kb.md) into each gerp's knowledge base
type: boolean
default: false
source_version:
description: a version of source.zip (empty is its latest)
required: false
default: ""
permissions:
contents: read
id-token: write
# one deploy per gerp input at a time, and a second one waits rather than cancelling the first
concurrency:
group: deploy-${{ inputs.gerp }}
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
gerps:
runs-on: ubuntu-latest
environment: prod
timeout-minutes: 10
outputs:
list: ${{ steps.gerps.outputs.list }}
lambdas_timeout: ${{ steps.gerps.outputs.lambdas_timeout }}
version: ${{ steps.source.outputs.version }}
fleet_dirs: ${{ steps.dirs.outputs.fleet }}
bff: ${{ steps.dirs.outputs.bff }}
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ inputs.source_version }}
- id: gerps
env:
GERP: ${{ inputs.gerp }}
run: |
if [ "$GERP" = all ]; then
# every gerp that runs: an active row with a real account, as deploy.py's _active_rows reads them
list="$(aws dynamodb scan --table-name gerp-customers --profile operator-org --no-cli-pager \
--filter-expression '#s = :a AND attribute_exists(aws_account_id)' \
--expression-attribute-names '{"#s": "status"}' --expression-attribute-values '{":a": {"S": "active"}}' \
--projection-expression gerp_id --output json | jq -c '[.Items[].gerp_id.S] | sort')"
else
list="$(jq -Rc 'split(",") | map(gsub("^ +| +$"; "")) | map(select(length > 0))' <<< "$GERP")"
fi
echo "list=$list" >> "$GITHUB_OUTPUT"
echo "lambdas_timeout=$(( 30 + $(jq length <<< "$list") ))" >> "$GITHUB_OUTPUT" # a minute a gerp, ten at a time
echo "gerps: $(jq -r 'join(", ")' <<< "$list")" >> "$GITHUB_STEP_SUMMARY"
- id: dirs
working-directory: ${{ steps.source.outputs.tree }}
run: |
echo "fleet=$(grep -vx 'prod/gradienterp_cloud/bff' deploy-dirs.txt | jq -Rsc 'split("\n") | map(select(length > 0))')" >> "$GITHUB_OUTPUT"
if grep -qx 'prod/gradienterp_cloud/bff' deploy-dirs.txt; then echo "bff=true" >> "$GITHUB_OUTPUT"; else echo "bff=false" >> "$GITHUB_OUTPUT"; fi
bff:
needs: gerps
if: needs.gerps.outputs.bff == 'true'
runs-on: ubuntu-latest
environment: prod
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/requirements.txt
- run: pip install -r scripts/requirements.txt
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ needs.gerps.outputs.version }}
summary: "false"
- working-directory: ${{ steps.source.outputs.tree }}
run: bash scripts/deploy.sh push --dirs prod/gradienterp_cloud/bff --notes "$(jq -r .commit source.json)"
lambdas:
needs: gerps
if: needs.gerps.outputs.fleet_dirs != '[]'
runs-on: ubuntu-latest
environment: prod
timeout-minutes: ${{ fromJSON(needs.gerps.outputs.lambdas_timeout) }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/requirements.txt
- run: pip install -r scripts/requirements.txt
- uses: actions/setup-node@v7
with:
node-version: "22"
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ needs.gerps.outputs.version }}
summary: "false"
- name: push
working-directory: ${{ steps.source.outputs.tree }}
env:
DIRS: ${{ needs.gerps.outputs.fleet_dirs }}
run: |
mapfile -t dirs < <(jq -r '.[]' <<< "$DIRS")
# push refuses a Node lambda without node_modules, and the zip leaves them out
for d in "${dirs[@]}"; do
if [ -f "$d/package-lock.json" ]; then (cd "$d" && npm ci --no-audit --no-fund); fi
done
# the artifacts once, with provenance; the fleet pipe then moves every gerp's functions onto them
{ echo "### pushed"; echo '```'; python3 scripts/fleet.py push "${dirs[@]}" --notes "$(jq -r .commit source.json)"; echo '```'; } | tee -a "$GITHUB_STEP_SUMMARY"
- name: fleet
working-directory: ${{ steps.source.outputs.tree }}
env:
LIST: ${{ needs.gerps.outputs.list }}
DIRS: ${{ needs.gerps.outputs.fleet_dirs }}
run: |
# the fleet pipe, the runner's composition: identical in logic to `deploy.sh fleet` (modules/terraform
# AGENTS), the same pieces in the same order; GNU parallel in the xargs slot, the log group and the
# summary are the runner's
mapfile -t dirs < <(jq -r '.[]' <<< "$DIRS")
snapshot="$RUNNER_TEMP/fleet-snapshot.tsv"
python3 scripts/fleet.py listzipversions > "$snapshot"
echo "::group::fleet"
rc=0
python3 scripts/fleet.py listgerps | cut -f1 | grep -Fx -f <(jq -r '.[]' <<< "$LIST") \
| parallel -k -j 10 --halt never 'python3 scripts/fleet.py listzipfnsconf --gerp {}' \
| python3 scripts/fleet.py status "$snapshot" --dirs "${dirs[@]}" \
| tee "$RUNNER_TEMP/fleet.tsv" \
| python3 scripts/fleet.py update \
|| rc=$?
cat "$RUNNER_TEMP/fleet.tsv" # the report in the log group as well as the summary
echo "::endgroup::"
{ echo "### fleet"; echo '```'; cat "$RUNNER_TEMP/fleet.tsv"; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
exit "$rc"
playbooks:
# playbooks.yaml composed: the same gerps, after their pushes; only when the dispatch asks, since a
# kb.md change reaching main runs it on its own
needs: [gerps, lambdas]
if: ${{ !cancelled() && inputs.playbooks }}
permissions:
contents: read
id-token: write
uses: ./.github/workflows/playbooks.yaml
with:
gerp: ${{ inputs.gerp }}
secrets: inherit
integ:
needs: [gerps, bff, lambdas]
if: ${{ !cancelled() && !contains(needs.*.result, 'failure') && (needs.lambdas.result == 'success' || needs.bff.result == 'success') }}
runs-on: ubuntu-latest
environment: prod
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/requirements.txt
- run: pip install -r scripts/requirements.txt
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ needs.gerps.outputs.version }}
summary: "false"
- working-directory: ${{ steps.source.outputs.tree }}
run: |
for m in $(sed -E 's#^(modules|prod)/([^/]+)/.*#\2#' deploy-dirs.txt | sort -u); do
if [ -d "tests/$m/integ" ]; then bash scripts/test.sh --env integ --module "$m"; fi
done
build:
needs: gerps
if: inputs.image == 'build'
runs-on: ubuntu-24.04-arm
environment: prod
timeout-minutes: 45
outputs:
tag: ${{ steps.push.outputs.tag }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/requirements.txt
- run: pip install -r scripts/requirements.txt
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ needs.gerps.outputs.version }}
summary: "false"
- name: build
working-directory: ${{ steps.source.outputs.tree }}
run: bash scripts/docker.sh --build
- id: push
name: push
working-directory: ${{ steps.source.outputs.tree }}
run: |
bash scripts/upload.sh image | tee "$RUNNER_TEMP/image.out"
tag="$(sed -n 's/^==> \(v[0-9]*\) = .*/\1/p' "$RUNNER_TEMP/image.out" | tail -1)"
[ -n "$tag" ] || { echo "upload.sh image printed no tag"; exit 1; }
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "image: $(grep '^==> v' "$RUNNER_TEMP/image.out")" >> "$GITHUB_STEP_SUMMARY"
runtimes:
needs: [gerps, build]
if: ${{ !cancelled() && inputs.image != 'none' && needs.gerps.result == 'success' && (needs.build.result == 'success' || (inputs.image == 'no-build' && needs.build.result == 'skipped')) }}
runs-on: ubuntu-latest
environment: prod
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
gerp: ${{ fromJSON(needs.gerps.outputs.list) }}
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: scripts/requirements.txt
- run: pip install -r scripts/requirements.txt
- uses: ./.github/actions/aws
with:
role: ${{ secrets.AWS_DEPLOY_ROLE_ARN }}
- id: source
uses: ./.github/actions/source
with:
version: ${{ needs.gerps.outputs.version }}
summary: "false"
- working-directory: ${{ steps.source.outputs.tree }}
env:
GERP: ${{ matrix.gerp }}
TAG: ${{ needs.build.outputs.tag }}
run: |
# the tag build pushed holds still; without one (image: no-build), the top of ECR
bash scripts/deploy.sh image --no-build --gerp "$GERP" ${TAG:+--tag "$TAG"} | tee "$RUNNER_TEMP/image.out"
{ echo "### $GERP"; echo '```'; cat "$RUNNER_TEMP/image.out"; echo '```'; } >> "$GITHUB_STEP_SUMMARY"