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
Copy file name to clipboardExpand all lines: articles/container-registry/container-registry-tasks-template.md
+50-28Lines changed: 50 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,43 +1,42 @@
1
1
---
2
-
title: Run task from template
2
+
title: Run task using template
3
3
description: Run an ACR task using an Azure Resource Manager template
4
4
ms.topic: article
5
-
ms.date: 03/23/2020
5
+
ms.date: 03/25/2020
6
6
---
7
7
8
8
# Run ACR Tasks using Resource Manager templates
9
9
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.
11
11
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.
13
13
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:
15
15
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`.
18
18
19
19
## Limitations
20
20
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.
24
23
25
24
## Prerequisites
26
25
27
26
***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.
29
28
30
29
## Example: Create registry and queue a build task
31
30
32
31
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:
33
32
34
33
* 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.
37
36
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
39
38
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*:
Verify the image is built by running [az acr repository show-tags][az-acr-repository-show-tags]:
56
56
57
57
```azurecli
@@ -68,7 +68,9 @@ Result
68
68
testtask
69
69
```
70
70
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.
72
74
73
75
First get the run ID with [az acr task list-runs][az-acr-task-list-runs]
74
76
```azurecli
@@ -136,8 +138,12 @@ Run ID: ca1 was successful after 47s
136
138
137
139
## Example: Task with managed identity
138
140
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
+
139
143
### Prepare a base registry
140
144
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
+
141
147
1. Create a second container registry, for example *mybaseregistry*, to store base images.
142
148
1. Pull the `node:9-alpine` image from Docker Hub, tag it for your base registry, and push it to the base registry:
143
149
@@ -150,6 +156,8 @@ Run ID: ca1 was successful after 47s
150
156
151
157
### Create a new Dockerfile
152
158
159
+
Create a Dockerfile that pulls the base image from your base registry.
160
+
153
161
1. In the GitHub UI, select **Create new file**.
154
162
1. Name your file *Dockerfile-test* and paste the following contents. Substitute your registry name for *mybaseregistry*.
155
163
```
@@ -161,24 +169,21 @@ Run ID: ca1 was successful after 47s
### Give identity pull permissions to the base registry
170
175
171
176
Give the managed identity permissions to pull from the base registry, *mybaseregistry*.
172
177
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:
174
179
175
180
```azurecli
176
181
baseregID=$(az acr show \
177
182
--name mybaseregistry \
178
183
--query id --output tsv)
179
184
```
180
185
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.
182
187
183
188
```azurecli
184
189
az role assignment create \
@@ -187,30 +192,47 @@ az role assignment create \
187
192
--role acrpull
188
193
```
189
194
190
-
### Modify the template
191
-
192
-
Update the following snip in the template with the name of your base registry
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
+
211
231
## Next steps
212
232
213
233
* 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).
0 commit comments