Skip to content

Commit

Permalink
Merge pull request #16698 from kvadevack/gzip-static
Browse files Browse the repository at this point in the history
Docker image: serve pre-compressed assets using gzip_static
  • Loading branch information
turt2live authored Mar 24, 2021
2 parents 0a793d2 + b8b8a5e commit 8ad5640
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,20 @@ RUN cp /src/config.sample.json /src/webapp/config.json
# Ensure we populate the version file
RUN dos2unix /src/scripts/docker-write-version.sh && bash /src/scripts/docker-write-version.sh

# Pre-compress for gzip_static
RUN find /src/webapp -type f \
\( -iname '*.css' -o -iname '*.js' -o -iname '*.json' -o -iname '*.html' \
-o -iname '*.svg' -o -iname '*.ttf' -o -iname '*.wasm' \) \
-exec gzip -9 -k {} \; -exec touch -r {} {}.gz \;

# App
FROM nginx:alpine

COPY --from=builder /src/webapp /app

# Insert wasm type into Nginx mime.types file so they load correctly.
RUN sed -i '3i\ \ \ \ application/wasm wasm\;' /etc/nginx/mime.types
RUN sed -i '3i\ \ \ \ application/wasm wasm\;' /etc/nginx/mime.types \
&& sed -i '2i\ gzip_static on\;' /etc/nginx/conf.d/default.conf

RUN rm -rf /usr/share/nginx/html \
&& ln -s /app /usr/share/nginx/html

0 comments on commit 8ad5640

Please sign in to comment.