Skip to content

Commit

Permalink
Dockerfile: cachebust
Browse files Browse the repository at this point in the history
  • Loading branch information
iakat committed Apr 2, 2023
1 parent 75039fd commit d026bda
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
23 changes: 23 additions & 0 deletions install_cachebust.sh
Original file line number Diff line number Diff line change
@@ -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[@]}"
}

0 comments on commit d026bda

Please sign in to comment.