Robert Schaap

Blogging like it’s 1999

Azure DevOps

In this post I elaborate a little bit more on how this website is build and deployed using Azure DevOps. To accomplish this I mainly use the Azure Pipelines and Azure Repos funcionality of the service.

The goal here is to automate the building and deploying of the website. That means I can make some changes, like write a new article, commit it to the master branch and push. After which Azure DevOps will trigger a build and deploy an updated version of the website so you can read the new article.

Azure DevOps is very easy to use, just register an account and create a new project to start with. If you have used GitHub or BitBucket getting your repo set up will be very familiar to you. Basically you configure your SSH key and either clone the created repository or add the repository as a remote to an existing repository. Since I already had some code I did the latter with the following two commands.

git remote add origin <git-repo-url>
git push -u origin --all

That takes care of storing the source code. To build and deploy the website we need to create a pipeline. You can either create it from a template within Azure Devops or create the .yaml file yourself in your repository and register it as a pipeline. I created the following pipeline.

trigger:
- master

pool:
  vmImage: 'ubuntu-20.04'

steps:
- script: wget -O hugo.tgz https://github.com/gohugoio/hugo/releases/download/v0.70.0/hugo_0.70.0_Linux-64bit.tar.gz && tar -xf hugo.tgz
  displayName: 'Get hugo'
- script: wget -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz --strip-components=1
  displayName: 'Get azcopy'
- script: git submodule update --init --recursive
  displayName: 'Init git submodules'
- script: ./hugo
  displayName: 'Generate website'
- script: ./azcopy sync public "$(SAS_URL)"
  displayName: 'Deploy website'

The pipeline is triggered by changes in the master branch, it is also possible to schedule pipelines or trigger them based on pull requests.

It starts with downloading hugo and AzCopy which are needed to build and deploy the website. Then it initializes any submodules in the repository, this step is necessary because I added a theme as a submodule. Finally, it generates the website and deploys it. I have used azcopy sync to deploy the website, it does not work very nicely with hugo because the timestamps of the files will be modified so it copies over more than is necessary. Since my website is only 3 MiB that is acceptable, but it is something that should be addressed in the future.

Secrets such as the SAS_URL should be injected into the script by using pipeline variables. Make sure to fix the url if it contains special characters. For instance, my container name is called $web which has to be escaped as %24web to work with azcopy sync.

There is a lot of room for improvement but this sort of works, and yes, I know I could have just used hugo deploy instead. 😄