Hello From GitHub
This blog post is coming from my terminal - and all going well a webhook will trigger an action on my hosting platform to update the site.
With a little help from my LLM provider of choice (Mistral) I have changed my website setup in a number of ways
- Created a docker compose file to run my website locally
- Set up the website repositories on GitHub and the web host server
- Installed 'webhook' and set up as a sytemd service
- Added a GitHub personal access token for read/write
- Customised hooks.json to run "deploy-site.sh" to pull from github only when I push to GitHub
hooks.json example
{
"id": "deploy-leofebey-com",
"execute-command": "/home/leo/deploy-site.sh",
"pass-arguments-to-command": [
{ "source": "string", "name": "leo" },
{ "source": "string", "name": "leofebey.com" },
{ "source": "url", "name": "token" }
],
"include-command-output-in-response": true
},
deploy-site.sh
#!/bin/bash
# /usr/local/bin/deploy-site.sh <hestia_user> <domain> <token>
set -euo pipefail
USER_NAME="${1:?Usage: deploy-site.sh <user> <domain> <token>}"
DOMAIN="${2:?Usage: deploy-site.sh <user> <domain> <token>}"
TOKEN="${3:-}"
# Per-site config: branch + deploy token.
# Unknown domains are rejected before doing anything.
declare -A BRANCHES=(
["leofebey.com"]="main"
)
declare -A TOKENS=(
["leofebey.com"]="OMITTED"
)
BRANCH="${BRANCHES[$DOMAIN]:-}"
[ -n "$BRANCH" ] || { echo "Unknown domain: $DOMAIN"; exit 1; }
[ "$TOKEN" = "${TOKENS[$DOMAIN]:-}" ] || { echo "Invalid token"; exit 1; }
# If invoked as root (from the webhook service), re-exec as the site user
if [ "$(id -un)" = "root" ]; then
exec sudo -u "$USER_NAME" "$0" "$USER_NAME" "$DOMAIN" "$TOKEN"
fi
WEBROOT="/home/$USER_NAME/web/$DOMAIN/public_html"
if [ ! -d "$WEBROOT/.git" ]; then
echo "No git repo at $WEBROOT — was the site set up?" >&2
exit 1
fi
if ! git -C "$WEBROOT" remote get-url origin | grep -qF "$DOMAIN"; then
echo "Repo origin at $WEBROOT does not look like it belongs to $DOMAIN" >&2
exit 1
fi
# Prevent overlapping deploys of the same site
LOCKDIR="/tmp/deploy-${DOMAIN//\//_}.lock"
if ! mkdir "$LOCKDIR" 2>/dev/null; then
echo "Deploy already running for $DOMAIN, aborting."
exit 0
fi
trap 'rmdir "$LOCKDIR"' EXIT
cd "$WEBROOT"
git fetch origin "$BRANCH"
git reset --hard "origin/$BRANCH"
git rev-parse "origin/$BRANCH" > .version.txt
# Grav sites: clear cache (harmless no-op for non-Grav sites)
rm -rf cache/* 2>/dev/null || true
echo "Deployed $DOMAIN: $(git rev-parse --short "origin/$BRANCH")"
So yeah - if this page exists it will have worked!
Page views: 36