From d026bda93243c91b77d6d64114f8f91abdea33d2 Mon Sep 17 00:00:00 2001 From: Katia Date: Sat, 1 Apr 2023 16:01:09 +0200 Subject: [PATCH] Dockerfile: cachebust --- Dockerfile | 4 +++- install_cachebust.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 install_cachebust.sh diff --git a/Dockerfile b/Dockerfile index fa274b4e6..1995c6b58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,11 @@ FROM nginx:alpine WORKDIR /opt/tar1090 COPY html . +COPY install_cachebust.sh /tmp COPY nginx.conf /etc/nginx/tar1090.conf RUN set -ex && \ - apk add --virtual=.build-deps git sed && \ + apk add --virtual=.build-deps git sed bash && \ + bash /tmp/install_cachebust.sh && \ mkdir -p /opt/tar1090-db && \ wget -qO- https://github.com/katlol/tar1090-db/releases/latest/download/db.tar | tar -C /opt/tar1090-db -xvf - && \ ln -s /opt/tar1090-db/db /opt/tar1090/db2 && \ diff --git a/install_cachebust.sh b/install_cachebust.sh new file mode 100644 index 000000000..7df5f75a5 --- /dev/null +++ b/install_cachebust.sh @@ -0,0 +1,23 @@ +#!/bin/bash +set -ex +{ + spritename="sprites_$(md5sum images/sprites.png | cut -d' ' -f1).png" + mv "images/sprites.png" "images/${spritename}" + sed -i -e "s#sprites.png#${spritename}#g" script.js + sed -i -e "s#sprites.png#${spritename}#g" index.html +} + +# cache busting js / css +{ + sedargs=("sed" "-i" "index.html") + for file in dbloader.js defaults.js early.js flags.js formatter.js layers.js markers.js planeObject.js registrations.js script.js style.css; do + md5sum=$(md5sum $file | cut -d' ' -f1) + prefix=$(cut -d '.' -f1 <<< "$file") + postfix=$(cut -d '.' -f2 <<< "$file") + newname="${prefix}_${md5sum}.${postfix}" + mv "$file" "$newname" + sedargs+=("-e" "s#${file}#${newname}#") + done + + "${sedargs[@]}" +}