Denne nettsiden er nå satt opp til å automatisk deployes ved hver eneste push til master branch. Den vil da bygge Hugo siten, for deretter å pushe oppdateringer til min webserver via rsync.
Dette er løst med følgende Github Actions pipeline script:
name: Build Hugo Website
on:
push:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
- name: Install Hugo Theme
run: git submodule update --init --recursive
- name: Clean public folder
run: rm -rf public/*
- name: Build
run: hugo --minify
- name: Deploy website with rsync
uses: burnett01/rsync-deployments@7.0.1
with:
switches: -avzr --quiet --delete
path: public/
remote_path: ${{ secrets.DEPLOY_PATH }}
remote_host: ${{ secrets.DEPLOY_HOST_IP }}
remote_user: ${{ secrets.DEPLOY_SSH_USER }}
remote_key: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
På webserveren måtte følgende også gjøres: Opprette SSH nøkkel:
ssh-keygen -t rsa -b 4096 -C "github-actions-deploy"
Legg nøkkel til authorized_keys
cat ~/path/to/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Kopiere privat nøkkel til Github secrets
cat ~/path/to/id_rsa