Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml2
-rw-r--r--Dockerfile.master4
-rw-r--r--dockerfiles/Dockerfile.bootstrap17
-rw-r--r--dockerfiles/Dockerfile.builder.onbuild3
-rwxr-xr-xscripts/minify-assets.sh26
5 files changed, 48 insertions, 4 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 15724744..c6fbe7db 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -272,6 +272,8 @@ pages:
- mv /usr/share/nginx/html/1* public/
# Check the size
- du -sh public/
+ - /scripts/minify-assets.sh public/ public/
+ - du -sh public/
artifacts:
paths:
- public
diff --git a/Dockerfile.master b/Dockerfile.master
index 5d67eae3..0e61f327 100644
--- a/Dockerfile.master
+++ b/Dockerfile.master
@@ -57,5 +57,9 @@ COPY --from=registry.gitlab.com/gitlab-org/gitlab-docs:12.4 ${TARGET} ${TARGET}
# changes
COPY --from=builder /source/public ${TARGET}
+# Minify assets
+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.bootstrap b/dockerfiles/Dockerfile.bootstrap
index 2de4905e..4d9b2d8e 100644
--- a/dockerfiles/Dockerfile.bootstrap
+++ b/dockerfiles/Dockerfile.bootstrap
@@ -1,8 +1,16 @@
#
+# Build minifier utility
+# Adapted from https://github.com/docker/docker.github.io/blob/publish-tools/Dockerfile.builder
+#
+FROM golang:1.13-alpine AS minifier
+RUN apk add --no-cache git
+RUN go get -d github.com/tdewolff/minify/cmd/minify \
+ && go build -v -o /minify github.com/tdewolff/minify/cmd/minify
+
+#
# This is the Nanoc boostrap Dockerfile which builds an image that contains
# all Nanoc's runtime dependencies and gems.
#
-
FROM registry.gitlab.com/gitlab-org/gitlab-build-images:gitlab-docs
# Install packages needed at build and run time
@@ -17,9 +25,6 @@ RUN apk add --no-cache libxslt libcurl openssl git grep bash pngquant nodejs
# Do not install rdoc to save some space
RUN echo 'gem: --no-document' >> /etc/gemrc
-# Copy scripts used for static HTML post-processing
-COPY scripts /scripts/
-
# Copy only Gemfile and Gemfile.lock
COPY /Gemfile* /source/
WORKDIR /source
@@ -27,4 +32,8 @@ WORKDIR /source
# Install gems
RUN NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --jobs 4
+# Copy scripts used for static HTML post-processing
+COPY scripts /scripts/
+COPY --from=minifier /minify /scripts/minify
+
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 2c5c4fd1..6f72cc53 100644
--- a/dockerfiles/Dockerfile.builder.onbuild
+++ b/dockerfiles/Dockerfile.builder.onbuild
@@ -28,6 +28,9 @@ ONBUILD RUN /scripts/normalize-links.sh /site ${VER}
# Compress images
ONBUILD RUN /scripts/compress_images.sh /site ${VER}
+# Minify assets
+ONBUILD RUN /scripts/minify ${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/minify-assets.sh b/scripts/minify-assets.sh
new file mode 100755
index 00000000..982aa650
--- /dev/null
+++ b/scripts/minify-assets.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+TARGET="$1"
+VER="$2"
+
+if [ -z "$TARGET" -o -z "$VER" ]; then
+ echo "Usage: $0 <target> <ver>"
+ echo "Either <target> or <ver> is missing. Exiting."
+ exit 1
+fi
+
+if ! [ -d "$TARGET" ]; then
+ echo "Target directory $TARGET does not exist. Exiting."
+ exit 1
+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
+
+echo "Done"