Skip to content

Commit 55448a8

Browse files
committed
draft complete
1 parent d994eb9 commit 55448a8

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

articles/container-registry/container-registry-tasks-template.md

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
---
2-
title: Run task from template
2+
title: Run task using template
33
description: Run an ACR task using an Azure Resource Manager template
44
ms.topic: article
5-
ms.date: 03/23/2020
5+
ms.date: 03/25/2020
66
---
77

88
# Run ACR Tasks using Resource Manager templates
99

10-
Task template reference at https://docs.microsoft.com/en-us/azure/templates/microsoft.containerregistry/2019-06-01-preview/registries/tasks
10+
[ACR Tasks](container-registry-tasks-overview.md) is a suite of features within Azure Container Registry to help you manage and modify container images across the container lifecycle.
1111

12-
Task run template reference at: https://docs.microsoft.com/en-us/azure/templates/microsoft.containerregistry/2019-06-01-preview/registries/taskruns
12+
This article shows how to use an Azure Resource Manager template to queue a [quick task](container-registry-tasks-overview.md#quick-task), similar to one you can create manually using the [az acr build][az-acr-build] command.
1313

14-
Use a template to run an ACR task in scenarios such as:
14+
A Resource Manager template to queue a task is useful in automation scenarios. For example:
1515

16-
* Deploy a container registry and immediately queue an ACR task to build or push a container image
17-
* Automate creation of additional resources used in a task, such as a managed identity for Azure resources or an Azure key vault
16+
* Use a template to create a container registry and immediately queue an ACR task to build or push a container image
17+
* Automate creation of additional resources you can use in a quick task, such as a managed identity for Azure resources. The template-based creation of a quick task allows you to use a managed identity, which currently isn't supported with `az acr build`.
1818

1919
## Limitations
2020

21-
* You must specify a remote context such as a GitHub repo as the source location for your task. You can't use a local source location.
22-
* For task runs using a managed identity, only a user-assigned managed identity is permitted.
23-
* [TODO: Run multi-step tasks? Only build from Dockerfile?]
21+
* You must specify a remote context such as a GitHub repo as the [source location](container-registry-tasks-overview.md#context-locations) for your task. You can't use a local source context.
22+
* For task runs using a managed identity, only a *user-assigned* managed identity is permitted.
2423

2524
## Prerequisites
2625

2726
* **GitHub account** - Create an account on https://github.com if you don't already have one. This tutorial series uses a GitHub repository to demonstrate automated image builds in ACR Tasks.
28-
* **Fork sample repository** - Use the GitHub UI to fork the following sample repository into your GitHub account: https://github.com/Azure-Samples/acr-build-helloworld-node
27+
* **Fork sample repository** - Use the GitHub UI to fork the following sample repository into your GitHub account: https://github.com/Azure-Samples/acr-build-helloworld-node. This repo contains sample Dockerfiles and source code to build small container images.
2928

3029
## Example: Create registry and queue a build task
3130

3231
This example uses a [sample template](https://github.com/Azure/acr/tree/master/docs/tasks/run-as-deployment/quickdockerbuild) that creates a container registry and queues a task to build and push an image. To use the template:
3332

3433
* First create a resource group, or use an existing group
35-
* Make sure to specify a unique registry name
36-
* Point to a remote GitHub repo for the build context, such as https://github.com/<your-GitHub-ID>/acr-build-helloworld-node
34+
* Specify a unique registry name
35+
* Point to a remote GitHub repo for the build context, such as https://github.com/<your-GitHub-ID>/acr-build-helloworld-node. The Dockerfile in the root of this repo builds a container image for small Node.js web app.
3736

38-
Deploy the template with the [az deployment group create[az-deployment-group-create] command. This example builds and pushes the *helloworld-node:testtask* image to a registry named *mycontainerregistry*:
37+
### Deploy the template
3938

40-
[Note that repository isn't a parameter but rather hard coded]
39+
Deploy the template with the [az deployment group create][az-deployment-group-create] command. This example builds and pushes the *helloworld-node:testtask* image to a registry named *mycontainerregistry*:
4140

4241
```azurecli
4342
az deployment group create \
@@ -48,10 +47,11 @@ az deployment group create \
4847
registryName=mycontainerregistry \
4948
taskRunName=testtask \
5049
repository=helloworld-node \
51-
sourceLocation=https://github.com/<your-GitHub-ID>/acr-build-helloworld-node.git \
52-
dockerFilePath=Dockerfile-test
50+
sourceLocation=https://github.com/<your-GitHub-ID>/acr-build-helloworld-node.git
5351
```
5452

53+
### Verify deployment
54+
5555
Verify the image is built by running [az acr repository show-tags][az-acr-repository-show-tags]:
5656

5757
```azurecli
@@ -68,7 +68,9 @@ Result
6868
testtask
6969
```
7070

71-
To view details about the task run, you can view the run log.
71+
### View run log
72+
73+
To view details about the task run, view the run log.
7274

7375
First get the run ID with [az acr task list-runs][az-acr-task-list-runs]
7476
```azurecli
@@ -136,8 +138,12 @@ Run ID: ca1 was successful after 47s
136138

137139
## Example: Task with managed identity
138140

141+
This [deployment example](https://github.com/Azure/acr/tree/master/docs/tasks/run-as-deployment/quickdockerbuildwithidentity) queues a task that uses a user-assigned managed identity. During the task run, the identity authenticates to pull an image from another Azure container registry. This scenario is similar to the one in [Cross-registry authentication in an ACR task using an Azure-managed identity](container-registry-tasks-cross-registry-authentication.md). For example, an organization might maintain a *base registry* with base images accessed by multiple development teams.
142+
139143
### Prepare a base registry
140144

145+
For demonstration purposes, create a separate container registry as your base registry, and push a Node.js base image pulled from Docker Hub.
146+
141147
1. Create a second container registry, for example *mybaseregistry*, to store base images.
142148
1. Pull the `node:9-alpine` image from Docker Hub, tag it for your base registry, and push it to the base registry:
143149

@@ -150,6 +156,8 @@ Run ID: ca1 was successful after 47s
150156

151157
### Create a new Dockerfile
152158

159+
Create a Dockerfile that pulls the base image from your base registry.
160+
153161
1. In the GitHub UI, select **Create new file**.
154162
1. Name your file *Dockerfile-test* and paste the following contents. Substitute your registry name for *mybaseregistry*.
155163
```
@@ -161,24 +169,21 @@ Run ID: ca1 was successful after 47s
161169
```
162170
1. Select **Commit new file**.
163171

164-
### Create a user assigned-identity
165-
166172
[!INCLUDE [container-registry-tasks-user-assigned-id](../../includes/container-registry-tasks-user-assigned-id.md)]
167173

168-
169174
### Give identity pull permissions to the base registry
170175

171176
Give the managed identity permissions to pull from the base registry, *mybaseregistry*.
172177

173-
Use the [az acr show][az-acr-show] command to get the resource ID of the base registry and store it in a variable:
178+
First use the [az acr show][az-acr-show] command to get the resource ID of the base registry and store it in a variable:
174179

175180
```azurecli
176181
baseregID=$(az acr show \
177182
--name mybaseregistry \
178183
--query id --output tsv)
179184
```
180185

181-
Use the [az role assignment create][az-role-assignment-create] command to assign the identity the `acrpull` role to the base registry. This role has permissions only to pull images from the registry.
186+
Use the [az role assignment create][az-role-assignment-create] command to assign the identity the Acrpull role to the base registry. This role has permissions only to pull images from the registry.
182187

183188
```azurecli
184189
az role assignment create \
@@ -187,30 +192,47 @@ az role assignment create \
187192
--role acrpull
188193
```
189194

190-
### Modify the template
191-
192-
Update the following snip in the template with the name of your base registry
193-
194195
### Deploy the template
195196

196197
```azurecli
197198
az deployment group create \
198199
--resource-group myResourceGroup \
199-
--template-uri taskmi2.json \
200+
--template-uri https://raw.githubusercontent.com/Azure/acr/master/docs/tasks/run-as-deployment/quickdockerbuildwithidentity/azuredeploy.json \
200201
--parameters azuredeploy.parameters.json \
201202
--parameters \
202203
registryName=mycontainerregistry \
203204
taskRunName=basetask \
204205
repository=helloworld-node \
205206
userAssignedIdentity=$resourceID \
207+
identityCredential=$clientID \
206208
sourceLocation=https://github.com/<your-GitHub-ID>/acr-build-helloworld-node.git \
207209
dockerFilePath=Dockerfile-test \
208210
baseRegistry=mybaseregistry.azurecr.io
209211
```
210212

213+
Verify the image is built by running [az acr repository show-tags][az-acr-repository-show-tags]:
214+
215+
```azurecli
216+
az acr repository show-tags \
217+
--name mycontainerregistry \
218+
--repository helloworld-node --output table
219+
```
220+
221+
Output:
222+
223+
```console
224+
Result
225+
--------
226+
basetask
227+
```
228+
229+
To view the run log, see steps in the [preceding section](#view-run-logs).
230+
211231
## Next steps
212232

213233
* See more template examples in the [ACR GitHub repo](https://github.com/Azure/acr/tree/master/docs/tasks/run-as-deployment).
234+
* For details about template properties, see the template reference for [Tasks](/azure/templates/microsoft.containerregistry/2019-06-01-preview/registries/tasks) and [Task runs](/azure/templates/microsoft.containerregistry/2019-06-01-preview/registries/taskruns).
235+
214236

215237
<!-- LINKS - Internal -->
216238
[azure-cli]: /cli/azure/install-azure-cli

0 commit comments

Comments
 (0)