My prior blog has been running on Cloudflare Pages for a couple of years now (since moving away from GitHub Pages). However, when I originally set it up, I never wrote a blog entry - and now I can't remember what I did.
Thankfully, there's plenty of documentation available:
The Zola documentation seemed slightly out of date, so I followed the guide provided by Cloudflare.
Prerequisites
- A Cloudflare account.
- A custom domain already hosted with Cloudflare.
- A hosted Git account with either GitLab or GitHub.
- A Git repository with your static files ready.
Steps
- Select the "Workers & Pages" menu.
- Click "Create".
- Choose the "Pages" tab.
- Select "Import an existing Git repository".
- Connect to your Git repository containing the static files for your site.
- Click "Begin setup".
- For "Framework preset", select "Zola".
- Expand the "Environment variables (advanced)" section and click "Add variable".
- Add a variable named
ZOLA_VERSION
and set it to a recent Zola release (e.g.,"0.20.0"
). - Click "Save and Deploy".
At this point, I encountered the following error in Cloudflare:
Executing user command: zola build
/bin/sh: 1: zola: not found
Failed: Error while executing user command. Exited with error code: 127
Failed: build command exited with code: 1
Failed: error occurred while running build command
Cloudflare's deployment page wasn't helpful, but the Zola documentation covers this error under Troubleshooting.
It links to an unresolved issue from 2023 noting that Zola is not included in the v2
build image: https://github.com/cloudflare/pages-build-image/issues/3
Two solutions are suggested. I chose the second, and added this environment variable:
UNSTABLE_PRE_BUILD
=asdf plugin add zola https://github.com/salasrod/asdf-zola && asdf install zola 0.20.0 && asdf global zola 0.20.0
After clicking "Save and Deploy" again, the build completed successfully.
Cloudflare Pages Custom Domain
By default, you will be given a dev site URL (e.g. your-site.pages.dev
). There is an additional step required to configure a custom domain to complete your hosting setup.
- Select the "Workers & Pages" menu.
- Click on your newly created project.
- Select the "Custom domains" tab.
- Click on "Set up a custom domain".
- Enter the URL of your custom domain
- Click "Continue".
- Confirm the creation of a new DNS record per the below:
Type | Name | Content | TTL |
---|---|---|---|
CNAME | @ | your-site.pages.dev | Auto |
- Click "Activate domain" to complete the setup.
Once the DNS changes have propagated, your site should be live.