Task #167
closed
Task #174: Automatically deploy blog on each fossil commit
Fossil: setup after-receive hooks to deploy nawan.my.id
Added by Nawan 24 days ago.
Updated 13 days ago.
Description
#!/bin/bash
# --- CONFIGURATION ---
# Path to the Fossil repository file on the server
FOSSIL_REPO="/path/to/mywebsite.fossil"
# The temporary directory to create the working copy for Hugo build
# This must be outside the web root.
WORK_DIR="/tmp/hugo_build_temp"
# The final destination for the static site files on the web server (via rsync)
# This is usually the document root (e.g., public_html)
# Replace user@host:path_to_webroot with your actual details
RSYNC_DEST="user@host:/var/www/myhugo-site-public"
# --- DEPLOYMENT LOGIC ---
# Ensure we operate in a clean environment
mkdir -p "$WORK_DIR"
cd "$WORK_DIR" || exit 1
# 1. Clean up any previous checkout (important for a fresh build)
rm -rf "$WORK_DIR"/*
# 2. Check out the latest committed version from the repository
# We use 'fossil open' to establish a checkout connection
# The '--once' flag tells it to only run the checkout and exit (not start a UI)
fossil open "$FOSSIL_REPO"
# 3. Build the Hugo site
# The 'hugo' command builds the site into the 'public/' subdirectory of the
# current working directory (which is $WORK_DIR)
# Use '--cleanDestinationDir' if you want a complete wipe before building
echo "Building Hugo site..."
hugo
# Check if the Hugo build was successful
if [ $? -ne 0 ]; then
echo "Hugo build failed! Aborting deployment."
exit 1
fi
# 4. Deploy the static files using rsync over SSH
# -a: archive mode (preserves permissions, ownership, etc.)
# -v: verbose
# -z: compress file data during transfer
# --delete: delete extra files from the destination that are not present in the source
echo "Deploying with rsync..."
rsync -avz --delete public/ "$RSYNC_DEST"
# 5. Clean up the temporary checkout directory after successful deployment
cd /
fossil close --force || true # Close the checkout connection
rm -rf "$WORK_DIR"
echo "Deployment complete."
- Blocked by Task #166: Install fossil from debian repo added
- Blocked by deleted (Task #166: Install fossil from debian repo)
- Follows Task #166: Install fossil from debian repo added
- Follows deleted (Task #166: Install fossil from debian repo)
- Blocked by Task #166: Install fossil from debian repo added
- Blocked by deleted (Task #166: Install fossil from debian repo)
- Parent task deleted (
#164)
- Target version set to Q4 2025
- Blocks Idea #165: Artikel ulasan Nimona added
- Blocks Idea #3: Artikel tentang Obsidian dan vendor lock-in added
- Blocks Idea #119: Artikel tentang suka duka menggunakan Redmine added
- Blocks deleted (Idea #3: Artikel tentang Obsidian dan vendor lock-in)
- Blocks deleted (Idea #165: Artikel ulasan Nimona)
- Blocks deleted (Idea #119: Artikel tentang suka duka menggunakan Redmine)
- Estimated time set to 0:15 h
- Start date set to 2025-12-13
- Estimated time deleted (
0:15 h)
- Estimated time set to 0:15 h
- Start date changed from 2025-12-13 to 2025-12-15
- Start date deleted (
2025-12-15)
- Description updated (diff)
- Status changed from New to In Progress
- % Done changed from 0 to 30
- % Done changed from 30 to 60
Memutuskan untuk mengimplementasikan after-receive hook di repositori lokal alih-alih di server.
Nawan wrote in #note-23:
Memutuskan untuk mengimplementasikan after-receive hook di repositori lokal alih-alih di server.
Ternyata lebih mudah jika di server karena after-receive hook tidak berjalan setelah mengkomit perubahan lokal dan dalam banyak kasus perlu dibantu dengan cron.
- Blocked by Task #186: Enable WAL mode for www.fossil database added
Because of the way I set up Fossil (#170), the after-receive hook script written in Bash will not work unless Bash, Hugo, and everything else necessary to run are mounted in the chroot directory. This is because, in my current configuration, Fossil automatically drops into the chroot jail. It may be worth considering using the before-commit hook instead, which I already use to test whether it can build.
- Copied to Task #187: Fossil: setup before-commit hooks to deploy nawan.my.id added
- Status changed from In Progress to Declined
- % Done changed from 60 to 100
I decided not to implement this task in favour of #187 because I think it's too complex than with before-commit hooks on local repository.
Also available in: Atom
PDF