Skip to content

Commit

Permalink
Merge pull request #296 from kiwix/donorbox
Browse files Browse the repository at this point in the history
Use a custom kiwix-serve index template
  • Loading branch information
rgaudin authored Oct 29, 2024
2 parents 26a6bb8 + d1437d1 commit 5a6387d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
8 changes: 7 additions & 1 deletion zim/library/backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down
38 changes: 38 additions & 0 deletions zim/library/update-kiwixserve-template.job.yaml
Original file line number Diff line number Diff line change
@@ -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"
66 changes: 66 additions & 0 deletions zim/library/update-kiwixserve-template.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
*** index.html 2024-10-29 12:16:01
--- index-kiwix.html 2024-10-29 12:18:18
***************
*** 4,10 ****
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link type="root" href="{{root}}">
! <title>Welcome to Kiwix Server</title>
<link
type="text/css"
href="{{root}}/skin/kiwix.css?KIWIXCACHEID"
--- 4,10 ----
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link type="root" href="{{root}}">
! <title>Kiwix Library</title>
<link
type="text/css"
href="{{root}}/skin/kiwix.css?KIWIXCACHEID"
***************
*** 39,44 ****
--- 39,46 ----
<script src="{{root}}/skin/isotope.pkgd.min.js?KIWIXCACHEID" defer></script>
<script src="{{root}}/skin/iso6391To3.js?KIWIXCACHEID"></script>
<script type="text/javascript" src="{{root}}/skin/index.js?KIWIXCACHEID" defer></script>
+ <link rel="stylesheet" type="text/css" href="https://donorbox.org/animate-popup-donate-button.css">
+ <script type="text/javascript" id="donorbox-donate-button-installer" src="https://donorbox.org/install-donate-button.js" data-target="_blank" data-href="https://donorbox.org/kiwix?default_interval=m" data-style="background: rgb(255, 153, 51); color: rgb(255, 255, 255); text-decoration: none; font-family: Verdana, sans-serif; display: flex; font-size: 16px; padding: 8px 22px 8px 18px; border-radius: 5px 5px 0px 0px; gap: 8px; width: fit-content; line-height: 24px; position: fixed; top: 50%; transform-origin: center center; z-index: 9999; overflow: hidden; right: 20px; transform: translate(50%, -50%) rotate(-90deg);" data-button-cta="Support" data-img-src="https://donorbox.org/images/white_logo.svg"></script>
</head>
<body>
<noscript>
EOF
)

cleanup() {
rm -f $TEMPLATE_TMP_PATH $TEMPLATE_SRC_PATH
}

echo "Cleaning up…"

cleanup

echo "Downloading source template from libkiwix version ${LIBKIWIX_VERSION}"

curl -o $TEMPLATE_SRC_PATH -L $TEMPLATE_URL

echo "Applying Kiwix Patch…"

echo "$KIWIX_PATCH" | patch --input=- --output=$TEMPLATE_TMP_PATH -p1 $TEMPLATE_SRC_PATH

echo "Replacing final file…"

mv $TEMPLATE_TMP_PATH $TEMPLATE_PATH

echo "Cleaning up"

cleanup

echo "done."

0 comments on commit 5a6387d

Please sign in to comment.