-
Notifications
You must be signed in to change notification settings - Fork 66
237 lines (204 loc) · 7.4 KB
/
ci.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
name: CI
on:
push:
branches:
- master
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: build
uses: ./.github/actions/build
- name: restore mypy cache
uses: actions/cache@v4
with:
path: .mypy_cache
key: mypy-cache-${{ github.ref_name }}
restore-keys: mypy-cache-master
- name: lint
run: make lint
test:
needs: lint
runs-on: ${{ contains(github.triggering_actor, '[bot]') && 'ubuntu-latest' || 'ubuntu-8x' }}
services:
postgres:
image: postgres:13.9-alpine
env:
POSTGRES_PASSWORD: secret
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:6.2.10-alpine
ports:
- 6379:6379
steps:
- uses: actions/checkout@v4
- name: build
uses: ./.github/actions/build
- name: install locale stuff
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: locales-all gettext
version: 1
- name: get number of CPU cores
uses: SimenB/[email protected]
id: cpu-cores
- name: test
env:
DATABASE_URL: postgres://postgres:secret@localhost:5432/postgres
REDISCLOUD_URL: redis://localhost:6379/5
run: make test -e SIMULTANEOUS_TEST_JOBS=${{ steps.cpu-cores.outputs.count }}
- name: publish test results
uses: phoenix-actions/test-reporting@v13
if: ${{ !contains(github.triggering_actor, '[bot]') }}
with:
name: Test results
path: "src/junit-*.xml"
reporter: java-junit
- name: upload code coverage to codeclimate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: dd4cac59d43b52ee4c29cfed9d5162098a49ff65d9e72003abc1fa65cd608f1d
with:
coverageLocations: |
${{github.workspace}}/src/coverage.xml:coverage.py
build-docker-image:
needs: test
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: build
uses: ./.github/actions/build
- name: set up qemu
uses: docker/setup-qemu-action@v3
- name: set up buildx
uses: docker/setup-buildx-action@v3
- name: generate image identifier
id: image
uses: ASzc/change-string-case-action@v6
with:
string: ${{ github.repository_owner }}
- name: login to ghcr
uses: docker/login-action@v3
if: ${{ github.ref == 'refs/heads/master' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build web image
uses: docker/build-push-action@v6
with:
context: .
target: web
push: ${{ github.ref == 'refs/heads/master' }}
tags: |
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-web:latest
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-web:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: build worker image
uses: docker/build-push-action@v6
with:
context: .
target: worker
push: ${{ github.ref == 'refs/heads/master' }}
tags: |
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:latest
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: build scheduler image
uses: docker/build-push-action@v6
with:
context: .
target: scheduler
push: ${{ github.ref == 'refs/heads/master' }}
tags: |
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:latest
ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:${{ github.sha }}
build-args: |
PYTHON_VERSION=${{ env.python-version }}
RELEASE=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-docker-image
if: github.ref == 'refs/heads/master' && github.repository_owner == 'tough-dev-school'
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: draft sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
finalize: false
- name: read image identifiers
id: image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.repository_owner }}
- name: update backend image
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_backend --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-web:${{ github.sha }} --with-registry-auth
- name: update celery worker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_worker --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }} --with-registry-auth
- name: update amocrm worker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_amocrm-worker --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }} --with-registry-auth
- name: update notion worker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: docker service update app_notion-worker --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-worker:${{ github.sha }} --with-registry-auth
- name: update celery scheduler image
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEPLOY_HOST }}
username: circle
key: ${{ secrets.DEPLOY_KEY }}
script: |
docker service update app_scheduler --detach --image ghcr.io/${{ steps.image.outputs.lowercase }}/monolith-scheduler:${{ github.sha }} --with-registry-auth
- name: finalize sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
finalize: true