-
Notifications
You must be signed in to change notification settings - Fork 199
401 lines (345 loc) · 16.4 KB
/
hotfix-wf-service.yml
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
name: Hotfix on workflows-service
on:
workflow_dispatch:
inputs:
environment:
type: choice
description: 'Choose Environment for Hotfix'
required: true
default: 'dev'
options:
- 'dev'
- 'sb'
- 'prod'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/workflows-service
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
sha_short: ${{ steps.version.outputs.sha_short }} # short sha of the commit
image_tags: ${{ steps.docker_meta.outputs.tags }} # <short_sha>-<branch_name>, <branch_name>, latest(for prod branch only)
version: ${{ steps.bump-version.outputs.version }} # [email protected]
bumped_tag: ${{ steps.bump-version.outputs.tag }} # bumped patched version X.X.X+1
docker_image: ${{ steps.docker-version.outputs.image }} # ghcr.io/ballerine-io/workflows-service
docker_tag: ${{ steps.docker-version.outputs.tag }} # <short_sha>-<branch_name>
docker_full_image: ${{ steps.docker-version.outputs.full_image }} # ghcr.io/ballerine-io/workflows-service:<short_sha>-<branch_name>
sanitized-branch: ${{ steps.sanitized-branch.outputs.sanitized-branch-name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get tags
run: git fetch --tags origin
- name: Get version
id: version
run: |
TAG=$(git tag -l "$(echo workflow-service@)*" | sort -V -r | head -n 1)
echo "tag=$TAG"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "TAG=$TAG" >> "$GITHUB_ENV"
SHORT_SHA=$(git rev-parse --short HEAD)
echo "sha_short=$SHORT_SHA"
echo "sha_short=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
echo "DEV_WF_SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
- name: Bump version
id: bump-version
uses: ./.github/actions/bump-version
with:
tag: ${{ steps.version.outputs.tag }}
- name: "Determine Branch"
id: sanitized-branch
uses: transferwise/sanitize-branch-name@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
- name: Cache Docker layers
id: cache
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
${{ runner.os }}-docker-
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker images
id: docker_meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ github.ref_name }}
type=raw,value=${{ inputs.environment }}
type=raw,value=${{ steps.version.outputs.sha_short }}-${{ inputs.environment }}
type=raw,value=${{ steps.version.outputs.sha_short }}-${{ steps.sanitized-branch.outputs.sanitized-branch-name }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'prod') }}
type=sha,format=short
- name: Docker metadata version
id: docker-version
run: |
DOCKER_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
DOCKER_TAG=${{ steps.version.outputs.sha_short }}-${{ github.ref_name }}
DOCKER_FULL_IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.sha_short }}-${{ steps.sanitized-branch.outputs.sanitized-branch-name }}
echo "DOCKER_IMAGE=$DOCKER_IMAGE"
echo "DOCKER_TAG=$DOCKER_TAG"
echo "DOCKER_FULL_IMAGE=$DOCKER_FULL_IMAGE"
echo "image=$DOCKER_IMAGE" >> $GITHUB_OUTPUT
echo "tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "full_image=$DOCKER_FULL_IMAGE" >> $GITHUB_OUTPUT
- name: Print docker version outputs
run: |
echo "Metadata: ${{ steps.docker_meta.outputs.tags }}"
echo "sha_short: ${{ steps.version.outputs.sha_short }}"
echo "docker_meta-tags: ${{ steps.docker_meta.outputs.tags }}"
echo "bump-version-version: ${{ steps.bump-version.outputs.version }}-hotfix"
echo "bump-version-tag: ${{ steps.bump-version.outputs.tag }}-hotfix"
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: services/workflows-service
platforms: linux/amd64
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ${{ steps.docker_meta.outputs.tags }}
build-args: |
"RELEASE=${{ steps.bump-version.outputs.tag }}-hotfix"
"SHORT_SHA=${{ steps.version.outputs.sha_short }}"
- name: Scan Docker Image
uses: aquasecurity/trivy-action@master
continue-on-error: true
with:
cache-dir:
image-ref: ${{ steps.docker-version.outputs.full_image }}
format: 'table'
ignore-unfixed: true
exit-code: 1
trivyignores: ./.trivyignore
vuln-type: 'os,library'
severity: 'CRITICAL'
- name: Update Service version in Environment
run: |
if [ "${{ inputs.environment }}" == "prod" ]; then
ENV="PROD"
elif [ "${{ inputs.environment }}" == "sb" ]; then
ENV="SB"
else
ENV="DEV"
fi
echo "$ENV"
curl -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_CI_ENV_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/ballerine-io/ballerine/actions/variables/${ENV^^}_WF_SHORT_SHA" \
-d "{\"name\":\"${ENV}_WF_SHORT_SHA\",\"value\":\"${{ steps.version.outputs.sha_short }}\"}"
build-and-push-ee-image:
runs-on: ubuntu-latest
needs: build-and-push-image
outputs:
SUBMODULE_SHORT_HASH: ${{ steps.lastcommit.outputs.shorthash }} # short sha of the commit
docker_tag: ${{ steps.docker-version.outputs.wf_m_tag }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: 'recursive'
token: ${{ secrets.SUBMODULES_TOKEN }}
- name: Cache Docker layers
id: cache
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
${{ runner.os }}-docker-
- name: Checkout wf-data-migration
uses: actions/checkout@v4
with:
repository: ballerine-io/wf-data-migration
token: ${{ secrets.SUBMODULES_TOKEN }}
ref: ${{ inputs.environment }}
fetch-depth: 1
path: services/workflows-service/prisma/data-migrations
- name: Get Latest Commit ID
id: lastcommit
uses: nmbgeek/github-action-get-latest-commit@main
with:
owner: ${{ github.repository_owner }}
token: ${{ secrets.SUBMODULES_TOKEN }}
repo: wf-data-migration
branch: ${{ inputs.environment }}
- name: Set Commit Id as Env
run: echo "SUBMODULE_SHORT_HASH=${{ steps.lastcommit.outputs.shorthash }}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: 'arm64,arm'
- name: Log in to the container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for ee Docker images
id: eemeta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{needs.build-and-push-image.outputs.docker_image}}-ee
tags: |
type=raw,value=${{ inputs.environment }}
type=raw,value=${{ needs.build-and-push-image.outputs.sha_short }}-${{ steps.lastcommit.outputs.shorthash }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}
type=sha,format=short
- name: Docker metadata version
id: docker-version
run: |
DOCKER_IMAGE=${{needs.build-and-push-image.outputs.docker_image}}-ee
DOCKER_TAG=${{ needs.build-and-push-image.outputs.sha_short }}-${{ steps.lastcommit.outputs.shorthash }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}
DOCKER_FULL_IMAGE=$DOCKER_IMAGE:$DOCKER_TAG
echo "DOCKER_IMAGE=$DOCKER_IMAGE"
echo "DOCKER_TAG=$DOCKER_TAG"
echo "DOCKER_FULL_IMAGE=$DOCKER_FULL_IMAGE"
echo "wf_m_image=$DOCKER_IMAGE" >> $GITHUB_OUTPUT
echo "wf_m_tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
echo "wf_m_full_image=$DOCKER_FULL_IMAGE" >> $GITHUB_OUTPUT
- name: Build and push ee Docker image
uses: docker/build-push-action@v5
with:
context: services/workflows-service
file: services/workflows-service/Dockerfile.ee
platforms: linux/amd64
push: true
cache-from: type=local,src=/tmp/.buildx-cache
tags: ${{ steps.eemeta.outputs.tags }}
build-args: |
"BASE_IMAGE=${{needs.build-and-push-image.outputs.docker_full_image}}"
"RELEASE=${{ needs.build-and-push-image.outputs.bumped_tag }}"
"SHORT_SHA=${{ needs.build-and-push-image.outputs.sha_short }}"
update-helm-chart:
runs-on: ubuntu-latest
needs: [build-and-push-ee-image,build-and-push-image]
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Checkout cloud-infra-config repository
uses: actions/checkout@v4
with:
repository: ballerine-io/cloud-infra-config
token: ${{ secrets.GIT_TOKEN }}
ref: main
fetch-depth: 1
sparse-checkout: |
kubernetes/helm/wf-service
sparse-checkout-cone-mode: true
- name: Check if values yaml file exists
id: update_helm_check
shell: bash
run: |
if [ -f "kubernetes/helm/wf-service/${{ inputs.environment }}-custom-values.yaml" ]; then
echo "file_name=${{ inputs.environment }}-custom-values.yaml" >> "$GITHUB_OUTPUT"
echo ${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}
else
echo "file_name=dev-custom-values.yaml" >> "$GITHUB_OUTPUT"
echo ${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}
fi
- name: Update workflow-service image version in the HelmChart
uses: fjogeleit/yaml-update-action@main
with:
repository: ballerine-io/cloud-infra-config
branch: main
commitChange: true
message: "Performed HotFix to ${{ inputs.environment }} wf-service application image Version to ${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }} - (Commit hash: ${{ github.sha }}, commit message: ${{ github.event.head_commit.message }})"
token: ${{ secrets.GIT_TOKEN }}
changes: |
{
"kubernetes/helm/wf-service/${{steps.update_helm_check.outputs.file_name}}": {
"image.tag": "${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}",
"prismaMigrate.image.tag": "${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}",
"dbMigrate.image.tag": "${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}",
"dataSync.image.tag": "${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }}"
}
}
send-to-slack:
runs-on: ubuntu-latest
needs: [update-helm-chart,build-and-push-ee-image,build-and-push-image]
environment: ${{ inputs.environment }}
if: ${{ needs.update-helm-chart.result == 'success' }}
permissions:
contents: read
packages: write
steps:
- name: Send alert to Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: '${{ secrets.ARGO_SLACK_CHANNEL_ID }}'
slack-message: "Hotfix on Wf-service app Deployment in ${{ inputs.environment }} with tag ${{ needs.build-and-push-image.outputs.sha_short }}-${{ needs.build-and-push-ee-image.outputs.SUBMODULE_SHORT_HASH }}-${{ needs.build-and-push-image.outputs.sanitized-branch }} build result: ${{ job.status }}. successfully updated the hotfix on wf-service helm values for ${{ inputs.environment }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.ARGO_SLACK_BOT_TOKEN }}
release:
runs-on: ubuntu-latest
needs: [build-and-push-image,update-helm-chart]
if: ${{ needs.update-helm-chart.result=='success' }} && (startsWith(github.ref, 'refs/heads/prod') || startsWith(github.ref, 'refs/heads/dev') || startsWith(github.ref, 'refs/heads/sb') || github.event.inputs.environment == 'dev')
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Release
run: |
if [ "${{ inputs.environment }}" == "dev" ]; then
suffix="-dev-${{ needs.build-and-push-image.outputs.sha_short }}"
else
suffix=""
fi
prefix="hotfix-"
gh release create ${prefix}${{ needs.build-and-push-image.outputs.version }}${suffix} --notes-start-tag ${{ needs.build-and-push-image.outputs.bumped_tag }}
sentry:
runs-on: ubuntu-latest
needs: [release,build-and-push-image]
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout
uses: actions/checkout@v4
# TODO: add caching for docker_full_image which build previously
- name: Run Container and Copy File
run: |
id=$(docker run --rm --name tmp -d ${{ needs.build-and-push-image.outputs.docker_full_image }} tail -f /dev/null)
mkdir -p ./dist
docker cp $id:/app/dist/ ./dist
curl -sL https://sentry.io/get-cli/ | SENTRY_CLI_VERSION="2.31.0" bash
sentry-cli releases new "${{needs.build-and-push-image.outputs.version}}"
echo "sentry-cli releases new ${{needs.build-and-push-image.outputs.version}}"
sentry-cli releases set-commits "${{needs.build-and-push-image.outputs.version}}" --auto --ignore-missing
echo "sentry-cli releases set-commits ${{needs.build-and-push-image.outputs.version}} --auto --ignore-missing"
sentry-cli sourcemaps upload --dist="${{needs.build-and-push-image.outputs.sha_short}}" --release="${{needs.build-and-push-image.outputs.version}}" ./dist
echo "sentry-cli sourcemaps upload --dist=${{needs.build-and-push-image.outputs.sha_short}} --release=${{needs.build-and-push-image.outputs.version}} ./dist"
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.WF_SENTRY_PROJECT }}