aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--roles/git/files/runner-zola/Dockerfile11
-rwxr-xr-xroles/git/files/runner-zola/webhook.sh36
-rw-r--r--roles/git/tasks/main.yml23
3 files changed, 69 insertions, 1 deletions
diff --git a/roles/git/files/runner-zola/Dockerfile b/roles/git/files/runner-zola/Dockerfile
new file mode 100644
index 0000000..be1eb6e
--- /dev/null
+++ b/roles/git/files/runner-zola/Dockerfile
@@ -0,0 +1,11 @@
+FROM alpine:latest
+
+RUN apk add --update-cache --upgrade --no-cache --purge \
+ zola git \
+ && rm -rf /var/cache/apk
+
+EXPOSE 80
+WORKDIR /tmp
+
+COPY webhook.sh /
+ENTRYPOINT ["/webhook.sh"]
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
diff --git a/roles/git/tasks/main.yml b/roles/git/tasks/main.yml
index 0557615..131b971 100644
--- a/roles/git/tasks/main.yml
+++ b/roles/git/tasks/main.yml
@@ -1,11 +1,14 @@
---
- name: Copy container build files
ansible.builtin.copy:
- src: gitolite-cgit
+ src: "{{ item }}"
dest: "{{ DATA_ROOT }}/git"
owner: "{{ USER }}"
group: "{{ USER }}"
mode: preserve
+ loop:
+ - gitolite-cgit
+ - runner-zola
- name: Build gitolite cgit image
containers.podman.podman_image:
@@ -38,3 +41,21 @@
jump: ACCEPT
comment: Accept gitolite SSH connections.
become: true
+
+- name: Build zola runner image
+ containers.podman.podman_image:
+ name: runner-zola
+ path: "{{ DATA_ROOT }}/git/runner-zola"
+ force: true
+ register: runner_zola_build
+
+- name: Start zola runner
+ containers.podman.podman_container:
+ name: runner-zola
+ image: runner-zola
+ network: "{{ NETWORK }}"
+ volumes:
+ # Mount the webserver webroot to deploy the blog.
+ # Use 'z' to shared-ly relable selinux contexts.
+ - "{{ DATA_ROOT }}/nginx/www:/www:z"
+ recreate: "{{ runner_zola_build.changed }}"