You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get started with [GitHub Actions](https://docs.github.com/en/actions) to train a model on Azure Machine Learning.
18
18
19
-
This article will teach you how to create an GitHub Actions workflow that builds and deploys a machine learning model to [Azure Machine Learning](/azure/machine-learning/overview-what-is-azure-machine-learning). You'll train a scikit-learn linear regression model on the NYC Taxi dataset.
19
+
> [!NOTE]
20
+
> GitHub Actions for Azure Machine Learning are provided as-is, and are not fully supported by Microsoft. If you encounter problems with a specific action, open an issue in the repository for the action. For example, if you encounter a problem with the aml-deploy action, report the problem in the [https://github.com/Azure/aml-deploy](https://github.com/Azure/aml-deploy) repo.
20
21
21
-
This tutorial uses [Azure Machine Learning Python SDK v2](/python/api/overview/azure/ml/installv2), which is in public preview, and [Azure CLI ML extension v2](/cli/azure/ml).
22
+
## Prerequisites
22
23
23
-
GitHub Actions uses a workflow YAML (.yml) file in the `/.github/workflows/` path in your repository. This definition contains the various steps and parameters that make up the workflow.
24
+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
25
+
- A GitHub account. If you don't have one, sign up for [free](https://github.com/join).
24
26
27
+
## Workflow file overview
25
28
26
-
## Prerequisites
29
+
A workflow is defined by a YAML (.yml) file in the `/.github/workflows/` path in your repository. This definition contains the various steps and parameters that make up the workflow.
27
30
28
-
- Complete the [Quickstart: Get started with Azure Machine Learning](/azure/machine-learning/quickstart-create-resources) to:
29
-
- Create a workspace
30
-
- Create a cloud-based compute instance to use for your development environment
31
-
- Create a cloud-based compute cluster to use for training your model. The cluster should have the name `cpu-cluster`
32
-
- Have a GitHub account. If you don't have one, sign up for [free](https://github.com/join).
31
+
The file has four sections:
33
32
34
-
## Step 1: Get the code
33
+
|Section |Tasks |
34
+
|---------|---------|
35
+
|**Authentication**| 1. Define a service principal. <br /> 2. Create a GitHub secret. |
36
+
|**Connect**| 1. Connect to the machine learning workspace. <br /> 2. Connect to a compute target. |
37
+
|**Job**| 1. Submit a training job. |
38
+
|**Deploy**| 1. Register model in Azure Machine Learning registry. 1. Deploy the model. |
35
39
36
-
Fork the following repo at GitHub:
40
+
## Create repository
37
41
38
-
```
39
-
https://github.com/azure/azureml-examples
40
-
```
42
+
Create a new repository off the [ML Ops with GitHub Actions and Azure Machine Learning template](https://github.com/machine-learning-apps/ml-template-azure).
41
43
42
-
## Step 2: Authenticate with Azure
44
+
1. Open the [template](https://github.com/machine-learning-apps/ml-template-azure) on GitHub.
45
+
2. Select **Use this template**.
43
46
44
-
To authenticate, you'll define how to authenticate with Azure. You can use a service principal or OpenID Connect.
47
+
:::image type="content" source="media/how-to-github-actions-machine-learning/gh-actions-use-template.png" alt-text="Select use this template":::
48
+
3. Create a new repository from the template. Set the repository name to `ml-learning` or a name of your choice.
45
49
46
-
### Generate deployment credentials
47
50
48
-
#[Service principal](#tab/userlevel)
51
+
## Generate deployment credentials
49
52
50
-
Create a [service principal](../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) with the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command in the [Azure CLI](/cli/azure/). Run this command with [Azure Cloud Shell](https://shell.azure.com/) in the Azure portal or by selecting the **Try it** button.
53
+
You can create a [service principal](../active-directory/develop/app-objects-and-service-principals.md#service-principal-object) with the [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac) command in the [Azure CLI](/cli/azure/). Run this command with [Azure Cloud Shell](https://shell.azure.com/) in the Azure portal or by selecting the **Try it** button.
51
54
52
55
```azurecli-interactive
53
56
az ad sp create-for-rbac --name "myML" --role contributor \
@@ -67,91 +70,12 @@ In the example above, replace the placeholders with your subscription ID, resour
67
70
}
68
71
```
69
72
70
-
# [OpenID Connect](#tab/openid)
71
-
72
-
OpenID Connect is an authentication method that uses short-lived tokens. Setting up [OpenID Connect with GitHub Actions](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect) is more complex process that offers hardened security.
73
-
74
-
1. If you do not have an existing application, register a [new Active Directory application and service principal that can access resources](../../active-directory/develop/howto-create-service-principal-portal.md). Create the Active Directory application.
75
-
76
-
```azurecli-interactive
77
-
az ad app create --display-name myApp
78
-
```
79
-
80
-
This command will output JSON with an `appId` that is your `client-id`. Save the value to use as the `AZURE_CLIENT_ID` GitHub secret later.
81
-
82
-
You will use the `objectId` value when creating federated credentials with Graph API and reference it as the `APPLICATION-OBJECT-ID`.
83
-
84
-
1. Create a service principal. Replace the `$appID` with the appId from your JSON output.
85
-
86
-
This command generates JSON output with a different `objectId` and will be used in the next step. The new `objectId` is the `assignee-object-id`.
87
-
88
-
Copy the `appOwnerTenantId` to use as a GitHub secret for `AZURE_TENANT_ID` later.
89
-
90
-
```azurecli-interactive
91
-
az ad sp create --id $appId
92
-
```
93
-
94
-
1. Create a new role assignment by subscription and object. By default, the role assignment will be tied to your default subscription. Replace `$subscriptionId` with your subscription ID, `$resourceGroupName` with your resource group name, and `$assigneeObjectId` with the generated `assignee-object-id`. Learn [how to manage Azure subscriptions with the Azure CLI](/cli/azure/manage-azure-subscriptions-azure-cli).
95
-
96
-
```azurecli-interactive
97
-
az role assignment create --role contributor --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName --subscription $subscriptionId --assignee-object-id $assigneeObjectId --assignee-principal-type ServicePrincipal
98
-
```
99
-
100
-
1. Run the following command to [create a new federated identity credential](/graph/api/application-post-federatedidentitycredentials?view=graph-rest-beta&preserve-view=true) for your active directory application.
101
-
102
-
* Replace `APPLICATION-OBJECT-ID` with the **objectId (generated while creating app)** for your Active Directory application.
103
-
* Set a value for `CREDENTIAL-NAME` to reference later.
104
-
* Set the `subject`. The value of this is defined by GitHub depending on your workflow:
105
-
* Jobs in your GitHub Actions environment: `repo:< Organization/Repository >:environment:< Name >`
106
-
* For Jobs not tied to an environment, include the ref path for branch/tag based on the ref path used for triggering the workflow: `repo:< Organization/Repository >:ref:< ref path>`. For example, `repo:n-username/ node_express:ref:refs/heads/my-branch` or `repo:n-username/ node_express:ref:refs/tags/my-tag`.
107
-
* For workflows triggered by a pull request event: `repo:< Organization/Repository >:pull_request`.
108
-
109
-
```azurecli
110
-
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:organization/repository:ref:refs/heads/main","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
111
-
```
112
-
113
-
To learn how to create a Create an active directory application, service principal, and federated credentials in Azure portal, see [Connect GitHub and Azure](/azure/developer/github/connect-from-azure#use-the-azure-login-action-with-openid-connect).
114
-
115
-
---
116
-
117
-
### Create secrets
118
-
119
-
# [Service principal](#tab/userlevel)
73
+
## Configure the GitHub secret
120
74
121
75
1. In [GitHub](https://github.com/), browse your repository, select **Settings > Secrets > Add a new secret**.
122
76
123
77
2. Paste the entire JSON output from the Azure CLI command into the secret's value field. Give the secret the name `AZURE_CREDENTIALS`.
124
78
125
-
# [OpenID Connect](#tab/openid)
126
-
127
-
---
128
-
129
-
The file has four sections:
130
-
131
-
|Section |Tasks |
132
-
|---------|---------|
133
-
|**Authentication** | 1. Define a service principal. <br /> 2. Create a GitHub secret. |
134
-
|**Connect** | 1. Connect to the machine learning workspace. <br /> 2. Connect to a compute target. |
135
-
|**Run** | 1. Submit a training run. |
136
-
|**Deploy** | 1. Register model in Azure Machine Learning registry. 1. Deploy the model. |
137
-
138
-
## Create repository
139
-
140
-
<!-- TODO: Replace with Clone https://github.com/Azure/azureml-examples/ -->
141
-
142
-
Create a new repository off the [ML Ops with GitHub Actions and Azure Machine Learning template](https://github.com/machine-learning-apps/ml-template-azure).
143
-
144
-
1. Open the [template](https://github.com/machine-learning-apps/ml-template-azure) on GitHub.
145
-
2. Select **Use this template**.
146
-
147
-
:::image type="content" source="media/how-to-github-actions-machine-learning/gh-actions-use-template.png" alt-text="Select use this template":::
148
-
3. Create a new repository from the template. Set the repository name to `ml-learning` or a name of your choice.
149
-
150
-
151
-
152
-
153
-
<!--TODO: Update setup.sh file in CLI, all 3 attributes -->
154
-
<!--TODO: Update compute-cluster in pipeline.yml OR give computer cluster name cpu-cluster -->
155
79
## Connect to the workspace
156
80
157
81
Use the **Azure Machine Learning Workspace action** to connect to your Azure Machine Learning workspace.
@@ -188,7 +112,7 @@ Use the [Azure Machine Learning Compute action](https://github.com/Azure/aml-com
Use the [Azure Machine Learning Training action](https://github.com/Azure/aml-run) to submit a ScriptRun, an Estimator or a Pipeline to Azure Machine Learning.
194
118
@@ -299,4 +223,5 @@ When your resource group and repository are no longer needed, clean up the resou
299
223
## Next steps
300
224
301
225
> [!div class="nextstepaction"]
302
-
> [Create and run machine learning pipelines with Azure Machine Learning SDK](./how-to-create-machine-learning-pipelines.md)
226
+
> [Learning path: End-to-end MLOps with Azure Machine Learning](/learn/paths/build-first-machine-operations-workflow/)
227
+
> [Create and run machine learning pipelines with Azure Machine Learning SDK v1](v1/how-to-create-machine-learning-pipelines.md)
0 commit comments