-
Notifications
You must be signed in to change notification settings - Fork 14
261 lines (254 loc) · 9.2 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
---
name: CI Build
on:
push:
branches: ['master', 'prod']
pull_request:
branches: ['master']
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_ORGANIZATION: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
django-tests:
name: "Django tests"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python_version: ["3.11"]
django_version: ['current', "4.2.14"]
env:
PYTHON_VERSION: ${{ matrix.python_version }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- if: matrix.django_version != 'latest' && matrix.django_version != 'current'
run: |
echo "DJANGO_VERSION=${DJANGO_VERSION}" | tee "${GITHUB_ENV}";
env:
DJANGO_VERSION: ${{ matrix.django_version }}
- if: matrix.django_version == 'latest'
run: |
latest_version=$(curl 'https://pypi.org/pypi/django/json' | jq .info.version -r)
echo "DJANGO_VERSION=${latest_version}" | tee "${GITHUB_ENV}";
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: |
./scripts/ci-docker-image/build_image.sh
./scripts/ci-docker-image/verify_image.sh
- name: Pull images
run: ./scripts/pull_images.py
- name: "Run tests"
run: ./run_test.sh
- name: "Check missing migrations"
run: docker compose run web makemigrations --check -v 3
- name: "Checks the entire Django project for potential problems"
run: docker compose run web check --fail-level DEBUG -v 3
- name: "Upload coverage"
uses: codecov/codecov-action@v4.3.1
with:
fail_ci_if_error: false
verbose: true
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
./scripts/ci-docker-image/push_image.sh
# Push cache
./scripts/ci-docker-image/build_image.sh
- name: Show logs on fail
if: ${{ failure() }}
run: docker compose logs
static-checks:
name: "Static checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Setup Python dependencies"
run: pip install -U pip wheel setuptools virtualenv
- name: "Run static checks"
uses: pre-commit/action@v3.0.1
bi-validate:
name: "BI Validate"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
env:
COMPOSE_FILE: "docker-compose.yaml:docker-compose.dbt.yaml:docker-compose.dbt-local.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Copy .env.example to .env"
run: cp .env.example .env
- name: "Build CI image"
run: |
./scripts/ci-docker-image/build_image.sh
./scripts/ci-docker-image/verify_image.sh
- name: "Build BI image"
run: |
# Build BI image
./scripts/bi-docker-image/build_image.sh
# Verify BI image
./scripts/bi-docker-image/verify_image.sh
- name: Pull images
run: ./scripts/pull_images.py
- run: docker compose config
- run: docker compose up -d
- run: ./run_manage.sh migrate
- run: ./run_manage.sh populate_db
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build
- name: "Push image (push)"
if: github.event_name == 'push'
run: ./scripts/bi-docker-image/push_image.sh
prod-image:
name: "Build Prod Image"
runs-on: ubuntu-latest
needs: [django-tests, static-checks]
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Set image tag"
if: |
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
run: |
set -x;
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "IMAGE_TAG=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
- name: "Build image"
run: ./scripts/prod-docker-image/build_image.sh
- name: "Verify image"
run: ./scripts/prod-docker-image/verify_image.sh
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
# Build cache
./scripts/prod-docker-image/build_image.sh
./scripts/prod-docker-image/push_image.sh
deploy-app:
name: "Deploy app (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Login to Heroku Docker Registry"
run: ./scripts/docker_login_heroku.py
- name: "Install Heroku CLI"
run: "curl https://cli-assets.heroku.com/install.sh | sh"
- name: "Set environment env variable"
run: |
APP_NAME="$(./scripts/detect_app_name.py)";
echo "APP_NAME=${APP_NAME}"
echo "IMAGE_TAG=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_APP=${APP_NAME}" >> $GITHUB_ENV;
echo "HEROKU_DOMAIN=$(./scripts/fetch_domain.py "${APP_NAME}")" >> $GITHUB_ENV;
- uses: chrnorm/deployment-action@releases/v1
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
target_url: "https://${{ env.HEROKU_DOMAIN }}"
state: in_progress
environment: "${{ env.HEROKU_APP }}"
- name: "Pull image"
run: ./scripts/prod-docker-image/pull_image.sh
- name: "Deploy"
run: './scripts/deploy.sh "${HEROKU_APP}"'
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
- name: Update deployment status (failure)
if: failure()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
deploy-bi:
name: "Deploy BI (push) - ${{ github.ref }}"
runs-on: ubuntu-latest
needs: [prod-image, bi-validate]
if: >-
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' || github.ref == 'refs/heads/prod')
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
COMPOSE_FILE: "docker-compose.dbt.yaml"
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version-file: '.python-version'
- name: "Login to Githhub Container Registry"
run: ./scripts/docker_login_github.py
- name: "Build BI image"
run: |
# Build BI image
./scripts/bi-docker-image/build_image.sh
# Verify BI image
./scripts/bi-docker-image/verify_image.sh
- run: pip install django-environ
- name: "Set environment env variable"
if: github.ref == 'refs/heads/prod'
run: |
source <(python ./pola-bi/dev.py --environment prod)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- name: "Set environment env variable"
if: github.ref == 'refs/heads/master'
run: |
source <(python ./pola-bi/dev.py --environment staging)
printenv | grep POLA_APP | cut -d "=" -f 2- | xargs -n 1 -I {} echo "::add-mask::{}"
printenv | grep POLA_APP >> $GITHUB_ENV;
- run: ./run_dbt.sh dbt deps
- run: ./run_dbt.sh dbt build
- name: "Push image (push)"
if: github.event_name == 'push'
env:
PREPARE_BUILDX_CACHE: true
run: |
# Build cache
./scripts/bi-docker-image/build_image.sh
./scripts/bi-docker-image/push_image.sh