Skip to content

Commit e0e6d22

Browse files
authored
Tox + code coverage (#150)
1 parent 57ef170 commit e0e6d22

16 files changed

+88
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ coverage.xml
4747
*.cover
4848
.hypothesis/
4949
.pytest_cache/
50+
*-testresults.xml
51+
test-output.xml
5052

5153
# Translations
5254
*.mo

.pipelines/azdo-base-pipeline.yml

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
# this pipeline should be ignored for now
2-
parameters:
3-
pipelineType: 'training'
4-
51
steps:
62
- script: |
7-
flake8 --output-file=$(Build.BinariesDirectory)/lint-testresults.xml --format junit-xml
8-
workingDirectory: '$(Build.SourcesDirectory)'
9-
displayName: 'Run code quality tests'
10-
enabled: 'true'
11-
12-
- script: |
13-
python -m pytest --junitxml=$(Build.BinariesDirectory)/unit-testresults.xml $(Build.SourcesDirectory)/tests/unit
14-
displayName: 'Run unit tests'
15-
enabled: 'true'
16-
env:
17-
SP_APP_SECRET: '$(SP_APP_SECRET)'
3+
./lint-and-test.sh
4+
displayName: 'Linting & unit tests'
185

196
- task: PublishTestResults@2
207
condition: succeededOrFailed()
218
inputs:
22-
testResultsFiles: '$(Build.BinariesDirectory)/*-testresults.xml'
9+
testResultsFiles: '*-testresults.xml'
2310
testRunTitle: 'Linting & Unit tests'
2411
failTaskOnFailedTests: true
25-
displayName: 'Publish linting and unit test results'
26-
enabled: 'true'
12+
displayName: 'Publish test results'
13+
14+
- task: PublishCodeCoverageResults@1
15+
displayName: 'Publish coverage report'
16+
condition: succeededOrFailed()
17+
inputs:
18+
codeCoverageTool: Cobertura
19+
summaryFileLocation: 'coverage.xml'
20+
reportDirectory: 'htmlcov'
21+
failIfCoverageEmpty: true

.pipelines/azdo-pr-build-train.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ pr:
44
include:
55
- master
66

7-
pool:
7+
pool:
88
vmImage: 'ubuntu-latest'
99

1010
container: mcr.microsoft.com/mlops/python:latest
1111

12-
1312
variables:
1413
- template: diabetes_regression-variables.yml
1514
- group: devopsforai-aml-vg
1615

17-
1816
steps:
1917
- template: azdo-base-pipeline.yml

.pipelines/diabetes_regression-ci-build-train.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ variables:
1414
- template: diabetes_regression-variables.yml
1515
- group: devopsforai-aml-vg
1616

17+
pool:
18+
vmImage: ubuntu-latest
1719

1820
stages:
1921
- stage: 'Model_CI'
2022
displayName: 'Model CI'
2123
jobs:
2224
- job: "Model_CI_Pipeline"
2325
displayName: "Model CI Pipeline"
24-
pool:
25-
vmImage: 'ubuntu-latest'
2626
container: mcr.microsoft.com/mlops/python:latest
2727
timeoutInMinutes: 0
2828
steps:
@@ -45,8 +45,6 @@ stages:
4545
- job: "Get_Pipeline_ID"
4646
condition: and(succeeded(), eq(coalesce(variables['auto-trigger-training'], 'true'), 'true'))
4747
displayName: "Get Pipeline ID for execution"
48-
pool:
49-
vmImage: 'ubuntu-latest'
5048
container: mcr.microsoft.com/mlops/python:latest
5149
timeoutInMinutes: 0
5250
steps:
@@ -92,8 +90,6 @@ stages:
9290
dependsOn: "Run_ML_Pipeline"
9391
condition: always()
9492
displayName: "Determine if evaluation succeeded and new model is registered"
95-
pool:
96-
vmImage: 'ubuntu-latest'
9793
container: mcr.microsoft.com/mlops/python:latest
9894
timeoutInMinutes: 0
9995
steps:
@@ -105,8 +101,6 @@ stages:
105101
jobs:
106102
- job: "Deploy_ACI"
107103
displayName: "Deploy to ACI"
108-
pool:
109-
vmImage: 'ubuntu-latest'
110104
container: mcr.microsoft.com/mlops/python:latest
111105
timeoutInMinutes: 0
112106
steps:
@@ -140,8 +134,6 @@ stages:
140134
jobs:
141135
- job: "Deploy_AKS"
142136
displayName: "Deploy to AKS"
143-
pool:
144-
vmImage: 'ubuntu-latest'
145137
container: mcr.microsoft.com/mlops/python:latest
146138
timeoutInMinutes: 0
147139
steps:
@@ -176,8 +168,6 @@ stages:
176168
jobs:
177169
- job: "Deploy_Webapp"
178170
displayName: "Deploy to Webapp"
179-
pool:
180-
vmImage: 'ubuntu-latest'
181171
container: mcr.microsoft.com/mlops/python:latest
182172
timeoutInMinutes: 0
183173
steps:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This reference architecture shows how to implement continuous integration (CI),
5555

5656
Once you have registered your ML model, you can use Azure ML + Azure DevOps to deploy it.
5757

58-
[Azure DevOps release pipeline](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops) packages the new model along with the scoring file and its python dependencies into a [docker image](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-azure-machine-learning-architecture#image) and pushes it to [Azure Container Registry](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-intro). This image is used to deploy the model as [web service](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-azure-machine-learning-architecture#web-service) across QA and Prod environments. The QA environment is running on top of [Azure Container Instances (ACI)](https://azure.microsoft.com/en-us/services/container-instances/) and the Prod environment is built with [Azure Kubernetes Service (AKS)](https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes).
58+
The [Azure DevOps multi-stage pipeline](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml) packages the new model along with the scoring file and its python dependencies into a [docker image](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-azure-machine-learning-architecture#image) and pushes it to [Azure Container Registry](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-intro). This image is used to deploy the model as [web service](https://docs.microsoft.com/en-us/azure/machine-learning/service/concept-azure-machine-learning-architecture#web-service) across QA and Prod environments. The QA environment is running on top of [Azure Container Instances (ACI)](https://azure.microsoft.com/en-us/services/container-instances/) and the Prod environment is built with [Azure Kubernetes Service (AKS)](https://docs.microsoft.com/en-us/azure/aks/intro-kubernetes).
5959

6060

6161
### Repo Details

diabetes_regression/scoring/score.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def run(data, request_headers):
7979
request_headers.get("X-Ms-Request-Id", ""),
8080
request_headers.get("Traceparent", ""),
8181
len(result)
82-
))
82+
))
8383

