Version the stylesheet URL by content hash at image build

A CDN in front of the site caches /style.css for hours, so a redeploy served
new HTML with the old stylesheet. The Dockerfile now rewrites the link to
style.css?v=<hash> in the built image (source stays unversioned) and fails
the build if the rewrite does not apply.
This commit is contained in:
2026-11-07 21:29:43 -07:00
parent eb101c3e05
commit a339ea93b1
+6
View File
@@ -1,3 +1,9 @@
FROM caddy:2 FROM caddy:2
COPY Caddyfile /etc/caddy/Caddyfile COPY Caddyfile /etc/caddy/Caddyfile
COPY dist/ /srv/fieldwork/ COPY dist/ /srv/fieldwork/
# A CDN in front of the site may cache /style.css for hours. Version its URL by content hash
# so a changed stylesheet is always fetched fresh. The build fails if the rewrite did not apply.
RUN h=$(md5sum /srv/fieldwork/style.css | cut -c1-10) \
&& sed -i "s|href=\"style.css\"|href=\"style.css?v=${h}\"|" /srv/fieldwork/index.html \
&& grep -q "style.css?v=${h}" /srv/fieldwork/index.html