Deploy
Updates
All updates need to be pushed to the Github repo.
A job is running on the Raspberry to check the repo every X minutes for changes and if yes
- downloads them,
- runs hugo to create the HTML output
- and syncs the output with the html folder.
An initial download of the GIT repo is required at /var/wiki_deploy to prepare everything:
1sudo git clone https://<token here>@github.com/maxbobse/wiki.gitdeploy.sh
The deployment script is stored at /var/wiki_deploy
1#!/bin/bash
2
3set -euo pipefail
4
5REPO_DIR="/opt/wiki_deploy/wiki"
6DEPLOY_DIR="/var/www/html"
7BRANCH="main"
8
9echo "====================================="
10echo "$(date): Checking for updates"
11echo "====================================="
12
13cd "$REPO_DIR"
14
15git fetch origin
16
17LOCAL=$(git rev-parse HEAD)
18REMOTE=$(git rev-parse origin/$BRANCH)
19
20if [ "$LOCAL" = "$REMOTE" ]; then
21 echo "No updates found."
22 exit 0
23fi
24
25echo "Updates found. Pulling changes..."
26
27git reset --hard
28git pull origin $BRANCH
29
30echo "Building Hugo site..."
31
32rm -rf public
33
34hugo --minify
35
36echo "Deploying..."
37
38sudo mkdir -p "$DEPLOY_DIR"
39
40#rsync -av --delete public/ "$DEPLOY_DIR/"
41rsync -av public/ "$DEPLOY_DIR/"
42
43echo "Deployment complete."Remember to make the script executable:
1sudo chmod +x /opt/wiki_deploy/deploy.shScheduling
The script is scheduled using systemd:
1sudo nano /etc/systemd/system/wiki-deploy.service 1[Unit]
2Description=Deploy Hugo Wiki
3After=network.online.target
4Wants=network.online.target
5
6[Service]
7Type=oneshot
8WorkingDirectory=/opt/wiki_deploy
9ExecStart=/opt/wiki_deploy/deploy.sh
10
11#Optional logging
12StandardOutput=journal
13StandardError=journal1sudo systemctl daemon-reload
2sudo systemctl start wiki-deploy.service
3sudo systemctl status wiki-deploy.serviceNext step is to add the timer that calls the service:
sudo nano /etc/systemd/system/wiki-deploy.timer
1[Unit]
2Description=Run Wiki Deploy Every 2 minutes
3
4[Timer]
5OnBootSec=2min
6OnUnitActiveSec=2min
7Persistent=true
8
9[Install]
10WantedBy=timers.target1sudo systemctl enable --now wiki-deploy.timerList all timers
1systemctl list-timersLast logging records
1journalctl -u wiki-deploy.service -n 100Real time logging
1journalctl -u wiki-deploy.service -f