8484
return {"result": result.tolist()}
8585

diabetes_regression/training/R/train_with_r_on_databricks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
args, unknown = parser.parse_known_args()
1212
folder = args.AZUREML_SCRIPT_DIRECTORY_NAME
1313

14-
os.system("cd " + "/dbfs/" + folder +
15-
" && Rscript r_train.r && ls -ltr model.rds")
14+
os.system("cd " + "/dbfs/" + folder
15+
+ " && Rscript r_train.r && ls -ltr model.rds")

docs/development_setup.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Development environment setup
2+
3+
### Setup
4+
5+
Please be aware that the local environment also needs access to the Azure subscription so you have to have Contributor access on the Azure ML Workspace.
6+
7+
In order to configure the project locally, create a copy of `.env.example` in the root directory and name it `.env`. Fill out all missing values and adjust the existing ones to suit your requirements.
8+
9+
### Installation
10+
11+
[Install the Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). The Azure CLI will be used to log you in interactively.
12+
13+
Create a virtual environment using [venv](https://docs.python.org/3/library/venv.html), [conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) or [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv).
14+
15+
Here is an example for setting up and activating a `venv` environment with Python 3:
16+
17+
```
18+
python3 -mvenv .venv
19+
source .venv/bin/activate
20+
```
21+
22+
Install the required Python modules in your virtual environment.
23+
24+
```
25+
pip install -r environment_setup/requirements.txt
26+
```
27+
28+
### Running local code
29+
30+
To run your local ML pipeline code on Azure ML, run a command such as the following (in bash, all on one line):
31+
32+
```
33+
export BUILD_BUILDID=$(uuidgen); python ml_service/pipelines/build_train_pipeline.py && python ml_service/pipelines/run_train_pipeline.py
34+
```
35+
36+
BUILD_BUILDID is a variable used to uniquely identify the ML pipeline between the
37+
`build_train_pipeline.py` and `run_train_pipeline.py` scripts. In Azure DevOps it is
38+
set to the current build number. In a local environment, we can use a command such as
39+
`uuidgen` so set a different random identifier on each run, ensuring there are
40+
no collisions.
41+
42+
### Local testing
43+
44+
Before committing, run `tox` to execute linter and unit test checks.

docs/getting_started.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ There are more variables used in the project. They're defined in two places, one
8080

8181
### Local configuration
8282

83-
In order to configure the project locally, create a copy of `.env.example` in the root directory and name it `.env`. Fill out all missing values and adjust the existing ones to suit your requirements.
84-
85-
For local development, you will also need to [install the Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). The Azure CLI will be used to log you in interactively.
86-
Please be aware that the local environment also needs access to the Azure subscription so you have to have Contributor access on the Azure ML Workspace.
83+
For instructions on how to set up a local development environment, refer to the [Development environment setup instructions](development_setup.md).
8784

8885
### Azure DevOps configuration
8986

environment_setup/install_requirements.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@
2626

2727

2828
python --version
29-
pip install azure-cli==2.0.46
30-
pip install --upgrade azureml-sdk[cli]
3129
pip install -r requirements.txt

0 commit comments

Comments
 (0)