Using Gitea Actions deploy Hugo website to AWS S3
After setting upd the Gitea and Hugo on AWS S3...
The next step is to implement some CI/CD and setup Gitea Actions for Hugo website, to push website to AWS S3 automatically when master branch is updated.
We have already - after installing, configuring and testing Gitea Gitea Server Setup, and setting up Gitea SSL, configured Hugo website deployment to AWS S3.
OK. Let’s go
Generate new token for Gitea runner
Navigate to https://your-gitea-server/your-user/your-repo/settings/actions/runners
and click Create New Runner
copy Registration Token
Start new Gitea Runner
ssh to the server where your new gitea runner will be running
and start docker container. you can start it as a separate executable, run it as a service etc, but here I’m using a docker container.
sudo docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-e GITEA_INSTANCE_URL=http://<my-gitea-server>:3000/ \
-e GITEA_RUNNER_REGISTRATION_TOKEN=<my-registration-token> \
-e GITEA_RUNNER_NAME=srv-act-runner \
--name my_runner \
--restart always \
-d docker.io/gitea/act_runner:latest
Check that runner registered ok
Navigate to https://your-gitea-server/your-user/your-repo/settings/actions/runners
and you should see that it is already running
Create a couple of AWS secrets
Go to: https://your-gitea-server/your-user/your-repo/settings/actions/secrets
And create a couple of huge secrets: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. You know what they mean, right?
Create Gitea Workflow for building and deploying Hugo to s3
In your hugo project, in the folder .gitea/workflows
create a file hugo-deploy.yaml
name: Gitea Actions - Hugo Deploy
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
Hugo-Deploy:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- name: Setup Hugo
uses: peaceiris/actions-hugo@v3
with:
hugo-version: '0.134.1' # or remove this for the latest
extended: true
- name: List files in the repository
run: |
ls
- name: Build
run: hugo
- name: Deploy
run: hugo deploy
env:
AWS_REGION: 'ap-southeast-2'
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: echo "🍏 This job's status is ${{ job.status }}."
If somehow you do not have a huge desire host your site in Sydney - change AWS_REGION to whatever you like more.
Commit and push
After pushing changes to the server you should see on the page https://your-gitea-server/your-user/your-repo/actions something close to
Have a great day!