-
Notifications
You must be signed in to change notification settings - Fork 20
511 lines (421 loc) · 15.5 KB
/
release.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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
name: Release
on:
push:
branches:
- master
paths:
- ".github/workflows/release.yml"
- "grai-server/**"
- "grai-frontend/**"
env:
py_ver: "3.11"
poetry_ver: "1.3.1"
SECRET_KEY: "fixed-test-key-that-doesnt-matter"
jobs:
get-poetry-version:
runs-on: ubuntu-latest
outputs:
poetry-version: ${{ steps.poetry-version.outputs.poetry-version }}
tag-exists: ${{ steps.check-tag.outputs.exists }}
defaults:
run:
working-directory: ./grai-server/app
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ env.py_ver }}"
- name: Install poetry
run: pip install poetry==${{ env.poetry_ver }}
- name: Get poetry version
id: poetry-version
run: |
echo "poetry-version=v$(poetry version --short)" >> $GITHUB_OUTPUT
- uses: mukunku/tag-exists-action@v1.2.0
id: check-tag
with:
tag: ${{ steps.poetry-version.outputs.poetry-version }}
lint-server:
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Install Python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "${{ env.py_ver }}"
- run: pip install black isort
- working-directory: "grai-server/app"
run: |
black . --check --exclude /migrations/
# isort . --profile black --check
tests-server:
runs-on: ubuntu-latest
needs: lint-server
defaults:
run:
working-directory: ./grai-server/app
services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: grai
POSTGRES_PASSWORD: grai
POSTGRES_DB: grai
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 2s --health-timeout 5s --health-retries 15
redis:
image: redis/redis-stack-server:6.2.6-v9
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ env.py_ver }}"
- name: Install package
run: |
pip install coverage
- uses: abatilo/actions-poetry@v2
with:
poetry-version: "${{ env.poetry_ver }}"
- run: poetry install
- name: Tests
env:
DEBUG: False
DB_HOST: "127.0.0.1"
DB_PORT: "5432"
DB_USER: grai
DB_NAME: grai
DB_PASSWORD: grai
GITHUB_PRIVATE_KEY: installations/tests/sample.private-key.pem
run: |
poetry run python manage.py migrate --noinput
poetry run coverage run -m pytest
poetry run coverage xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: grai-server
token: ${{ secrets.CODECOV_TOKEN }}
build-server-release:
if: ${{needs.get-poetry-version.outputs.tag-exists == 'false' }}
runs-on: ubuntu-latest
needs: [get-poetry-version, lint-server, tests-server]
permissions:
contents: write
outputs:
image-digest-server: ${{ steps.docker-build-server.outputs.digest }}
image-digest-worker: ${{ steps.docker-build-worker.outputs.digest }}
image-digest-beat-worker: ${{ steps.docker-build-beat-worker.outputs.digest }}
defaults:
run:
working-directory: grai-server/app
steps:
- uses: actions/checkout@v3
- uses: ncipollo/release-action@v1
with:
tag: ${{ needs.get-poetry-version.outputs.poetry-version }}
commit: ${{ github.sha }}
generateReleaseNotes: true
makeLatest: true
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta-server
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-server
tags: |
type=raw,value=cloud,priority=100
type=raw,value=latest,priority=100
type=raw,value=${{ needs.get-poetry-version.outputs.poetry-version }},priority=100
- name: Extract metadata (tags, labels) for Docker
id: meta-worker
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-worker
tags: |
type=raw,value=cloud,priority=100
type=raw,value=latest,priority=100
type=raw,value=${{ needs.get-poetry-version.outputs.poetry-version }},priority=100
- name: Extract metadata (tags, labels) for Docker
id: meta-beat-worker
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-beat-worker
tags: |
type=raw,value=cloud,priority=100
type=raw,value=latest,priority=100
type=raw,value=${{ needs.get-poetry-version.outputs.poetry-version }},priority=100
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Build
id: docker-build-server
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-server
push: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build
id: docker-build-worker
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-worker
push: true
tags: ${{ steps.meta-worker.outputs.tags }}
labels: ${{ steps.meta-worker.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build
id: docker-build-beat-worker
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-beat-worker
push: true
tags: ${{ steps.meta-beat-worker.outputs.tags }}
labels: ${{ steps.meta-beat-worker.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-server-cloud:
if: ${{needs.get-poetry-version.outputs.tag-exists == 'true' }}
runs-on: ubuntu-latest
needs: [get-poetry-version, lint-server, tests-server]
permissions:
contents: write
outputs:
image-digest-server: ${{ steps.docker-build-cloud-server.outputs.digest }}
image-digest-worker: ${{ steps.docker-build-cloud-worker.outputs.digest }}
image-digest-beat-worker: ${{ steps.docker-build-cloud-beat-worker.outputs.digest }}
defaults:
run:
working-directory: grai-server/app
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta-cloud-server
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-server
tags: |
type=raw,value=cloud,priority=100
- name: Extract metadata (tags, labels) for Docker
id: meta-cloud-worker
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-worker
tags: |
type=raw,value=cloud,priority=100
- name: Extract metadata (tags, labels) for Docker
id: meta-cloud-beat-worker
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-beat-worker
tags: |
type=raw,value=cloud,priority=100
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Build Cloud Server
id: docker-build-cloud-server
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-server
push: true
tags: ${{ steps.meta-cloud-server.outputs.tags }}
labels: ${{ steps.meta-cloud-server.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Cloud Worker
id: docker-build-cloud-worker
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-worker
push: true
tags: ${{ steps.meta-cloud-worker.outputs.tags }}
labels: ${{ steps.meta-cloud-worker.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Cloud Beat Worker
id: docker-build-cloud-beat-worker
uses: docker/build-push-action@v4
with:
context: grai-server/app
target: grai-beat-worker
push: true
tags: ${{ steps.meta-cloud-beat-worker.outputs.tags }}
labels: ${{ steps.meta-cloud-beat-worker.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy-server:
runs-on: ubuntu-latest
needs: [build-frontend, build-server-cloud, build-server-release]
if: ${{ always() && needs.build-frontend.result == 'success' && (needs.build-server-cloud.result == 'success' || needs.build-server-release.result == 'success') }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Deploy to Kubernetes cluster - api
uses: ianbelcher/eks-kubectl-action@master
with:
cluster_name: ${{ secrets.CLUSTER_NAME }}
args: set image deployment/api-prod api=ghcr.io/${{ github.repository }}/grai-server@${{ needs.build-server-release.outputs.image-digest-server || needs.build-server-cloud.outputs.image-digest-server }}
- name: Deploy to Kubernetes cluster - celery
uses: ianbelcher/eks-kubectl-action@master
with:
cluster_name: ${{ secrets.CLUSTER_NAME }}
args: set image deployment/celery-worker-prod celery-worker=ghcr.io/${{ github.repository }}/grai-worker@${{ needs.build-server-release.outputs.image-digest-worker || needs.build-server-cloud.outputs.image-digest-worker }}
- name: Deploy to Kubernetes cluster - celery beat
uses: ianbelcher/eks-kubectl-action@master
with:
cluster_name: ${{ secrets.CLUSTER_NAME }}
args: set image deployment/celery-beat-worker-prod celery-beat-worker=ghcr.io/${{ github.repository }}/grai-beat-worker@${{ needs.build-server-release.outputs.image-digest-beat-worker || needs.build-server-cloud.outputs.image-digest-beat-worker }}
- name: Verify deployment
uses: ianbelcher/eks-kubectl-action@master
with:
cluster_name: ${{ secrets.CLUSTER_NAME }}
args: rollout status deployment/api-prod
tests-frontend:
runs-on: ubuntu-latest
defaults:
run:
working-directory: grai-frontend
env:
REACT_APP_ALGOLIA_APP_ID: test
steps:
- uses: actions/checkout@master
- name: Use latest Node.js
uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci
- name: Run lint
run: npm run lint
- name: Run npm tests
run: npm test -- --coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: grai-frontend
token: ${{ secrets.CODECOV_TOKEN }}
build-frontend:
runs-on: ubuntu-latest
needs: tests-frontend
env:
REACT_APP_SERVER_URL: ${{ secrets.REACT_APP_SERVER_URL }}
REACT_APP_POSTHOG_API_KEY: ${{ secrets.REACT_APP_POSTHOG_API_KEY }}
REACT_APP_POSTHOG_HOST: https://ph.grai.io
REACT_APP_ALGOLIA_APP_ID: ${{ secrets.REACT_APP_ALGOLIA_APP_ID }}
REACT_APP_SENTRY_DSN: ${{ secrets.REACT_APP_SENTRY_DSN }}
defaults:
run:
working-directory: grai-frontend
steps:
- uses: actions/checkout@master
- name: Use latest Node.js
uses: actions/setup-node@v3
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup environment variables
run: ./env.sh
- uses: actions/upload-artifact@master
with:
name: frontend-build
path: "./grai-frontend/build"
- name: Run bundlewatch
run: npm run bundlewatch
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
deploy-frontend:
runs-on: ubuntu-latest
needs: [build-frontend, build-server-cloud, build-server-release]
if: ${{ always() && needs.build-frontend.result == 'success' && (needs.build-server-cloud.result == 'success' || needs.build-server-release.result == 'success') }}
defaults:
run:
working-directory: grai-frontend
steps:
- uses: actions/download-artifact@master
with:
name: frontend-build
path: "./grai-frontend/build"
- name: Copy to s3
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
source: "./grai-frontend/build"
dest: s3://${{ secrets.APP_BUCKET }}
flags: --recursive
- name: Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DISTRIBUTION: ${{ secrets.AWS_CF_DISTRIBUTION }}
PATHS: "/*"
AWS_REGION: "us-east-1"
package-frontend:
runs-on: ubuntu-latest
needs: [get-poetry-version, tests-frontend]
if: ${{needs.get-poetry-version.outputs.tag-exists == 'false' }}
permissions:
contents: write
defaults:
run:
working-directory: grai-frontend
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/grai-frontend
tags: |
type=raw,value=latest,priority=100
type=raw,value=${{ needs.get-poetry-version.outputs.poetry-version }},priority=100
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
- name: Build
id: docker-build
uses: docker/build-push-action@v4
with:
context: grai-frontend
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max