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
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.
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.
It also stores the built image in the ACR repository.
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
.
Also, when I updated the source code in the Git repository, an automatic build ran here as well.
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
-ACR Task Overview -About updating the basic image of ACR tasks