Gitea Actions를 사용하여 Hugo 웹사이트를 AWS S3에 배포하기
AWS S3에 Gitea와 Hugo를 설정한 후...
다음 단계는 CI/CD를 구현하고, Gitea Actions for Hugo website, to push website to AWS S3를 설정하여 master 브랜치가 업데이트될 때 자동으로 웹사이트를 AWS S3에 푸시하는 것입니다.
우리는 이미 Gitea를 설치하고 구성하여 테스트한 후, Gitea Server Setup과 setting up Gitea SSL을 설정한 상태이며, Hugo website deployment to AWS S3도 구성했습니다.
좋습니다. 시작해 보겠습니다.
Gitea runner를 위한 새로운 토큰 생성
https://your-gitea-server/your-user/your-repo/settings/actions/runners로 이동한 후 Create New Runner
를 클릭합니다.
등록 토큰을 복사합니다.
새로운 Gitea Runner 시작
새로운 Gitea runner가 실행될 서버에 ssh로 접속한 후, docker 컨테이너를 시작합니다. 별도의 실행 파일로 시작하거나 서비스로 실행할 수도 있지만, 여기서는 docker 컨테이너를 사용합니다.
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
Runner가 정상적으로 등록되었는지 확인
https://your-gitea-server/your-user/your-repo/settings/actions/runners로 이동한 후, 이미 실행되고 있는지 확인합니다.
AWS 비밀 정보 생성
https://your-gitea-server/your-user/your-repo/settings/actions/secrets로 이동한 후, AWS_ACCESS_KEY_ID와 AWS_SECRET_ACCESS_KEY라는 두 개의 큰 비밀 정보를 생성합니다. 이들이 무엇을 의미하는지 아시겠죠?
Hugo를 S3에 빌드 및 배포하기 위한 Gitea 워크플로우 생성
Hugo 프로젝트의 .gitea/workflows
폴더에 hugo-deploy.yaml
파일을 생성합니다.
name: Gitea Actions - Hugo Deploy
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on:
push:
branches:
- master
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 }}."
혹시 시드니에 호스팅할 의지가 없다면, AWS_REGION을 원하는 값으로 변경하시면 됩니다.
이 설정:
on:
push:
branches:
- master
master 브랜치로의 모든 푸시 및 머지 작업을 처리합니다.
커밋 및 푸시
서버에 변경사항을 푸시한 후, https://your-gitea-server/your-user/your-repo/actions 페이지에서 다음과 유사한 내용을 확인할 수 있습니다.
좋은 하루 보내세요!
유용한 링크
- Deploy Hugo-generated website to AWS S3
- Submit Google Form in Hugo Website
- Hugo Cheat Sheet
- Most popular themes for Hugo
- Mainroad theme image handling
- Markdown Cheatsheet
- Gitea Server Setup
- Setting up Gitea SSL
- Reinstall linux
- Bash Cheat Sheet
- Hugo Space
- How to store thumbnail images in page bundle folder for Hugo sites with Mainroad theme