[DOCKER] [Azure] Build automatically with ACR task triggered by base image / source code update

By using the function ACR task of Azure Container Registry (ACR), you can automatically build a container image triggered by an update of the base image or source code.

ACR Task Overview: https://docs.microsoft.com/en-us/azure/container-registry/container-registry-tasks-overview

1. Create an ACR task

Have a Git repository in advance that contains the ACR and Dockerfile. Execute the following command on the azure cloud shell or the console with az login.

 ACR_NAME = <created ACR name>
 ACR_TASK_NAME = <arbitrary ACR task name>

az acr task create \
  --registry ${ACR_NAME} \
  --name ${ACR_TASK_NAME} \
 --image <arbitrary container image name>: <tag> \
 --context <Git repository clone URL> \
 --file <Dockerfile name> \
  --git-access-token <Git Access token (PAT)>

Official tutorial command execution example: https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-tutorial-base-image-update#create-a-task

You can check the created ACR task from [Service]-[Task] of ACR. 2020-11-07_16h05_30.png

2. Perform the ACR task manually

You must manually run the ACR task once to enable automatic builds. https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-tasks-base-images#additional-considerations

Execute it with the following command.

az acr task run --registry ${ACR_NAME} --name ${ACR_TASK_NAME} 

You can check the execution from the [Execute] tab of the task. 2020-11-07_16h33_16_2.png

It also stores the built image in the ACR repository.

3. Check the automatic build by updating the base image / source code

This time, I'll update the base image on Docker Hub. The time from update to build trigger depends on the location of the base image, which can take 10-60 minutes for Docker Hub. https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-tasks-base-images#base-image-notifications

When I waited for about 10 minutes and looked at the task screen, I was able to confirm the execution of the ACR task whose trigger was image update. 2020-11-07_16h49_53.png

Also, when I updated the source code in the Git repository, an automatic build ran here as well. 2020-11-07_16h53_07.png

If you want to turn off automatic builds, you can do so with the options of the az acr task update command. https://docs.microsoft.com/ja-jp/cli/azure/acr/task?view=azure-cli-latest#az_acr_task_update

az acr task update --name ${ACR_TASK_NAME} --registry ${ACR_NAME} --base-image-trigger-enabled false
az acr task update --name ${ACR_TASK_NAME} --registry ${ACR_NAME} --commit-trigger-enabled false

Reference material

-ACR Task Overview -About updating the basic image of ACR tasks

Recommended Posts

[Azure] Build automatically with ACR task triggered by base image / source code update
Monitor source code changes with guard-shell and make & execute automatically