forked from trainindata/deploying-machine-learning-models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.yml
341 lines (318 loc) · 9.59 KB
/
config.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
version: '2.1'
orbs:
node: circleci/[email protected]
defaults: &defaults
docker:
- image: cimg/python:3.11.1
working_directory: ~/project
prepare_venv: &prepare_venv
run:
name: Create venv
command: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
prepare_tox: &prepare_tox
run:
name: Install tox
command: |
pip install --user tox
fetch_data: &fetch_data
run:
name: Set script permissions and fetch data
command: |
source venv/bin/activate
chmod +x ./scripts/fetch_kaggle_dataset.sh
./scripts/fetch_kaggle_dataset.sh
jobs:
section_07_test_app:
<<: *defaults
working_directory: ~/project/section-07-ci-and-publishing/house-prices-api
steps:
- checkout:
path: ~/project
- *prepare_tox
- run:
name: Runnning app tests
command: |
tox
section_07_deploy_app_to_railway:
<<: *defaults
steps:
- checkout:
path: ~/project/
- node/install:
node-version: '16.13'
- run: node --version
- run: npm i -g @railway/cli
- run:
name: Deploy to Railway App (You must set RAILWAY_TOKEN env var)
command: |
cd section-07-ci-and-publishing/house-prices-api && railway up --detach
section_07_test_and_upload_regression_model:
<<: *defaults
working_directory: ~/project/section-07-ci-and-publishing/model-package
steps:
- checkout:
path: ~/project
- *prepare_tox
- run:
name: Fetch the data
command: |
tox -e fetch_data
- run:
name: Test the model
command: |
tox
- run:
name: Publish model to Gemfury
command: |
tox -e publish_model
section_08_deploy_app_container_via_railway:
<<: *defaults
steps:
- setup_remote_docker:
# Supported versions: https://circleci.com/docs/2.0/building-docker-images/#docker-version
version: 20.10.18
- checkout:
path: ~/project/
- node/install:
node-version: '16.13'
- run: node --version
- run: npm i -g @railway/cli
- run:
name: Build and run Dockerfile (see https://docs.railway.app/deploy/dockerfiles)
command: |
cd section-08-deploying-with-containers && railway up --detach
test_regression_model_py37:
docker:
- image: circleci/python:3.7.6
working_directory: ~/project/packages/regression_model
steps:
- checkout:
path: ~/project
- run:
name: Run tests with Python 3.7
command: |
sudo pip install --upgrade pip
pip install --user tox
tox -e py37
test_regression_model_py38:
docker:
- image: circleci/python:3.8.0
working_directory: ~/project/packages/regression_model
steps:
- checkout:
path: ~/project
- run:
name: Run tests with Python 3.8
command: |
sudo pip install --upgrade pip
pip install --user tox
tox -e py38
test_ml_api_py37:
docker:
- image: circleci/python:3.7.6
working_directory: ~/project/packages/ml_api
steps:
- checkout:
path: ~/project
- run:
name: Run API tests with Python 3.7
command: |
sudo pip install --upgrade pip
pip install --user tox
tox -e py37
test_ml_api_py38:
docker:
- image: circleci/python:3.8.1
working_directory: ~/project/packages/ml_api
steps:
- checkout:
path: ~/project
- run:
name: Run API tests with Python 3.8
command: |
sudo pip install --upgrade pip
pip install --user tox
tox -e py38
train_and_upload_regression_model:
<<: *defaults
steps:
- checkout
- *prepare_venv
- run:
name: Install requirements
command: |
. venv/bin/activate
pip install -r packages/regression_model/requirements.txt
- *fetch_data
- run:
name: Train model
command: |
. venv/bin/activate
PYTHONPATH=./packages/regression_model python3 packages/regression_model/regression_model/train_pipeline.py
- run:
name: Publish model to Gemfury
command: |
. venv/bin/activate
chmod +x ./scripts/publish_model.sh
./scripts/publish_model.sh ./packages/regression_model/
section_9_differential_tests:
<<: *defaults
steps:
- checkout
- *prepare_venv
- run:
name: Capturing previous model predictions
command: |
. venv/bin/activate
pip install -r packages/ml_api/diff_test_requirements.txt
PYTHONPATH=./packages/ml_api python3 packages/ml_api/tests/capture_model_predictions.py
- run:
name: Runnning differential tests
command: |
. venv/bin/activate
pip install -r packages/ml_api/requirements.txt
py.test -vv packages/ml_api/tests -m differential
section_11_build_and_push_to_heroku_docker:
<<: *defaults
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run: docker login --username=$HEROKU_EMAIL --password=$HEROKU_API_KEY registry.heroku.com
- run:
name: Setup Heroku CLI
command: |
wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
- run:
name: Build and Push Image
command: |
make build-ml-api-heroku push-ml-api-heroku
- run:
name: Release to Heroku
command: |
heroku container:release web --app $HEROKU_APP_NAME
section_12_publish_docker_image_to_aws:
<<: *defaults
working_directory: ~/project/packages/ml_models
steps:
- checkout
- setup_remote_docker
- run:
name: Publishing docker image to aws ECR
command: |
sudo pip install awscli
eval $(aws ecr get-login --no-include-email --region us-east-1)
make build-ml-api-aws tag-ml-api push-ml-api-aws
aws ecs update-service --cluster ml-api-cluster --service custom-service --task-definition first-run-task-definition --force-new-deployment
section_13_train_and_upload_neural_network_model:
docker:
- image: circleci/python:3.6.4-stretch
working_directory: ~/project
steps:
- checkout
- *prepare_venv
- run:
name: Install requirements
command: |
. venv/bin/activate
pip install -r packages/neural_network_model/requirements.txt
- run:
name: Fetch Training data - 2GB
command: |
. venv/bin/activate
chmod +x ./scripts/fetch_kaggle_large_dataset.sh
./scripts/fetch_kaggle_large_dataset.sh
- run:
name: Train model
command: |
. venv/bin/activate
PYTHONPATH=./packages/neural_network_model python3 packages/neural_network_model/neural_network_model/train_pipeline.py
- run:
name: Publish model to Gemfury
command: |
. venv/bin/activate
chmod +x ./scripts/publish_model.sh
./scripts/publish_model.sh ./packages/neural_network_model/
tags_only: &tags_only
filters:
branches:
ignore: /.*/
tags:
only: /^.*/
workflows:
version: 2
deploy_pipeline:
jobs:
- section_07_test_app
- section_07_deploy_app_to_railway:
requires:
- section_07_test_app
filters:
branches:
only:
- master
- demo
# upload after git tags are created
- section_07_test_and_upload_regression_model:
<<: *tags_only
- section_08_deploy_app_container_via_railway:
filters:
branches:
only:
- master
- demo
# test-all:
# jobs:
# - test_regression_model_py36
# - test_regression_model_py37
# - test_regression_model_py38
# - test_ml_api_py36
# - test_ml_api_py37
# # - test_ml_api_py38 pending NN model update
# - section_9_differential_tests
# - train_and_upload_regression_model:
# requires:
# - test_regression_model_py36
# - test_regression_model_py37
# - test_regression_model_py38
# - test_ml_api_py36
# - test_ml_api_py37
# - section_9_differential_tests
# filters:
# branches:
# only:
# - master
# - section_10_deploy_to_heroku:
# requires:
# - train_and_upload_regression_model
# filters:
# branches:
# only:
# - master
# - section_11_build_and_push_to_heroku_docker:
# requires:
# - train_and_upload_regression_model
# filters:
# branches:
# only:
# - master
# - section_12_publish_docker_image_to_aws:
# requires:
# - train_and_upload_regression_model
# filters:
# branches:
# only:
# - master
# - section_13_train_and_upload_neural_network_model:
# requires:
# - test_regression_model
# - test_ml_api
# - section_9_differential_tests
# - train_and_upload_regression_model
# filters:
# branches:
# only:
# - master