Clean up your durable functions history
Recently I have been working with Azure Durable Functions, which are an extension of the Azure …
It has been a while since I have written a post on melodiouscode.net; partly because it has been a busy year, but also because I didn’t fancy sorting out some server problems on my digital ocean droplet. Until now melodiouscode.net was hosted on the Ghost CMS Platform within an Ubuntu Droplet on digital ocean’s infrastructure; proxied through the Cloudflare platform for speed and security.
The image that the “Ghost Droplet” was created from contained an old version of the Lets Encrypt agent; the version of the Ghost install was out of date, and the theme I used didn’t support the new version of Ghost.
After undertaking some research into alternative solutions, I decided to try out the Jekyll static site generator; why not go back to basics and have an HTML, Javascript, and CSS website?
Before I jump ahead I want to explain a little about what the components of my new Static MelodiousCode are; if you are just here for the instructions on how to host a Jekyll static site with Azure, Cloudflare, and GitHub skip down to the bottom!
Back in the old days (ok, the slightly less recent days) the internet was just a collection of HTML pages; you wrote your webpages and hosted them on your webserver. The server returned the files from its storage drive; they were just basic HTML. In time along came JavaScript, CSS, and eventually dynamically driven pages created as part of the request to the webserver. A static site is what it sounds like; a collection of HTML pages (that may contain Javascript or CSS) that are served on request by a web server. The main benefit being simplicity; your request to this page didn’t require any processing beyond locating the file; nothing was generated or changed, if you refresh the page you will get precisely the same response.
A static site sounds great; simple pages that serve static content to your users. However maintaining all those static pages, copy and pasting templates, updating them with common changes; is time-consuming and prone to error.
Jekyll is a static site generator; it takes the content you write for your site (via markdown files) and merges them into a set of template files to create your static HTML. Via the template files, you can alter the structure or broader details without having to edit each file. Jekyll will regenerate your pages and provide you with a static site to deploy.
Azure Static Sites is a hosting platform that allows you to serve your static content (HTML, Javascript, CSS, Images, etc.) as a website without the need for dealing with hosting infrastructure, databases, or configurations. Azure Static Sites integrates directly with a GitHub repository, and via GitHub Actions (continuous integration) can build your Jekyll site and upload it to Azure on-demand.
The first step is to install the Jekyll toolchain and its dependencies on your local machine (or the environment you wish to use to create your site).
gem install Jekyll bundler
Jekyll new myblog
bundle exec jekyll serve
You now have a tiny webserver running inside your command window hosting a new Jekyll site; visit http://localhost:4000 to view it.
Setup a Git repository for your site (you can set it to private mode if you wish) and commit your Jekyll files (all of the folder) to the main branch. If you don’t know about Git, then I suggest using the GitHub desktop client; otherwise, go about it in your usual way.
The static site resource in Microsoft Azure is designed to integrate directly with a GitHub repository; in fact, it is the only way of uploading your files. If you do not already have an Azure account, you can sign up for one for free; currently, the Static Sites resource is free, so you will not need to provide any payment details.
Once the resource has finished creating, you will find that a build step has failed in your GitHub Actions (if you don’t get an email about it, go and check). This is because there are a few extra setup steps required in the Action Definition; pull the changes to your repository that Azure has made and open the file in the .github\workflows directory. The file will look something like this; at the time of writing there is a mistake in the created file (some lines are missing). To fix the problem, and allow the build to run, correct the file to look like this.
IMPORTANT: The example file contains values like this “AZURE_STATIC_WEB_APPS_API_TOKEN_WITTY_SKY_0C6D4E003”; you need to ensure you replace them with the keys from your GitHub Secrets that Azure has created for you (which will be the same as the URL name displayed on your Static Sites Overview in the Azure Portal).
Once you have committed this change you will find that your GitHub Action will run and your new static azure site will serve your site; you can see the URL in the Overview tab on the Azure Portal.
You have a working site; hosted on an azurestaticsites.net domain, not a perfect domain name but at least it works! You could map your domain to Azure via your domain registrar following the instructions on the Azure Portal, or you could take the next step and set up a security and performance layer for free using Cloudflare.
Adding your domain to Cloudflare is beyond the scope of this article, but it is an easy process to follow in their wizards. Once you have onboarded the domain to Cloudflare, you need to follow the instructions on the custom domains tab of your Azure Resource Dashboard. Some items to note:
Thank you to my friend Tony Hillier-Swift of https://www.hillier-swift.co.uk/ for pointing out a few glitches in the instructions for the Jekyll Install! Tony is one of those systems people that all developers have a love-hate relationship with (and I should know, we took our first programming classes together); go check out his blog!