Search results provided by Azure Search - read how I built it in this post.
Max Melcher

2 minute read

In Hugo version 0.56 a native deployment command was introduced to deploy your blog/website to various cloud providers - one of them is Azure. In this post I show how I simplified my deployment pipeline with this command.

Hugo deploy

The Hugo deploy command uses Azure CLI and your config.toml / config.yaml file and checks for a [deployment] section. Additionally, you need to have two environment variables present - even tho the documentation says you have to use az login (thats incorrect, it works without). That has the benefit that your config file does not have the secrets and you can still publicly store it on github.

Environment Variables

You must have the environment variable AZURE_STORAGE_ACCOUNT and one of the following: AZURE_STORAGE_KEY or AZURE_STORAGE_SAS_TOKEN.

In powershell you can configure them like this:

$Env:AZURE_STORAGE_ACCOUNT = "<AccountName>"
$Env:AZURE_STORAGE_KEY = "<AccountKey>"

Or if you want to have it dynamic - that requires you to be logged in with Azure CLI:

$Env:AZURE_STORAGE_ACCOUNT = "<AccountName>"
$Env:AZURE_STORAGE_KEY = az storage account keys list -n <AccountName> --query [0].value -o tsv

Deployment Configuration

My deployment configuration looks like this:

order = [".jpg$", ".gif$"]

name = "azure"

# Azure Blob Storage; see https://gocloud.dev/howto/blob/#azure

URL = "azblob://$web"

#  Cache static assets for 20 years.

pattern = "^.+\\.(js|css|svg|ttf)$"
cacheControl = "max-age=630720000, no-transform, public"
gzip = true

pattern = "^.+\\.(png|jpg)$"
cacheControl = "max-age=630720000, no-transform, public"
gzip = false

pattern = "^.+\\.(html|xml|json)$"
gzip = true

And in action

Simplified deployment with Azure DevOps

As described in the post RUNNING HUGO ON AZURE FOR 2$ A MONTH, I use Azure DevOps to automatically deploy Hugo to Azure and have everything version-controlled. My old pipeline did the following:

  • Generate Hugo content
  • Sync the content to Azure Storage (upload new files, delete no longer required files)
  • Set the cache header of files
  • Purge the Azure CDN
  • Index the content with Azure Search

I could combine the sync and cache header job with the Hugo native deployment - but as of know, the build task that I use, does not support that.

For local testing, the native deployment is great!

Hope it helps,

comments powered by Disqus