aboutsummaryrefslogtreecommitdiff
path: root/roles/git/files/runner-zola/webhook.sh
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-12-30 15:01:12 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-12-30 15:01:12 +0100
commit543b1f369576430b76f0aa7d44c4fe6f7e9785b4 (patch)
tree6b84bbdfe49a73db7e9920255e8a1f0d6a516c06 /roles/git/files/runner-zola/webhook.sh
parentad21e610481ae8b39a314dd5b9d6e16732b5943a (diff)
downloadansible-memzero-543b1f369576430b76f0aa7d44c4fe6f7e9785b4.tar.gz
ansible-memzero-543b1f369576430b76f0aa7d44c4fe6f7e9785b4.zip
git: add zola runner to automatically build & depoly the blog
Diffstat (limited to 'roles/git/files/runner-zola/webhook.sh')
-rwxr-xr-xroles/git/files/runner-zola/webhook.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/roles/git/files/runner-zola/webhook.sh b/roles/git/files/runner-zola/webhook.sh
new file mode 100755
index 0000000..6f20c8c
--- /dev/null
+++ b/roles/git/files/runner-zola/webhook.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# Simple webhook to build and deploy latest blog version.
+# The webhook allows to pass an optional ref as url path.
+#
+# Examples:
+# curl <host> ; Will deploy main ref
+# curl <host>/blub ; Will deploy blub ref
+
+while true; do
+ echo "Wait for webhook trigger ..."
+
+ # Wait until webhook is triggered and parse out optional branch info.
+ # The branch info can be passed via the url path, an example is:
+ # GET /blub HTTP/1.1
+ REF=$(echo -e "HTTP/1.0 204 No Content\r\nConnection: close\r\n\r" | nc -l -p 80 | awk '/GET/ { print $2; }' | tr -d '/')
+ # If we got a ref use it else default to main.
+ REF=${REF:-main}
+
+ if [ ! -d blog ]; then
+ git clone https://git.memzero.de/blog
+ fi
+ git -C blog submodule init
+ git -C blog submodule update
+ git -C blog fetch --prune
+ echo "Checking out ref: $REF"
+ git -C blog checkout $REF || continue
+
+ zola --root blog build || continue
+
+ # webroot must be mounted at /www.
+ rm -rf /www/blog
+ mv blog/public /www/blog
+
+ echo "SUCCESS: Updated /www/blog"
+done