summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-07-15 14:36:32 +0300
committerLars Wirzenius <liw@liw.fi>2023-07-15 14:36:32 +0300
commit3f61ba245fa3f03653fcecc871c5eae4f2019a1a (patch)
tree78d0841477ae88ee7f347b38bee524af825242ff
parent443aa4cf07b074b41fd6036a9b8496cbc9d58a90 (diff)
downloadambient-ci-3f61ba245fa3f03653fcecc871c5eae4f2019a1a.tar.gz
feat: incremental ikiwiki site building
Sponsored-by: author
-rw-r--r--ikiwiki-ambient-script13
-rwxr-xr-xikiwiki.sh56
2 files changed, 55 insertions, 14 deletions
diff --git a/ikiwiki-ambient-script b/ikiwiki-ambient-script
index 19cc585..54fe257 100644
--- a/ikiwiki-ambient-script
+++ b/ikiwiki-ambient-script
@@ -5,8 +5,13 @@ set -xeuo pipefail
export HOME=/workspace
mkdir /workspace/html
-sed -i 's#^srcdir:.*#srcdir: /workspace/src#' ikiwiki.setup
-sed -i 's#^destdir:.*#destdir: /workspace/html#' ikiwiki.setup
+cp ikiwiki.setup /workspace
+sed -i 's#^srcdir:.*#srcdir: /workspace/src#' /workspace/ikiwiki.setup
+sed -i 's#^destdir:.*#destdir: /workspace/cache/html#' /workspace/ikiwiki.setup
-ikiwiki --setup ikiwiki.setup --libdir /workspace/deps --rebuild --verbose
-tar -cf "$1" -C /workspace/html .
+rm -rf .ikiwiki
+cp -a /workspace/cache/.ikiwiki .ikiwiki
+ikiwiki --setup /workspace/ikiwiki.setup --libdir /workspace/deps --refresh --verbose
+
+find /workspace/cache/.ikiwiki -mindepth 1 -delete
+mv .ikiwiki/* /workspace/cache/.ikiwiki
diff --git a/ikiwiki.sh b/ikiwiki.sh
index 7d8a778..90e444b 100755
--- a/ikiwiki.sh
+++ b/ikiwiki.sh
@@ -1,30 +1,66 @@
#!/bin/bash
+#
+# Build an ikiwiki of mine, incrementally, and publish it on my local
+# web server.
+#
+# Usage: $0 /path/to/ikiwiki.setup
-set -xeuo pipefail
+set -euo pipefail
setup="$1"
+# Get local source and html directories. The source directory will get
+# an .ambient-script, if missing. The html directory will be used by
+# the build, for incremental builds, and will be updated from the VM
+# after the build.
srcdir="$(sed -n '/^srcdir: */s///p' "$setup")"
destdir="$(sed -n '/^destdir: */s///p' "$setup")"
+# Where this script resides. We'll get the ambient-run script and
+# other files from there.
ambientdir="$(dirname "$0")"
-artifact="$(mktemp)"
-artifactdir="$(mktemp -d)"
-trap 'rm -rf "$artifact $artifactdir"' EXIT
+# A temporary directory for helper files.
+tmp="$(mktemp -d)"
+trap 'rm -rf "$tmp"' EXIT
-if [ ! -e "$srcdir/.ambient-script" ]; then
- cp ikiwiki-ambient-script "$srcdir/.ambient-script"
+# Create a cache, with the local html directory and the site's
+# .ikiwiki directory.
+cache="$tmp/cache"
+mkdir "$cache" "$cache/.ikiwiki" "$cache/html"
+if [ -e "$srcdir/.ikiwiki" ]; then
+ rsync -a "$srcdir/.ikiwiki/." "$cache/.ikiwiki/."
fi
+if [ -e "$destdir" ]; then
+ rsync -a "$destdir/." "$cache/html/."
+fi
+
+# Always install an .ambient-script the source directory. We gladly
+# overwrite any existing one. I don't keep one in my site sources.
+script="$srcdir/.ambient-script"
+cp "$ambientdir/ikiwiki-ambient-script" "$script"
+
+# Run ikiwiki under ambient-run. The input is the local source
+# directory. An incremental build needs the local html directory and
+# the site's .ikiwiki directory, and changes to those need to persist
+# between runs, so we use the cache mechanism.
"$ambientdir/ambient-run" \
--image ~/tmp/ambient/ambient-ikiwiki.qcow2 \
- --artifact "$artifact" \
--dependencies ~/.ikiwiki/ \
+ --cache "$cache" \
--log ~/tmp/ambient/log \
"$srcdir"
+# Remove the script installed one.
+rm "$script"
+
+# Copy back .ikiwiki and html to source directory and local html
+# directory.
+install -d "$srcdir/.ikiwiki" "$destdir" # create them if missing"
+rsync -av --del "$cache/.ikiwiki/." "$srcdir/.ikiwiki/."
+rsync -av --del "$cache/html/." "$destdir/."
+
+# Update the local web server.
remote=_ewww@web
ssh "$remote" install -d /srv/http/web/.
-
-tar -C "$artifactdir" -xf "$artifact"
-rsync -a --del "$artifactdir/." "$remote:/srv/http/."
+rsync -a --del "$cache/html/." "$remote:/srv/http/."