From d1437d1be4986cae53906ac8a5edabb08e04c0f8 Mon Sep 17 00:00:00 2001 From: rgaudin Date: Tue, 29 Oct 2024 14:47:06 +0000 Subject: [PATCH] Use a custom kiwix-serve index template - Start kiwix-serve with --custom-index option - Add a Job that creates this index.html from the Github version (pinned version) applying two patches: - Changing the title name (yay) - Adding the donorbox sticky donate button This jobs is supposed to be ran manually when we change kiwix-serve version --- zim/library/backend.yaml | 8 ++- .../update-kiwixserve-template.job.yaml | 38 +++++++++++ zim/library/update-kiwixserve-template.sh | 66 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 zim/library/update-kiwixserve-template.job.yaml create mode 100755 zim/library/update-kiwixserve-template.sh diff --git a/zim/library/backend.yaml b/zim/library/backend.yaml index 9f22dca..74f72e5 100644 --- a/zim/library/backend.yaml +++ b/zim/library/backend.yaml @@ -19,10 +19,12 @@ spec: # /!\ manually purge kiwix-serve cache on kiwix-serve version upgrade # curl -X PURGE -H "X-Purge-Type: kiwix-serve" http://library-frontend-service # also check that varnish hack still necessary (gzip, endpoints) + # /!\ manually trigger update-kiwixserve-template Job on kiwix-serve upgrade + # after having updated the LIBKIWIX_VERSION field in env (and tested!) - image: ghcr.io/kiwix/kiwix-tools:3.7.0-1 imagePullPolicy: IfNotPresent name: kiwix-tools - args: ["kiwix-serve", "-b", "--library", "--monitorLibrary", "--threads", "16", "--searchLimit", "5", "--nodatealias", "/data/library/internal_library.xml"] + args: ["kiwix-serve", "-b", "--library", "--monitorLibrary", "--threads", "16", "--searchLimit", "5", "--nodatealias", "--customIndex", "/data/kiwix-serve-templates/index-template.html", "/data/library/internal_library.xml"] ports: - containerPort: 80 livenessProbe: @@ -43,6 +45,10 @@ spec: subPath: internal_library.xml name: library-volume readOnly: true + - mountPath: "/data/kiwix-serve-templates" + subPath: kiwix-serve-templates + name: library-volume + readOnly: true resources: requests: memory: "2Gi" diff --git a/zim/library/update-kiwixserve-template.job.yaml b/zim/library/update-kiwixserve-template.job.yaml new file mode 100644 index 0000000..907fac0 --- /dev/null +++ b/zim/library/update-kiwixserve-template.job.yaml @@ -0,0 +1,38 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: update-kiwixserve-template + namespace: zim +spec: + backoffLimit: 1 + template: + spec: + containers: + - name: maintenance + image: ghcr.io/kiwix/maintenance:latest + imagePullPolicy: Always + env: + # this must be set according to the libkiwix version that is bundled in the + # kiwix-serve version we use in library-data-backend-deployment + # can be obtain with `kiwix-serve --version` + - name: LIBKIWIX_VERSION + value: "14.0.0" + - name: INSTALL_SCRIPTS + value: "update-template#github://kiwix/operations/zim/library/update-kiwixserve-template.sh\n" + volumeMounts: + - mountPath: "/data" + subPath: kiwix-serve-templates + name: library-volume + readOnly: false + args: ["/usr/local/bin/update-template"] + resources: + requests: + cpu: 200m + memory: 1Gi + volumes: + - name: library-volume + persistentVolumeClaim: + claimName: kiwix-library-pvc + restartPolicy: Never + nodeSelector: + k8s.kiwix.org/role: "storage" diff --git a/zim/library/update-kiwixserve-template.sh b/zim/library/update-kiwixserve-template.sh new file mode 100755 index 0000000..f32cc87 --- /dev/null +++ b/zim/library/update-kiwixserve-template.sh @@ -0,0 +1,66 @@ +#!/bin/bash +set -e + +TEMPLATE_PATH=/data/index-template.html +TEMPLATE_TMP_PATH="${TEMPLATE_PATH}.tmp" +TEMPLATE_SRC_PATH="${TEMPLATE_PATH}.src" +TEMPLATE_URL="https://github.com/kiwix/libkiwix/raw/refs/tags/${LIBKIWIX_VERSION}/static/templates/index.html" +KIWIX_PATCH=$(cat < + + +! Welcome to Kiwix Server + + + +! Kiwix Library + + + ++ ++ + + +