Deploy Static Blog to Cloudflare Workers With GitHub Actions CI
Initial setups for the blog will be skipped, since it has been done years ago for me.
I assume you already have a Cloudflare account and a domain using it for DNS resolution.
Because we will only be using
wrangler on the local machine once, I do not recommend installing it with
npm or other package management tools. Instead, go to its GitHub repo to download the binary file for your platform and extract it to your blog’s root directory.
wrangler init --site my-blog # or whatever name you like
Run it from command line, a file named
wrangler.toml will be created, fill in the blanks like following:
name = "your_blog_name"
To find your
Zone ID and
Account ID, get to the overview page of that domain, they can be found on the bottom-right corner of the page.
wrangler config, it will ask for the
API Token you just generated:
To generate a new
API Token, go to your Cloudflare profile page and click
Create, use the template for
Edit Cloudflare Workers but remove the
User permissions - we will not be using them here. For other fields, follow the least privilege principle.
Also save it to the
Secrets area of your blog’s GitHub repo, name it with
CF_WORKERS_TOKEN or you will need to edit your workflows.
In the root directory of your blog, create a new file with whatever filename but having
.yml as extension at
.github/workflows/. Put the following contents into that file:
Commit and push everything to GitHub, the CI shoud be running. Check the progress and any issues at the
Actions page of your repo.
A type DNS record to the domain pointing to
18.104.22.168. You should be able to see the blog up and running when the DNS is updated.