-
Notifications
You must be signed in to change notification settings - Fork 65
357 lines (352 loc) · 12.6 KB
/
main.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
name: Python Continuous Integration
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
PNPM_VERSION: 8.5.1
PYTHON_VERSION: 3.10.13
NODE_VERSION: 18
AZURE_RESOURCE_GROUP_NAME: "azure-ml-yolo"
AZURE_LOCATION: "northeurope"
AZURE_ML_WORKSPACE_NAME: "cats-dogs-yola"
AZURE_WEBAPP_NAME: "cats-dogs-yola"
DELETE_WEBAPP: "false"
DOCKER_IMAGE_NAME: "guillaumechervetlunique/mlopspython"
permissions:
id-token: write
contents: write
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
id: filter_python
with:
filters: |
packages:
- 'packages/**'
production:
- 'production/**'
train:
- 'train/**'
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Poetry dependencies
run: |
python -m pip install --upgrade pip
pip install --user poetry
- name: Format with Black
run: |
poetry install
poetry run black train
poetry run black train --check
- name: Lint with flake8
run: |
poetry install
poetry run flake8 .
packages_unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --user poetry
- name: Run unit tests Packages Extraction
working-directory: packages/extraction
run: |
poetry install
poetry run coverage run -m unittest tests.extraction_tests
poetry run coverage report
- name: Run unit tests Packages Inference
working-directory: packages/inference
run: |
poetry install
#poetry run coverage run -m unittest tests.inference_tests
#poetry run coverage report
train_unit_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --user poetry
- name: Build packages
run: |
chmod +x ./Makefile
./Makefile
- name: Run unit tests Extraction
working-directory: train/extraction
run: |
poetry lock
poetry install
#poetry run coverage run -m unittest tests.extraction_test
#poetry run coverage report
- name: Run unit tests Label Split Data
working-directory: train/label_split_data
run: |
poetry lock
poetry install
poetry run coverage run -m unittest tests.label_split_data_test
poetry run coverage report
#- name: Run unit tests Train
# working-directory: train/train
# run: |
# poetry install --dev
# poetry run python -m unittest tests.train_test
#- name: Run unit tests Evaluate
# working-directory: train/test
# run: |
# poetry install --dev
# poetry run python -m unittest tests.evaluate_test
tags:
runs-on: ubuntu-latest
needs: [train_unit_tests, packages_unit_tests]
outputs:
new_version: ${{ steps.tag.outputs.new_version }}
steps:
- uses: actions/checkout@v3
- name: Bump version and push tag
id: tag_version
if: github.ref == 'refs/heads/main'
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Add tag to output step for main branch
id: tag
run: |
if [ '${{ github.ref }}' = 'refs/heads/main' ]; then
echo "new_version=${{ steps.tag_version.outputs.new_version }}" >> $GITHUB_OUTPUT
else
echo "new_version=pr-${{ github.event.number }}-${{ github.run_number }}" >> $GITHUB_OUTPUT
fi
train:
runs-on: ubuntu-latest
environment: MLOpsPython
needs: tags
outputs:
MODEL_VERSION: ${{ steps.train.outputs.MODEL_VERSION }}
INTEGRATION_DATASET_VERSION: ${{ steps.train.outputs.INTEGRATION_DATASET_VERSION }}
EXPERIMENT_ID: ${{ steps.train.outputs.EXPERIMENT_ID }}
AZURE_RESOURCE_GROUP_NAME: ${{ env.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ML_WORKSPACE_NAME: ${{ env.AZURE_ML_WORKSPACE_NAME }}
DOCKER_IMAGE_NAME: ${{ env.DOCKER_IMAGE_NAME }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --user poetry
- name: Build packages
run: |
chmod +x ./Makefile
./Makefile
- name: azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run Train Pipeline
run: |
poetry install
az extension add -n ml
az group create --name ${{ env.AZURE_RESOURCE_GROUP_NAME }} --location ${{ env.AZURE_LOCATION }}
az ml workspace create -n ${{ env.AZURE_ML_WORKSPACE_NAME }} -g ${{ env.AZURE_RESOURCE_GROUP_NAME }}
cwd=$(pwd)
cd ./extraction
chmod +x ./init_dataset.sh
./init_dataset.sh ${{ env.AZURE_RESOURCE_GROUP_NAME }} ${{ env.AZURE_ML_WORKSPACE_NAME }}
cd $cwd
cd ./label_split_data
chmod +x ./init_dataset.sh
./init_dataset.sh ${{ env.AZURE_RESOURCE_GROUP_NAME }} ${{ env.AZURE_ML_WORKSPACE_NAME }}
cd $cwd
#poetry run python azureml_run_test.py > train_output.txt
poetry run python azureml_run_pipeline.py \
--subscription_id ${{ secrets.AZURE_SUBSCRIPTION_ID }} \
--resource_group_name ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
--workspace_name ${{ env.AZURE_ML_WORKSPACE_NAME }} \
--location ${{ env.AZURE_LOCATION }} \
--tags "{\"triggering_actor\":\"${{github.triggering_actor}}\"}" \
> train_output.txt
cat train_output.txt
working-directory: train
- name: download model
id: train
run: |
az extension add -n ml
MODEL_VERSION=$(python bin/retrieve_output.py ./train/train_output.txt model_version)
echo "MODEL_VERSION=$MODEL_VERSION" >> $GITHUB_OUTPUT
INTEGRATION_DATASET_VERSION=$(python bin/retrieve_output.py ./train/train_output.txt integration_dataset_version)
echo "INTEGRATION_DATASET_VERSION=$INTEGRATION_DATASET_VERSION" >> $GITHUB_OUTPUT
EXPERIMENT_ID=$(python bin/retrieve_output.py ./train/train_output.txt experiment_id)
echo "EXPERIMENT_ID=$EXPERIMENT_ID" >> $GITHUB_OUTPUT
mkdir model
rm -r model
mkdir model
cd model
az ml model download --name cats-dogs-others --version $MODEL_VERSION --resource-group ${{ env.AZURE_RESOURCE_GROUP_NAME }} --workspace-name ${{ env.AZURE_ML_WORKSPACE_NAME }}
# find files recursively and copy them to the current directory root
find ./ -name '*.keras' -exec cp "{}" ./ \;
find ./ -name '*.json' -exec cp "{}" ./ \;
rm -r ./cats-dogs-others
- name: Upload Model Build Artifact
uses: actions/upload-artifact@v2
with:
name: Publish model
path: ./model
- name: release
uses: actions/create-release@v1
id: create_release
if: github.ref == 'refs/heads/main'
with:
draft: false
prerelease: false
body: |
${{ needs.tags.outputs.changelog }}
release_name: "v${{ needs.tags.outputs.new_version }}"
tag_name: "v${{ needs.tags.outputs.new_version }}"
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Zip Release
uses: TheDoctor0/[email protected]
with:
filename: mlopspython_model.zip
path: .
directory: ./model
- name: upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./model/mlopspython_model.zip
asset_name: mlopspython_model.zip
asset_content_type: application/zip
build_docker:
needs: [train, tags]
uses: ./.github/workflows/docker.yml
with:
image_name: ${{ needs.train.outputs.DOCKER_IMAGE_NAME }}
image_version: ${{ needs.tags.outputs.new_version }}
image_build_args: ""
image_context: ./production/api
image_file: "./production/api/Dockerfile"
model_version: ${{ needs.train.outputs.MODEL_VERSION }}
resource_group: ${{ needs.train.outputs.AZURE_RESOURCE_GROUP_NAME }}
workspace_name: ${{ needs.train.outputs.AZURE_ML_WORKSPACE_NAME }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
deploy:
environment: MLOpsPython
runs-on: ubuntu-latest
needs: [tags, build_docker]
steps:
- name: azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy container
run: |
# https://learn.microsoft.com/en-us/cli/azure/container?view=azure-cli-latest#az-container-create()
az container create --resource-group ${{ env.AZURE_RESOURCE_GROUP_NAME}} --name ${{ env.AZURE_WEBAPP_NAME }} --dns-name-label ${{ env.AZURE_WEBAPP_NAME }} --image docker.io/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.tags.outputs.new_version }} --ports 5000
integration_tests:
environment: MLOpsPython
runs-on: ubuntu-latest
needs: [deploy, train]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --user poetry
- name: azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run Integration Test
working-directory: production/integration
run: |
poetry install
az extension add -n ml
poetry run python azureml_run_pipeline.py \
--subscription_id ${{ env.AZURE_SUBSCRIPTION_ID }} \
--resource_group_name ${{ env.AZURE_RESOURCE_GROUP_NAME }} \
--workspace_name ${{ env.AZURE_ML_WORKSPACE_NAME }} \
--experiment_id ${{ needs.train.outputs.EXPERIMENT_ID }} \
--integration_dataset_name "cats-dogs-others-integration" \
--integration_dataset_version ${{ needs.train.outputs.INTEGRATION_DATASET_VERSION }} \
--url "http://${{ env.AZURE_WEBAPP_NAME }}.${{ env.AZURE_LOCATION }}.azurecontainer.io:5000/upload" > integration_output.txt
cat integration_output.txt
- name: Delete Environment
run: |
if [ "${{ env.DELETE_WEBAPP }}" = "true" ]; then
az container delete --resource-group ${{ env.AZURE_RESOURCE_GROUP_NAME}} --name ${{ env.AZURE_WEBAPP_NAME }} --yes
fi
webapp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: dorny/paths-filter@v2
id: filter_webapp
with:
filters: |
webapp:
- 'webapp/**'
- uses: actions/setup-node@v2
with:
node-version: '18'
- name: Build webapp
working-directory: production/webapp
run: |
npm ci
npm run build
- name: Upload WebApp Build Artifact
uses: actions/upload-artifact@v2
with:
name: Publish webapp
path: ./production/webapp/build