Skip to content

Commit 5b031f0

Browse files
authored
Merge pull request #79538 from dlepow/acrfix
[ACR] Tasks triggered by base image updates
2 parents b29db1e + 9d32859 commit 5b031f0

File tree

2 files changed

+48
-26
lines changed

2 files changed

+48
-26
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: Automate OS and framework patching with Azure Container Registry Tasks (ACR Tasks)
3-
description: An introduction to ACR Tasks, a suite of features in Azure Container Registry that provides secure, automated container image build and patching in the cloud.
2+
title: Automate building and patching container images with Azure Container Registry Tasks (ACR Tasks)
3+
description: An introduction to ACR Tasks, a suite of features in Azure Container Registry that provides secure, automated container image build, management, and patching in the cloud.
44
services: container-registry
55
author: dlepow
66

77
ms.service: container-registry
88
ms.topic: article
9-
ms.date: 05/20/2019
9+
ms.date: 06/12/2019
1010
ms.author: danlep
1111
---
1212

13-
# Automate OS and framework patching with ACR Tasks
13+
# Automate container image builds and maintenance with ACR Tasks
1414

15-
Containers provide new levels of virtualization, isolating application and developer dependencies from infrastructure and operational requirements. What remains, however, is the need to address how this application virtualization is patched.
15+
Containers provide new levels of virtualization, isolating application and developer dependencies from infrastructure and operational requirements. What remains, however, is the need to address how this application virtualization is managed and patched over the container lifecycle.
1616

1717
## What is ACR Tasks?
1818

@@ -42,8 +42,7 @@ The following table shows a few examples of supported context locations for ACR
4242
| Local filesystem | Files within a directory on the local filesystem. | `/home/user/projects/myapp` |
4343
| GitHub master branch | Files within the master (or other default) branch of a GitHub repository. | `https://github.com/gituser/myapp-repo.git` |
4444
| GitHub branch | Specific branch of a GitHub repo.| `https://github.com/gituser/myapp-repo.git#mybranch` |
45-
| GitHub PR | Pull request in a GitHub repo. | `https://github.com/gituser/myapp-repo.git#pull/23/head` |
46-
| GitHub subfolder | Files within a subfolder in a GitHub repo. Example shows combination of PR and subfolder specification. | `https://github.com/gituser/myapp-repo.git#pull/24/head:myfolder` |
45+
| GitHub subfolder | Files within a subfolder in a GitHub repo. Example shows combination of a branch and subfolder specification. | `https://github.com/gituser/myapp-repo.git#mybranch:myfolder` |
4746
| Remote tarball | Files in a compressed archive on a remote webserver. | `http://remoteserver/myapp.tar.gz` |
4847

4948
ACR Tasks is designed as a container lifecycle primitive. For example, integrate ACR Tasks into your CI/CD solution. By executing [az login][az-login] with a [service principal][az-login-service-principal], your CI/CD solution could then issue [az acr build][az-acr-build] commands to kick off image builds.
@@ -61,7 +60,7 @@ Learn how to trigger builds on source code commit in the second ACR Tasks tutori
6160

6261
## Automate OS and framework patching
6362

64-
The power of ACR Tasks to truly enhance your container build workflow comes from its ability to detect an update to a base image. When the updated base image is pushed to your registry, ACR Tasks can automatically build any application images based on it.
63+
The power of ACR Tasks to truly enhance your container build workflow comes from its ability to detect an update to a base image. When the updated base image is pushed to your registry, or a base image is updated in a public repo such as in Docker Hub, ACR Tasks can automatically build any application images based on it.
6564

6665
Container images can be broadly categorized into *base* images and *application* images. Your base images typically include the operating system and application frameworks upon which your application is built, along with other customizations. These base images are themselves typically based on public upstream images, for example: [Alpine Linux][base-alpine], [Windows][base-windows], [.NET][base-dotnet], or [Node.js][base-node]. Several of your application images might share a common base image.
6766

@@ -72,7 +71,7 @@ Because ACR Tasks dynamically discovers base image dependencies when it builds a
7271
Learn about OS and framework patching in the third ACR Tasks tutorial, [Automate image builds on base image update with Azure Container Registry Tasks](container-registry-tutorial-base-image-update.md).
7372

7473
> [!NOTE]
75-
> Base image updates trigger builds only when both the base and application images reside in the same Azure container registry, or the base resides in a public Docker Hub repository.
74+
> Currently, base image updates trigger builds only when both the base and application images reside in the same Azure container registry, or the base resides in a public Docker Hub or Microsoft Container Registry repository.
7675
7776
## Multi-step tasks
7877

articles/container-registry/container-registry-tutorial-base-image-update.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: dlepow
66

77
ms.service: container-registry
88
ms.topic: tutorial
9-
ms.date: 09/24/2018
9+
ms.date: 06/12/2019
1010
ms.author: danlep
1111
ms.custom: "seodec18, mvc"
1212
# Customer intent: As a developer or devops engineer, I want container
@@ -68,17 +68,31 @@ A base image is often updated by the image maintainer to include new features or
6868

