Eliminating build servers with Azure Container Registry

Published on 04 June 2018

Currently I use an Azure Linux Webapp with a custom container to host one of my web apps. The build & release process looks like this:

  • commit code to the master branch of a github repository
  • CI build in VSTS builds docker image & pushes it to Docker Hub
  • CD release in VSTS updates the container image for the Web App in Azure

When I saw this tweet I knew that this process could be simplified:

Armed with this tutorial you can create a build task with your source code repo and an existing Azure Container Registry. To do this you have to install the latest Azure CLI or launch a cloud shell from the Azure portal.

az acr build-task create \
    --registry $ACR_NAME \
    --name mybuild\
    --image myImage:{{.Build.ID}} \
    --context https://github.com/$GIT_USER/myrepo \
    --branch master \
    --git-access-token $GIT_PAT

This works for Visual Studio Team Services Repos as well if you pass the personal access token from your VSTS account to the git-access-token parameter.

Together with the Continuous Deployment feature of Azure App Service for Linux you can now build & push your updates directly to your Web App - no build server required.

At the moment there's a caveat, though. Copy references in your docker file will have to be from the root or your build will break. This will be fixed in the future.

UPDATE 25.06.2018

You can now use subfolders in a git repo as the build context. Here's an example for my website located at https://github.com/hoetz/3dshootercom/tree/master/src/Web

az acr build-task create \
    --registry $ACR_NAME \
    --name 3dsbuild\
    --image 3ds:{{.Build.ID}} \
    --context https://github.com/$GIT_USER/3dshootercom.git#master:src/Web \
    --git-access-token $GIT_PAT