Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit 347c776

Browse files
authored
Merge pull request #1 from Merlion-Crew/ml_model_uc76
UC-90: Build ML models container image to Nexus
2 parents 0a09d09 + 7097926 commit 347c776

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
pipeline {
2+
agent { label 'master' }
3+
environment {
4+
ML_IMAGE_FOLDER = 'imagefiles'
5+
IMAGE_NAME = 'mlmodelimage'
6+
MODEL_NAME = 'diabetes_regression_model.pkl'
7+
MODEL_VERSION = '1'
8+
SCORE_SCRIPT = 'scoring/score.py'
9+
RESOURCE_GROUP = "${RESOURCE_GROUP}"
10+
WORKSPACE_NAME = "${WORKSPACE_NAME}"
11+
ML_CONTAINER_REGISTRY = "${ML_CONTAINER_REGISTRY}"
12+
}
13+
stages {
14+
stage('initialize') {
15+
steps {
16+
echo 'Remove the previous one!'
17+
}
18+
post {
19+
always {
20+
deleteDir() /* clean up our workspace */
21+
}
22+
}
23+
}
24+
stage('generate_dockerfile') {
25+
steps {
26+
echo "Hello build ${env.BUILD_ID}"
27+
/*checkout scm*/
28+
checkout([$class: 'GitSCM', branches: [[name: '*/ml_model_uc76']],
29+
userRemoteConfigs: [[url: 'https://github.com/Merlion-Crew/MLOpsPython.git/']]])
30+
31+
azureCLI commands: [[exportVariablesString: '/id|SUBSCRIPTION_ID', script: "az account show"]], principalCredentialId: "${AZURE_SP}"
32+
33+
sh '''#!/bin/bash -ex
34+
source /home/azureuser/anaconda3/bin/activate mlopspython_ci
35+
python3 -m ml_service.util.create_scoring_image
36+
'''
37+
}
38+
}
39+
stage('build_and_push') {
40+
steps {
41+
echo "Build docker images"
42+
43+
sh '''#!/bin/bash -ex
44+
az acr login --name $ML_CONTAINER_REGISTRY
45+
docker build -t $NEXUS_DOCKER_REGISTRY_URL/$IMAGE_NAME:$BUILD_ID ./diabetes_regression/scoring/$ML_IMAGE_FOLDER/
46+
'''
47+
48+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'nexus-docker-repo',
49+
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
50+
51+
sh '''#!/bin/bash -ex
52+
docker login -u $USERNAME --password $PASSWORD https://$NEXUS_DOCKER_REGISTRY_URL
53+
docker push $NEXUS_DOCKER_REGISTRY_URL/$IMAGE_NAME:$BUILD_ID
54+
'''
55+
}
56+
}
57+
}
58+
}
59+
}

ml_service/util/create_scoring_image.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,19 @@
4040
scoring_env = Environment.from_conda_specification(name="scoringenv", file_path="conda_dependencies.yml") # NOQA: E501
4141
inference_config = InferenceConfig(
4242
entry_script=score_file, environment=scoring_env)
43-
package = Model.package(ws, [model], inference_config)
43+
44+
saved_package = os.environ.get("ML_IMAGE_FOLDER")
45+
saved_dockerfile = True
46+
if (saved_package is None):
47+
saved_dockerfile = False
48+
package = Model.package(ws, [model], inference_config, generate_dockerfile=saved_dockerfile)
49+
50+
4451
package.wait_for_creation(show_output=True)
52+
53+
if(saved_dockerfile):
54+
package.save(saved_package)
55+
4556
# Display the package location/ACR path
4657
print(package.location)
4758

0 commit comments

Comments
 (0)