Skip to content

Commit da4344d

Browse files
authored
Merge pull request #158 from ositanachi/patch-1
Patch 1
2 parents 7d07de0 + 7159a95 commit da4344d

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

articles/machine-learning/how-to-connection.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,126 @@ wps_connection = WorkspaceConnection(
539539
ml_client.connections.create_or_update(workspace_connection=wps_connection)
540540
```
541541

542+
---
543+
544+
### Generic Container Registry
545+
546+
Using the GenericContainerRegistry workspace connection, you can specify an external registry, such as Nexus or Artifactory, for image builds. Environment images will be pushed and served from the specified registry, and the previous cache will be ignored.
547+
548+
# [Azure CLI](#tab/cli)
549+
550+
Create a connection using the following YAML files. Be sure to update the appropriate values:
551+
```yml
552+
#myenv.yml
553+
$schema: https://azuremlschemas.azureedge.net/latest/environment.schema.json
554+
name: docker-image-plus-conda-example
555+
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04
556+
type: python_feed
557+
conda_file: conda_dep.yml
558+
description: Environment created from a Docker image plus Conda environment
559+
```
560+
561+
```yml
562+
#conda_dep.yml
563+
name: project_environment
564+
dependencies:
565+
- python=3.10
566+
- pip:
567+
- azureml-defaults
568+
channels:
569+
- anaconda
570+
- conda-forge
571+
```
572+
573+
```yml
574+
#connection.yml
575+
name: ws_conn_generic_container_registry
576+
type: container_registry
577+
target: https://test-registry.com
578+
credentials:
579+
type: username_password
580+
username: contoso
581+
password: pass
582+
```
583+
584+
```yml
585+
#hello_world_job.yml
586+
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
587+
command: echo "hello world"
588+
environment: azureml:<env name>@latest
589+
```
590+
591+
Create connection from YAML file with your credentials:
592+
593+
```azurecli
594+
az ml connection create --file connection.yaml --credentials username=<username> password=<password> --resource-group my-resource-group --workspace-name my-workspace
595+
```
596+
597+
Create environment
598+
599+
```azurecli
600+
az ml environment create --name my-env --version 1 --file my_env.yml --conda-file conda_dep.yml --image mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04 --resource-group my-resource-group --workspace-name my-workspace
601+
```
602+
603+
You can verify that the environment was successfully created
604+
605+
```azurecli
606+
az ml environment show --name my-env --version 1 --resource-group my-resource-group --workspace-name my-workspace
607+
```
608+
609+
# [Python SDK](#tab/python)
610+
611+
The following example creates an Azure Container Registry connection. A managed identity authenticates this connection:
612+
613+
```python
614+
import os
615+
from azure.ai.ml import MLClient
616+
from azure.identity import DefaultAzureCredential
617+
from azure.ai.ml.entities import Environment
618+
from azure.ai.ml.entities import WorkspaceConnection
619+
from azure.ai.ml.entities import UsernamePasswordConfiguration
620+
from azureml.core.conda_dependencies import CondaDependencies
621+
from azure.ai.ml import command
622+
623+
# Enter details of AML workspace
624+
subscription_id = "<SUBSCRIPTION_ID>"
625+
resource_group = "<RESOURCE_GROUP>"
626+
workspace = "<AML_WORKSPACE_NAME>"
627+
628+
ml_client = MLClient( DefaultAzureCredential(), subscription_id, resource_group, workspace)
629+
# Fetching secrets from env var to secure access, these secrets can be set outside or source code
630+
registry_username = os.environ["REGISTRY_USERNAME"]
631+
registry_password = os.environ["REGISTRY_PASSWORD"]
632+
credentials = UsernamePasswordConfiguration(username= registry_username, password= registry_password)
633+
634+
# Create GenericContainerRegistry workspace connection for a generic registry
635+
ws_connection = WorkspaceConnection(name="<name>", target="<target>", type="GenericContainerRegistry", credentials=credentials)
636+
ml_client.connections.create_or_update(ws_connection)
637+
638+
# Create an environment
639+
env_docker_conda = Environment(image="<base image>", conda_file="<yml file>", name="docker-image-plus-conda-example", description="Environment created from a Docker image plus Conda environment.")
640+
ml_client.environments.create_or_updat(env_docker_conda)
641+
642+
job = command(command="echo 'hello world'", environment=env_docker_conda,display_name="v2-job-example")
643+
returned_job = ml_client.create_or_update(job)
644+
```
645+
646+
# [Studio](#tab/azure-studio)
647+
648+
1. Navigate to the [Azure Machine Learning studio](https://ml.azure.com/).
649+
650+
1. Under **Manage** in the left navigation, select **Connections** and then select **Create**.
651+
652+
:::image type="content" source="media/how-to-connection/how-to-manage-connections-create.png" lightbox="media/how-to-connection/create-new-data-connection.png" alt-text="Screenshot showing the start of creating a new connection in Azure Machine Learning studio UI.":::
653+
654+
1. Under **Other resources types**, select **Generic Container Registry*
655+
:::image type="content" source="media/how-to-connection/how-to-connect-generic-container-registry.png" lightbox="media/how-to-connection/create-new-data-connection.png" alt-text="Screenshot highlighting the option to connect to a generic container registry in Azure Machine Learning studio UI.":::
656+
657+
1. Input the required information, and then select **Add connection**
658+
:::image type="content" source="media/how-to-connection/how-to-connect-add-connection.png" lightbox="media/how-to-connection/create-new-data-connection.png" alt-text="Screenshot showing the input fields for connecting to a generic container registry in Azure Machine Learning studio UI.":::
659+
660+
---
661+
542662
## Related content
543663

544664
If you use a data connection (Snowflake DB, Amazon S3, or Azure SQL DB), these articles offer more information:
293 KB
Loading
396 KB
Loading
274 KB
Loading

0 commit comments

Comments
 (0)