Pelican is a great tool for creating flat HTML websites like a blog. The utility allows you to create pages using Markdown, and then converts them to HTML using a theme. The result is a website that doesn't have a lot of overhead from a backend dynamically generating content, querying a database, or having a backend exposed to the internet. Other similar tools include Jekyll, Hugo, and Eleventy.
There are some important caveats to using something like Pelican though, namely the flexibility of the backend to allow for more interactivity, such as comments on a blog post. To handle that, we can utilize something like Staticman to leverage GitHub as a means of storing these comments.
Here is the general process of how I set up a Static Web App on Azure with Pelican and Staticman. You could probably do something very similar using any static site generator and achieve the same end goal; a simple HTML website with comment functionality hosted on Azure.
rg-apps
. Following the Azure Cloud Adoption Framework, resource groups should be created to help manage resource lifecycle, so this resource group should contain everything related to your static web app.Cool, we have our Static Web App, but it's completely empty (probably). Now what? Lets get our GitHub CI/CD pipeline setup to automagically build and deploy our site!
build
phase that builds your pelican site build:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
name: Build Pelican Site
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.12
uses: actions/setup-python@v5.2.0
with:
python-version: 3.12
- name: Install pelican with markdown
shell: bash
run: "pip install invoke pelican[markdown]"
- name: Install YAML
shell: bash
run: "pip install pyyaml"
- name: Build the project
shell: bash
run: "pelican content -s publishconf.py"
- name: Check if we have everything
shell: bash
run: "ls -la output/"
- name: Store output for deployment
uses: actions/upload-artifact@v4
with:
name: pelican-site
path: "output/"
We can modify the workflow to allow for manual triggering of the job
workflow_dispatch
to the on:
node at the top. This tells the workflow that we can manually kick this off.or
condition to the if then
statements on the build
and deploy
phases to allow these jobs to run when github.event_name == 'workflow_dispatch'
You'll need to have a deploy
phase that pushes the artifacts from the build
phase to the Azure Static Web Page app
deploy:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: build
name: Deploy Job
steps:
- uses: actions/checkout@v4
- name: Get built pelican site
uses: actions/download-artifact@v4
with:
name: pelican-site
path: "output/"
- name: Deploy
id: deploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
#repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for GitHub integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations ######
app_location: "output/" # App source code path relative to repository root
#api_location: "api" # Api source code path relative to repository root - optional
output_location: "public" # Built app content directory, relative to app_location - optional
###### End of Repository/Build Configurations ######
deploy
step, mainly the azure_static_web_apps_api_token
, action
, app_location
, and output_location
This will take the artifacts from the output directory that were built in the previous phase, and then upload them to the Azure Static Web App.
Go to the Settings for your repo, and find the Secrets and Variables section
AZURE_STATIC_WEB_APPS_API_TOKEN
and populate it with the deployment token from step 1. Save it, and remember you may need to periodically update that deployment token. You'll never be able to view it from here after creating/updating it.The recommended procedure here is to make changes (like writing a new blog entry) in a branch, and then merge via pull request into Main when you're ready to publish the changes. The CI/CD pipeline takes care of the rest!
Your static web app will have an automatically generated FQDN that you will be able to use to visit your site. Also, fun fact: your site will get an SSL certificate automatically as well! This automatically generated FQDN is probably not suitable for production use, so you'll want to associate a custom domain.
The steps to add the domain will differ depending on which you select. The first two will have similar steps.
The last option will guide you through the process of purchasing a new domain name.
Follow the steps to finish verifying and adding your domain.
@
pointing to the public IP of the Static Web App. Now our website is there, but comments are still not working. We need to set up Staticman to handle our commenting. I'm not going to cover configuring Staticman with your website, but am assuming that you will be able to follow the Staticman documentation for that. This will only cover getting Staticman running within Azure.
Create a new App Service.
After the App Service has deployed, navigate to Deployment Center
Select GitHub as the source
Sign up for GitHub Developer
Grant the following permissions to the app for the blog repository
Register the application here. Note the App ID
.pem
file that downloads.Back in the App Service, add Environment Variables
NODE_ENV
This should be production
, development
or test
GITHUB_APP_ID
This is the App ID of the GitHub App we just createdGITHUB_PRIVATE_KEY
This will be the ENTIRE contents of the .pem
private key file, however, after pasting it in (converts to single line), we need to open Advanced edit and add \n
line breaks after the opening and before the closing: -----BEGIN RSA PRIVATE KEY-----\n ... \n-----END RSA PRIVATE KEY-----
.RSA_PRIVATE_KEY
should be the same process as the GITHUB_PRIVATE_KEY
, but generate your own RSA key for this. Use OpenSSL and use a decent key size.AKISMET_SITE
This is the URL for your homepage, i.e. https://mysite.com
AKISMET_API_KEY
Go get a free Akismet key for your personal blog. Seriously, just go sign up and it's free.Visit your GitHub Apps installation URL, which should be something like, but not necessarily https://github.com/apps/mysite-staticman
. Authorize the app to access the things.
/v2/connect/<GITHUB_USERNAME>/<SITE_REPO_NAME>
. You should get an OK!
message.At this point, your blog and Staticman should be up and running in Azure Static Web App and Web App Service. You may need to massage some of the config for your site accordingly to make sure that the comments form points to the right place, and all that stuff. But I think I've done enough to help you for now.
Happy blogging!
0 comments