-
Notifications
You must be signed in to change notification settings - Fork 40
420 lines (381 loc) · 14.4 KB
/
Copy pathv3-release-deploy.yml
File metadata and controls
420 lines (381 loc) · 14.4 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
---
name: "(TEMPORARY) v3 Release and Deployment"
on:
workflow_dispatch:
inputs:
run-type:
description: >-
Specify whether to just build, just deploy, or both
required: true
default: BUILD_AND_DEPLOY
type: choice
options:
- BUILD_ONLY
- DEPLOY_ONLY
- BUILD_AND_DEPLOY
version-suffix:
description: >-
Version suffix appended to the current, valid v3 tag name. Recommended to be
<abbreviated-branch-or-ticket-num>-<count>; e.g.: 1234-1, 4567-10, etc. The full version
that is used to tag Images will then be <base-tag>-<version-suffix>, e.g.:
v3.2026.01.30.0-1234-1
required: false
default: ""
envs:
description: >-
List of environments to deploy to
required: true
default: >-
test,
sandbox,
prod
deploy-platform:
description: >-
Deploy platform Terraservices?
required: true
type: boolean
default: false
aws-region:
description: >-
Override the AWS Region destination for uploaded artifacts.
Default to `us-east-1`.
default: us-east-1
type: choice
options:
- us-east-1
- us-west-2
required: true
permissions:
id-token: write # This is required for requesting the AWS IAM OIDC JWT
contents: write # This is required for actions/checkout
env:
AWS_REGION: ${{ inputs.aws-region }}
JIB_IMAGES: |
[
"bfd-server-ng"
]
BASE_IMAGES: |
[
"bfd-platform-base-java"
]
ACCOUNT_ROLE_MAP: |
{
"prod": "${{ secrets.PROD_ACCOUNT_GHA_ROLE_ARN }}",
"non-prod": "${{ secrets.NON_PROD_ACCOUNT_GHA_ROLE_ARN }}"
}
defaults:
run:
shell: bash
jobs:
setup:
runs-on: ubuntu-24.04
outputs:
current-version: ${{ steps.bfd-version-strings.outputs.current-version }}
full-version-tag: ${{ steps.bfd-version-strings.outputs.full-version-tag }}
envs-as-json: ${{ steps.envs-as-json.outputs.envs-as-json }}
env:
REF_NAME: ${{ github.ref_name }}
REF: ${{ github.ref }}
steps:
- name: Validate ref
run: |
if ! echo "$REF" | grep -P '^refs/tags.*$'; then
echo "$REF_NAME is not a tag; this Workflow must be ran with a valid v3 tag as the reference"
exit 1
fi
if ! echo "$REF_NAME" | grep -P '^v3\.\d{4}.\d{2}.\d{2}.\d+$'; then
echo "$REF_NAME MUST be in the form 'v3.yyyy.MM.dd.<integer>', e.g.: v3.2026.01.30.0"
exit 1
fi
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: "Install yq"
run: |
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
sudo chmod +x /usr/bin/yq
- name: Set and Validate Version Strings
id: bfd-version-strings
env:
VERSION_SUFFIX: ${{ inputs.version-suffix }}
run: |
bfd_parent_pom_version="$(yq --output-format=yaml .project.version apps/pom.xml)"
full_version_tag="$REF_NAME"
if [[ -n $VERSION_SUFFIX ]]; then
full_version_tag="$REF_NAME-$VERSION_SUFFIX"
fi
# Validate and set current-version and full-version-tag
echo "$bfd_parent_pom_version" | grep -P '^\d+\.\d+\.\d+$|^\d+\.\d+\.\d+-SNAPSHOT$'
echo current-version="$bfd_parent_pom_version" >> "$GITHUB_OUTPUT"
echo "$full_version_tag" | grep -P '^v3\.\d{4}.\d{2}.\d{2}.\d+.*$'
echo full-version-tag="$full_version_tag" >> "$GITHUB_OUTPUT"
- name: Envs as JSON
id: envs-as-json
env:
ENVS: ${{ inputs.envs }}
run: |
envs_as_json="$(jq -Rc '[(split(",") // [])[]| sub("^ "; "") | sub(" $"; "")]' <<<"$ENVS")"
echo "envs-as-json=$envs_as_json" >> "$GITHUB_OUTPUT"
deploy-platform:
if: ${{ inputs.deploy-platform && (inputs.run-type == 'DEPLOY_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY') }}
uses: ./.github/workflows/deploy-platform-services.yml
needs: [setup]
strategy:
matrix:
account-type: ["prod", "non-prod"]
fail-fast: false
with:
account-type: ${{ matrix.account-type }}
git-ref: ${{ github.ref_name }}
secrets: inherit
pull-base-java:
# deploy-platform is conditional, so we want to run this step if it runs or not as long as it
# did not fail.
if: |
(inputs.run-type == 'BUILD_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY')
&& (
(!failure() && !cancelled()) && needs.setup.result == 'success'
)
needs: [deploy-platform, setup]
runs-on: ${{ format('codebuild-bfd-non-prod-platform-docker-{0}-{1}', github.run_id, github.run_attempt) }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6
with:
role-to-assume: ${{ secrets.NON_PROD_ACCOUNT_GHA_ROLE_ARN }}
role-session-name: v3-release-deploy-${{ github.run_id }}-${{ github.run_attempt }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2
- name: Pull base images
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
BASE_IMAGES_VERSION: latest
run: |
echo "::add-mask::$REGISTRY"
readarray -t images < <(echo "$BASE_IMAGES" | jq -r -c '.[]')
for image in "${images[@]}"
do
docker pull "${REGISTRY}/${image}:${BASE_IMAGES_VERSION}"
docker tag "${REGISTRY}/${image}:${BASE_IMAGES_VERSION}" "${image}:${BASE_IMAGES_VERSION}"
docker rmi "${REGISTRY}/${image}:${BASE_IMAGES_VERSION}"
docker save "${image}:${BASE_IMAGES_VERSION}" > "${{ runner.temp }}/${image}_${BASE_IMAGES_VERSION}.tar"
done
- name: Upload base image artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: bfd-platform-base-java
path: ${{ runner.temp }}/*.tar
retention-days: 1
build-server-ng-image:
# For reasons unknown, _downstream_ jobs must also guard against
# their needed Jobs depending on conditional jobs.
if: |
(inputs.run-type == 'BUILD_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY')
&& (
(!failure() && !cancelled()) && needs.setup.result == 'success'
)
runs-on: ubuntu-24.04-arm
needs: [setup, pull-base-java]
env:
CURRENT_VERSION: ${{ needs.setup.outputs.current-version }}
FULL_VERSION_TAG: ${{ needs.setup.outputs.full-version-tag }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
ref: ${{ github.ref_name }}
- name: Retrieve base java image
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
pattern: "*bfd-platform-base-java*"
merge-multiple: true
path: ${{ runner.temp }}
- name: Load base image into Docker
run: |
docker load --input "${{ runner.temp }}/bfd-platform-base-java_latest.tar"
rm -f "${{ runner.temp }}/bfd-platform-base-java_latest.tar"
- name: Install gitleaks
run: |
curl -s https://api.github.com/repos/gitleaks/gitleaks/releases/latest \
| grep "browser_download_url.*linux_x64.tar.gz" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -
sudo tar -xzf "$(find -iname 'gitleaks*.tar.gz')" -C /usr/bin gitleaks
sudo chmod +x /usr/bin/gitleaks
- name: Setup JDK
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
java-version: "25"
distribution: corretto
- name: Build bfd-server-ng and deps
run: |-
mvn clean install \
-DskipTests=true \
-DskipITs \
-Dmaven.javadoc.skip=true \
-Dcheckstyle.skip \
-Dmaven.build.cache.enabled=true \
--threads 1C \
--no-transfer-progress \
-pl :bfd-server-ng \
-am
working-directory: ./apps
- name: Build bfd-server-ng Image
run: |-
mvn --batch-mode com.google.cloud.tools:jib-maven-plugin:dockerBuild \
-pl :bfd-server-ng \
-Djib.skip=false \
-Djib.from="docker://bfd-platform-base-java:latest" \
--no-transfer-progress
working-directory: ./apps
- name: Export jib images
run: |
readarray -t images < <(echo "$JIB_IMAGES" | jq -r -c '.[]')
for image in "${images[@]}"
do
docker save "$image:$CURRENT_VERSION" > "${image}.tar"
done
working-directory: ${{ runner.temp }}
- name: Upload jib image artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: jib-images
path: ${{ runner.temp }}/*.tar
retention-days: 1
push-jib-images:
if: |
(inputs.run-type == 'BUILD_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY')
&& (
(!failure() && !cancelled()) && needs.setup.result == 'success'
)
needs: [setup, build-server-ng-image]
strategy:
matrix:
account: ["prod", "non-prod"]
runs-on: codebuild-bfd-${{ matrix.account }}-platform-docker-${{ github.run_id }}-${{ github.run_attempt }}
env:
CURRENT_VERSION: ${{ needs.setup.outputs.current-version }}
FULL_VERSION_TAG: ${{ needs.setup.outputs.full-version-tag }}
steps:
- name: Get role ARN
id: get-role-arn
run: |
role_arn="$(jq -r --arg account_type "${{ matrix.account }}" '.[$account_type]' <<<"$ACCOUNT_ROLE_MAP")"
echo "::add-mask::$role_arn"
echo "role-arn=$role_arn" >> "$GITHUB_OUTPUT"
- name: Download jib image artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: jib-images
path: ${{ runner.temp }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6
with:
role-to-assume: ${{ steps.get-role-arn.outputs.role-arn }}
role-session-name: v3-release-deploy-${{ github.run_id }}-${{ github.run_attempt }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@d539f0932e70871a027e9d5a9d8fc38589180a64 # v2
- name: Push jib images
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
run: |
echo "::add-mask::$REGISTRY"
for image_filename in ./*.tar
do
docker load --input "$image_filename"
image="$(basename "$image_filename" .tar)"
docker tag "$image:$CURRENT_VERSION" "$REGISTRY/$image:$FULL_VERSION_TAG"
docker rmi "$image:$CURRENT_VERSION"
docker push "$REGISTRY/$image:$FULL_VERSION_TAG"
done
working-directory: ${{ runner.temp }}
build-other-images:
# deploy-platform is conditional, so we want to run this step if it runs or not as long as it
# did not fail.
if: |
(inputs.run-type == 'BUILD_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY')
&& (
(!failure() && !cancelled()) && needs.setup.result == 'success'
)
uses: ./.github/workflows/build-container-images.yml
needs: [deploy-platform, setup]
permissions:
contents: read
id-token: write
with:
branch: ${{ github.ref_name }}
versionTag: ${{ needs.setup.outputs.full-version-tag }}
awsRegion: ${{ inputs.aws-region }}
# Build other images, like Lambda images, Python applications, etc.
# See .github/workflows/build_container_images_matrix.json for list of buildable images
imagesCsv: >-
bfd-platform-server-fluent-bit,
bfd-platform-idr-pipeline,
bfd-platform-migrator-ng,
bfd-platform-consume-idr-events,
bfd-platform-run-idr-pipeline
baseImagesVersion: latest
cleanupImageArtifacts: false # We'll cleanup at the end, so don't do anything
tagLatest: false
secrets: inherit
deploy-to-envs:
if: |
needs.setup.outputs.envs-as-json != '[]'
&& (inputs.run-type == 'DEPLOY_ONLY' || inputs.run-type == 'BUILD_AND_DEPLOY')
&& (
(!failure() && !cancelled()) && needs.setup.result == 'success'
)
uses: ./.github/workflows/deploy-env-services.yml
needs: [setup, push-jib-images, build-other-images]
strategy:
matrix:
bfd-env: ${{ fromJson(needs.setup.outputs.envs-as-json) }}
fail-fast: true
with:
bfd-env: ${{ matrix.bfd-env }}
services: >-
config,
cluster,
database,
migrator-ng,
idr-pipeline,
idr-pipeline-metrics,
idr-pipeline-alarms,
server-ng,
server-ng-metrics,
server-ng-alarms
git-ref: ${{ github.ref_name }}
per-service-vars-json: >-
{
"migrator-ng": {
"migrator_version_override": "${{ needs.setup.outputs.full-version-tag }}"
},
"idr-pipeline": {
"consume_idr_events_version_override": "${{ needs.setup.outputs.full-version-tag }}",
"pipeline_version_override": "${{ needs.setup.outputs.full-version-tag }}",
"run_idr_pipeline_version_override": "${{ needs.setup.outputs.full-version-tag }}"
},
"server-ng": {
"log_router_version_override": "${{ needs.setup.outputs.full-version-tag }}",
"server_version_override": "${{ needs.setup.outputs.full-version-tag }}"
}
}
secrets: inherit
cleanup-artifacts:
if: ${{ !cancelled() }}
needs: [build-other-images]
runs-on: ubuntu-24.04
steps:
- name: Delete all artifacts
uses: GeekyEggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118 # v6.0.0
with:
name: "*"
failOnError: false