Hello Blogging (4) - Deploy it. Way to Automation
You now have a blog actually working on the internet, but you are very frustrated on how you deploy the site manually
EVERY SINGLE TIME
You want these boring steps automated, then more time for ☕.
You may have a flashback when creating a Cloudflare Pages project, you can provide a git repo instead of uploading the site.
But I self-host my own git (gitea) as I like my code in my homelab, so this GitHub / GitLab option offered by Cloudflare is a no go for me.
I need to write my CI/CD stuff for the first time and it should be a nice Hello CI/CD for me.
Gitea Action
is compatible with Github Action
, so there is not much a difference from using Github Action.
** Of course the Github Action Marketplace can be used on Gitea
, which comes very handy.
Instant helper to test GitHub Action Locally
Before I start writing the action, I have one issue to solve.
I don’t want to push multiple times in order to just test my Gitea Action.
And.. nektos/act comes into rescue.
act
could be used to test Gitea Action locally, without have to act silly to test just the Gitea action.
To install this tool, just brew it
➜ brew install act
After setting up the tool, I could actually start writing the action by creating a yaml file under .github/workflows
--- your-blog-content
|_ .github
|_ workflows
|_ build.yaml
and here is my action to deploy it.
Basically it makes not much a difference from installing the blog on clean machine.
The huzky-blog
on the last section should be your project name on CloudFlare Pages, test-blogger
in last example.
Prerequisite of automatic deployment, API token
Now you have noticed that there is a CLOUDFLARE_API_TOKEN in the step for the cloudflare/wrangler action to work.
To acquire a API token, go to the Worker & Pages in Cloudflare Dashboard and select “Manage API tokens” on the right.
Click “Create Token” > Select “Edit Cloudflare Worker” API token template and fill in the form like this
After checking your permission and clicking “Create Token”, Cloudflare will give you the API token.
** WARNING: Please keep the API key in a safe place, the token could not be viewed again.
Now you have the token to deploy the site, programmatically. Go to the your-blog-content
folder and run
➜ act --container-architecture linux/amd64 -s CLOUDFLARE_API_TOKEN="your cloudflare token"
--container-architecture
set to linux/amd64
as my Gitea runner is in x64.
-s
to pass the secrets.CLOUDFLARE_API_TOKEN
.
After running the command, the action is run locally and you can see that the website is deployed at the end. Kind of automatically.
Now to fully enable the CI/CD, what you need to add is the CLOUDFLARE_API_TOKEN secret to gitea secret section.
After adding the secret, push the changes to git and you can see the action is running.
And voilà, you have the Automatic blog deployment when you push the changes to the repo.