6969
When a base image is updated, you're presented with the need to rebuild any container images in your registry based on it to include the new features and fixes. ACR Tasks includes the ability to automatically build images for you when a container's base image is updated.
7070

71+
### Tasks triggered by a base image update
72+
73+
* Currently, for image builds from a Dockerfile, an ACR task detects dependencies on base images in the same Azure container registry, a public Docker Hub repo, or a public repo in Microsoft Container Registry. If the base image specified in the `FROM` statement resides in one of these locations, the ACR task adds a hook to ensure the image is rebuilt any time its base is updated.
74+
75+
* When you create an ACR task with the [az acr task create][az-acr-task-create] command, by default the task is *enabled* for trigger by a base image update. That is, the `base-image-trigger-enabled` property is set to True. If you want to disable this behavior in a task, update the property to False. For example, run the following [az acr task update][az-acr-task-update] command:
76+
77+
```azurecli
78+
az acr task update --myregistry --name mytask --base-image-trigger-enabled False
79+
```
80+
81+
* To enable an ACR task to determine and track a container image's dependencies -- which include its base image -- you must first trigger the task **at least once**. For example, trigger the task manually using the [az acr task run][az-acr-task-run] command.
82+
83+
* To trigger a task on base image update, the base image must have a *stable* tag, such as `node:9-alpine`. This tagging is typical for a base image that is updated with OS and framework patches to a latest stable release. If the base image is updated with a new version tag, it does not trigger a task. For more information about image tagging, see the [best practices guidance](https://blogs.msdn.microsoft.com/stevelasker/2018/03/01/docker-tagging-best-practices-for-tagging-and-versioning-docker-images/).
84+
7185
### Base image update scenario
7286

73-
This tutorial walks you through a base image update scenario. The [code sample][code-sample] includes two Dockerfiles: an application image, and an image it specifies as its base. In the following sections, you create an ACR task that automatically triggers a build of the application image when a new version of the base image is pushed to your container registry.
87+
This tutorial walks you through a base image update scenario. The [code sample][code-sample] includes two Dockerfiles: an application image, and an image it specifies as its base. In the following sections, you create an ACR task that automatically triggers a build of the application image when a new version of the base image is pushed to the same container registry.
7488

7589
[Dockerfile-app][dockerfile-app]: A small Node.js web application that renders a static web page displaying the Node.js version on which it's based. The version string is simulated: it displays the contents of an environment variable, `NODE_VERSION`, that's defined in the base image.
7690

7791
[Dockerfile-base][dockerfile-base]: The image that `Dockerfile-app` specifies as its base. It is itself based on a [Node][base-node] image, and includes the `NODE_VERSION` environment variable.
7892

7993
In the following sections, you create a task, update the `NODE_VERSION` value in the base image Dockerfile, then use ACR Tasks to build the base image. When the ACR task pushes the new base image to your registry, it automatically triggers a build of the application image. Optionally, you run the application container image locally to see the different version strings in the built images.
8094

81-
In this tutorial, your ACR task builds and pushes a single container image specified in a Dockerfile. ACR Tasks can also run [multi-step tasks](container-registry-tasks-multi-step.md), using a YAML file to define steps to build, push, and optionally test multiple containers.
95+
In this tutorial, your ACR task builds and pushes an application container image specified in a Dockerfile. ACR Tasks can also run [multi-step tasks](container-registry-tasks-multi-step.md), using a YAML file to define steps to build, push, and optionally test multiple containers.
8296

8397
## Build the base image
8498

@@ -107,21 +121,17 @@ az acr task create \
107121
> [!IMPORTANT]
108122
> If you previously created tasks during the preview with the `az acr build-task` command, those tasks need to be re-created using the [az acr task][az-acr-task] command.
109123
110-
This task is similar to the quick task created in the [previous tutorial](container-registry-tutorial-build-task.md). It instructs ACR Tasks to trigger an image build when commits are pushed to the repository specified by `--context`.
111-
112-
Where it differs is in its behavior, in that it also triggers a build of the image when its *base image* is updated. The Dockerfile specified by the `--file` argument, [Dockerfile-app][dockerfile-app], supports specifying an image from within the same registry as its base:
124+
This task is similar to the quick task created in the [previous tutorial](container-registry-tutorial-build-task.md). It instructs ACR Tasks to trigger an image build when commits are pushed to the repository specified by `--context`. While the Dockerfile used to build the image in the previous tutorial specifies a public base image (`FROM node:9-alpine`), the Dockerfile in this task, [Dockerfile-app][dockerfile-app], specifies a base image in the same registry:
113125

114126
```Dockerfile
115127
FROM ${REGISTRY_NAME}/baseimages/node:9-alpine
116128
```
117129

118-
When you run a task, ACR Tasks detects an image's dependencies. If the base image specified in the `FROM` statement resides within the same registry or a public Docker Hub repository, it adds a hook to ensure this image is rebuilt any time its base is updated.
130+
This configuration makes it easy to simulate a framework patch in the base image later in this tutorial.
119131

120132
## Build the application container
121133

122-
To enable ACR Tasks to determine and track a container image's dependencies--which include its base image--you **must** first trigger its task **at least once**.
123-
124-
Use [az acr task run][az-acr-task-run] to manually trigger the task and build the application image:
134+
Use [az acr task run][az-acr-task-run] to manually trigger the task and build the application image. This step ensures that the task tracks the application image's dependency on the base image.
125135

126136
```azurecli-interactive
127137
az acr task run --registry $ACR_NAME --name taskhelloworld
@@ -133,22 +143,28 @@ Once the task has completed, take note of the **Run ID** (for example, "da6") if
133143

134144
If you're working locally (not in the Cloud Shell), and you have Docker installed, run the container to see the application rendered in a web browser before you rebuild its base image. If you're using the Cloud Shell, skip this section (Cloud Shell does not support `az acr login` or `docker run`).
135145

136-
First, log in to your container registry with [az acr login][az-acr-login]:
146+
First, authenticate to your container registry with [az acr login][az-acr-login]:
137147

138148
```azurecli
139149
az acr login --name $ACR_NAME
140150
```
141151

142-
Now, run the container locally with `docker run`. Replace **\<run-id\>** with the Run ID found in the output from the previous step (for example, "da6").
152+
Now, run the container locally with `docker run`. Replace **\<run-id\>** with the Run ID found in the output from the previous step (for example, "da6"). This example names the container `myapp` and includes the `--rm` parameter to remove the container when you stop it.
143153

144-
```azurecli
145-
docker run -d -p 8080:80 $ACR_NAME.azurecr.io/helloworld:<run-id>
154+
```bash
155+
docker run -d -p 8080:80 --name myapp --rm $ACR_NAME.azurecr.io/helloworld:<run-id>
146156
```
147157

148158
Navigate to `http://localhost:8080` in your browser, and you should see the Node.js version number rendered in the web page, similar to the following. In a later step, you bump the version by adding an "a" to the version string.
149159

150160
![Screenshot of sample application rendered in browser][base-update-01]
151161

162+
To stop and remove the container, run the following command:
163+
164+
```bash
165+
docker stop myapp
166+
```
167+
152168
## List the builds
153169

154170
Next, list the task runs that ACR Tasks has completed for your registry using the [az acr task list-runs][az-acr-task-list-runs] command:
@@ -220,7 +236,7 @@ If you'd like to perform the following optional step of running the newly built
220236
If you're working locally (not in the Cloud Shell), and you have Docker installed, run the new application image once its build has completed. Replace `<run-id>` with the RUN ID you obtained in the previous step. If you're using the Cloud Shell, skip this section (Cloud Shell does not support `docker run`).
221237

222238
```bash
223-
docker run -d -p 8081:80 $ACR_NAME.azurecr.io/helloworld:<run-id>
239+
docker run -d -p 8081:80 --name updatedapp --rm $ACR_NAME.azurecr.io/helloworld:<run-id>
224240
```
225241

226242
Navigate to http://localhost:8081 in your browser, and you should see the updated Node.js version number (with the "a") in the web page:
@@ -229,6 +245,12 @@ Navigate to http://localhost:8081 in your browser, and you should see the update
229245

230246
What's important to note is that you updated your **base** image with a new version number, but the last-built **application** image displays the new version. ACR Tasks picked up your change to the base image, and rebuilt your application image automatically.
231247

248+
To stop and remove the container, run the following command:
249+
250+
```bash
251+
docker stop updatedapp
252+
```
253+
232254
## Clean up resources
233255

234256
To remove all resources you've created in this tutorial series, including the container registry, container instance, key vault, and service principal, issue the following commands:
@@ -257,8 +279,9 @@ In this tutorial, you learned how to use a task to automatically trigger contain
257279
<!-- LINKS - Internal -->
258280
[azure-cli]: /cli/azure/install-azure-cli
259281
[az-acr-build]: /cli/azure/acr#az-acr-build-run
260-
[az-acr-task-create]: /cli/azure/acr
261-
[az-acr-task-run]: /cli/azure/acr#az-acr-run
282+
[az-acr-task-create]: /cli/azure/acr/task#az-acr-task-create
283+
[az-acr-task-update]: /cli/azure/acr/task#az-acr-task-update
284+
[az-acr-task-run]: /cli/azure/acr/task#az-acr-task-run
262285
[az-acr-login]: /cli/azure/acr#az-acr-login
263286
[az-acr-task-list-runs]: /cli/azure/acr
264287
[az-acr-task]: /cli/azure/acr

0 commit comments

Comments
 (0)