diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2019-06-24 20:21:08 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2019-06-24 20:21:08 +0300 |
commit | b4c532e2a3bd05316381ac914c175df66a9ecb68 (patch) | |
tree | da49b6b7876394e1ba9aeafcf397f9cf7601ea13 | |
parent | 7e701518da02827f18d373c104aa91829eb67877 (diff) | |
parent | 69690954a4ba52af68ee7a40b61a75746160d466 (diff) |
Merge branch 'compress-img' into 'master'
Compress PNG images during Docker build
Closes #368
See merge request gitlab-com/gitlab-docs!478
-rw-r--r-- | dockerfiles/Dockerfile.bootstrap | 2 | ||||
-rw-r--r-- | dockerfiles/Dockerfile.builder.onbuild | 3 | ||||
-rwxr-xr-x | scripts/compress_images.sh | 29 |
3 files changed, 33 insertions, 1 deletions
diff --git a/dockerfiles/Dockerfile.bootstrap b/dockerfiles/Dockerfile.bootstrap index 63a5b6e2..fc9b5359 100644 --- a/dockerfiles/Dockerfile.bootstrap +++ b/dockerfiles/Dockerfile.bootstrap @@ -25,6 +25,6 @@ WORKDIR /source RUN NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --jobs 4 # Install packages needed at build and run time -RUN apk add --no-cache libxslt libcurl openssl git grep bash +RUN apk add --no-cache libxslt libcurl openssl git grep bash pngquant CMD echo "Nothing to do here. This is the bootstrap image that contains all dependencies to build the docs site." diff --git a/dockerfiles/Dockerfile.builder.onbuild b/dockerfiles/Dockerfile.builder.onbuild index f768892b..30934883 100644 --- a/dockerfiles/Dockerfile.builder.onbuild +++ b/dockerfiles/Dockerfile.builder.onbuild @@ -26,6 +26,9 @@ ONBUILD RUN rm -rf /source/tmp # Do some HTML post-processing on the archive ONBUILD RUN /scripts/normalize-links.sh /site ${VER} +# Compress images +ONBUILD RUN /scripts/compress_images.sh /site ${VER} + # Make an index.html and 404.html which will redirect / to /${VER}/ ONBUILD RUN echo "<html><head><title>Redirect for ${VER}</title><meta http-equiv=\"refresh\" content=\"0;url='/${VER}/'\" /></head><body><p>If you are not redirected automatically, click <a href=\"/${VER}/\">here</a>.</p></body></html>" > /site/index.html ONBUILD RUN echo "<html><head><title>Redirect for ${VER}</title><meta http-equiv=\"refresh\" content=\"0;url='/${VER}/'\" /></head><body><p>If you are not redirected automatically, click <a href=\"/${VER}/\">here</a>.</p></body></html>" > /site/404.html diff --git a/scripts/compress_images.sh b/scripts/compress_images.sh new file mode 100755 index 00000000..87993268 --- /dev/null +++ b/scripts/compress_images.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +TARGET="$1" +VER="$2" +PNGQUANT=$(which pngquant) +PNG="$PNGQUANT -f --skip-if-larger --ext .png --speed 1" + +if [ -z "$TARGET" ]; then + echo "Usage: $0 <target> <version>" + echo "No target provided. Exiting." + exit 1 +fi + +if [ -z "$VER" ]; then + echo "Usage: $0 <target> <version>" + echo "No version provided. Exiting." + exit 1 +fi + +if ! [ -d "$TARGET/$VER" ]; then + echo "Target directory $TARGET/$VER does not exist. Exiting." + exit 1 +fi + +# Compress images +for image in $(find ${TARGET}/${VER}/ -name "*.png") + do $PNG $image + echo "Compressing $image" +done |