diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2019-12-09 14:05:03 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2019-12-09 14:05:03 +0300 |
commit | 1493636874d778512849b8d561f7d238345945db (patch) | |
tree | bf3323be037c05ffdb5f489d10f30709681e9489 | |
parent | 341b92f23b2a9ef6d1f87846be5ff6bfead2513f (diff) | |
parent | 2bfda3d4bcf417ead3adf124d0c2042399df296d (diff) |
Merge branch 'scripts-check-existence' into 'master'
Refactor how minify script works
See merge request gitlab-org/gitlab-docs!643
-rw-r--r-- | .gitlab-ci.yml | 26 | ||||
-rw-r--r-- | Dockerfile.master | 5 | ||||
-rw-r--r-- | dockerfiles/Dockerfile.builder.onbuild | 6 | ||||
-rwxr-xr-x | scripts/minify-assets.sh | 9 |
4 files changed, 34 insertions, 12 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee05b131..23b10065 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -280,14 +280,36 @@ pages: dependencies: - compile_prod # Contains the public directory script: + # # We want to use the artifacts of the compile_prod job as # the latest docs deployment, and the other versions are # taken from /usr/share/nginx/html which are included in # the image we pull from. + # - mv /usr/share/nginx/html/1* public/ - # Check the size + + # + # Check the size before minifying + # - du -sh public/ - - /scripts/minify-assets.sh public/ public/ + + # + # Minify the assets of the resulting site. The single versions + # will be minified eventually when the minification propagates + # to all versions that are included in gitlab-docs:latest + # (around 12.7), but we also need to minify the content we + # pull from master. Currently, there's no way to exclude + # files or directories when minifying, so we minify the whole + # site (even the versions that are already minified). + # TODO: Move to top. + # When all versions are minified, we can move this script + # to run first and avoid minifying the already minified versions. + # + - /scripts/minify-assets.sh ./ public/ + + # + # Check the size after minifying + # - du -sh public/ artifacts: paths: diff --git a/Dockerfile.master b/Dockerfile.master index dddd6f2b..eeb6c342 100644 --- a/Dockerfile.master +++ b/Dockerfile.master @@ -56,9 +56,10 @@ COPY --from=registry.gitlab.com/gitlab-org/gitlab-docs:12.3 ${TARGET} ${TARGET} # changes COPY --from=builder /source/public ${TARGET} -# Minify assets +# Since we changed images when we invoked 'FROM nginx:1.12-alpine' above, +# the minify script is not included. Thus, we copy it from the previous image +# (aliased as builder). COPY --from=builder /scripts/minify* /scripts/ -RUN /scripts/minify-assets.sh ${TARGET}/ ${TARGET} # Serve the site (target), which is now all static HTML CMD echo -e "GitLab docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;' diff --git a/dockerfiles/Dockerfile.builder.onbuild b/dockerfiles/Dockerfile.builder.onbuild index 6f72cc53..fd1877c0 100644 --- a/dockerfiles/Dockerfile.builder.onbuild +++ b/dockerfiles/Dockerfile.builder.onbuild @@ -23,13 +23,13 @@ ONBUILD RUN mv /source/public /site/${VER} ONBUILD RUN rm -rf /source/tmp # Do some HTML post-processing on the archive -ONBUILD RUN /scripts/normalize-links.sh /site ${VER} +ONBUILD RUN [ -f /scripts/normalize-links.sh ] && /scripts/normalize-links.sh /site ${VER} || "/scripts/normalize-links.sh not found" # Compress images -ONBUILD RUN /scripts/compress_images.sh /site ${VER} +ONBUILD RUN [ -f /scripts/compress_images.sh ] && /scripts/compress_images.sh /site ${VER} || "/scripts/compress_images.sh not found" # Minify assets -ONBUILD RUN /scripts/minify ${VER} +ONBUILD RUN [ -f /scripts/minify ] && /scripts/minify /site ${VER} || "/scripts/minify not found" # 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 diff --git a/scripts/minify-assets.sh b/scripts/minify-assets.sh index 982aa650..02562039 100755 --- a/scripts/minify-assets.sh +++ b/scripts/minify-assets.sh @@ -17,10 +17,9 @@ fi # Minify assets printf "Optimizing assets..." -printf "HTML..."; /scripts/minify -r --type=html --match=\.html -o ${TARGET}/ ${TARGET} || true -printf "CSS..." ; /scripts/minify -r --type=css --match=\.css -o ${TARGET}/ ${TARGET} || true -printf "JSON..."; /scripts/minify -r --type=json --match=\.json -o ${TARGET}/ ${TARGET} || true -printf "SVG..." ; /scripts/minify -r --type=svg --match=\.svg -o ${TARGET}/ ${TARGET} || true -printf "XML..." ; /scripts/minify -r --type=xml --match=\.xml -o ${TARGET}/ ${TARGET} || true +printf "HTML..."; /scripts/minify -r --type=html --match=\.html -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true +printf "CSS..." ; /scripts/minify -r --type=css --match=\.css -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true +printf "JSON..."; /scripts/minify -r --type=json --match=\.json -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true +printf "SVG..." ; /scripts/minify -r --type=svg --match=\.svg -o ${TARGET}/${VER}/ ${TARGET}/${VER} || true echo "Done" |