Skip to content

Commit 0fd052e

Browse files
authored
Update Image creation to use new package (#260)
Update Image creation to use the new package
1 parent 9459616 commit 0fd052e

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed
+13-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import os
22
import argparse
33
from azureml.core import Workspace
4-
from azureml.core.image import ContainerImage, Image
5-
from azureml.core.model import Model
4+
from azureml.core.environment import Environment
5+
from azureml.core.model import Model, InferenceConfig
66
import shutil
77
from ml_service.util.env_variables import Env
88

@@ -36,37 +36,24 @@
3636
shutil.copy(os.path.join(".", sources_dir,
3737
"conda_dependencies.yml"), path_to_scoring)
3838
os.chdir(path_to_scoring)
39-
image_config = ContainerImage.image_configuration(
40-
execution_script=score_file,
41-
runtime="python",
42-
conda_file="conda_dependencies.yml",
43-
description="Image with ridge regression model",
44-
tags={"area": "diabetes_regression"},
45-
)
4639

47-
image = Image.create(
48-
name=e.image_name, models=[
49-
model], image_config=image_config, workspace=ws
50-
)
40+
scoring_env = Environment.from_conda_specification(name="scoringenv", file_path="conda_dependencies.yml") # NOQA: E501
41+
inference_config = InferenceConfig(
42+
entry_script=score_file, environment=scoring_env)
43+
package = Model.package(ws, [model], inference_config)
44+
package.wait_for_creation(show_output=True)
45+
# Display the package location/ACR path
46+
print(package.location)
5147

5248
os.chdir(cwd)
5349

54-
image.wait_for_creation(show_output=True)
55-
56-
if image.creation_state != "Succeeded":
57-
raise Exception("Image creation status: {image.creation_state}")
50+
if package.state != "Succeeded":
51+
raise Exception("Image creation status: {package.creation_state}")
5852

59-
print("{}(v.{} [{}]) stored at {} with build log {}".format(
60-
image.name,
61-
image.version,
62-
image.creation_state,
63-
image.image_location,
64-
image.image_build_log_uri,
65-
)
66-
)
53+
print("Package stored at {} with build log {}".format(package.location, package.package_build_log_uri)) # NOQA: E501
6754

6855
# Save the Image Location for other AzDO jobs after script is complete
6956
if args.output_image_location_file is not None:
7057
print("Writing image location to %s" % args.output_image_location_file)
7158
with open(args.output_image_location_file, "w") as out_file:
72-
out_file.write(str(image.image_location))
59+
out_file.write(str(package.location))

0 commit comments

Comments
 (0)