Skip to content

Commit 5557230

Browse files
committed
Fix merge conflict
1 parent 72fc706 commit 5557230

File tree

1 file changed

+27
-102
lines changed

1 file changed

+27
-102
lines changed

articles/machine-learning/how-to-github-actions-machine-learning.md

Lines changed: 27 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: machine-learning
77
ms.subservice: mlops
88
author: juliakm
99
ms.author: jukullam
10-
ms.date: 09/07/2022
10+
ms.date: 10/21/2021
1111
ms.topic: how-to
1212
ms.custom: github-actions-azure
1313
---
@@ -16,38 +16,41 @@ ms.custom: github-actions-azure
1616

1717
Get started with [GitHub Actions](https://docs.github.com/en/actions) to train a model on Azure Machine Learning.
1818

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.
2021
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
2223

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).
2426

27+
## Workflow file overview
2528

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.
2730

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:
3332

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. |
3539

36-
Fork the following repo at GitHub:
40+
## Create repository
3741

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).
4143

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**.
4346

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.
4549

46-
### Generate deployment credentials
4750

48-
# [Service principal](#tab/userlevel)
51+
## Generate deployment credentials
4952

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.
5154

5255
```azurecli-interactive
5356
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
6770
}
6871
```
6972

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
12074

12175
1. In [GitHub](https://github.com/), browse your repository, select **Settings > Secrets > Add a new secret**.
12276

12377
2. Paste the entire JSON output from the Azure CLI command into the secret's value field. Give the secret the name `AZURE_CREDENTIALS`.
12478

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 -->
15579
## Connect to the workspace
15680

15781
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
188112
with:
189113
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
190114
```
191-
## Submit training run
115+
## Submit training job
192116

193117
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.
194118

@@ -299,4 +223,5 @@ When your resource group and repository are no longer needed, clean up the resou
299223
## Next steps
300224

301225
> [!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

Comments
 (0)