diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2023-11-08 05:44:58 +0300 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2023-11-08 05:44:58 +0300 |
commit | ba9685522a6a0575b676a85c7655315a1bd352e4 (patch) | |
tree | 3569e853761b324762f4b3f447ead8d84d7bcad7 | |
parent | 53aeef3a6feb3ba0f4f6104ad74b6692714fb058 (diff) |
Use Alpine 3.18 for the single Docker image
-rw-r--r-- | .gitlab/ci/build-and-deploy.gitlab-ci.yml | 4 | ||||
-rw-r--r-- | .gitlab/ci/rules.gitlab-ci.yml | 2 | ||||
-rw-r--r-- | dockerfiles/single.Dockerfile | 25 | ||||
-rwxr-xr-x | scripts/minify-assets.sh | 6 |
4 files changed, 22 insertions, 15 deletions
diff --git a/.gitlab/ci/build-and-deploy.gitlab-ci.yml b/.gitlab/ci/build-and-deploy.gitlab-ci.yml index 87d144e6..ecd94707 100644 --- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml +++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml @@ -44,10 +44,12 @@ # Build the Lunr.js search index if needed - if [[ "$SEARCH_BACKEND" == "lunr" ]]; then make build-lunr-index; fi # Minify the assets of the resulting site + # The trailing slash of public/ is important + # https://github.com/tdewolff/minify/blob/master/cmd/minify/README.md#directories - mkdir dest/ - scripts/minify-assets.sh dest/ public/ - rm -rf public/ - - mv dest/public public/ + - mv dest/ public/ # # The script lines for gzipping the site (not used in upstream review apps, to speed up pipelines) diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index e8f4b9c8..66534292 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -3,7 +3,7 @@ ############################################### default: - image: registry.gitlab.com/gitlab-org/gitlab-docs/base:alpine-3.18-ruby-3.2.2-4207821e + image: registry.gitlab.com/gitlab-org/gitlab-docs/base:alpine-3.18-ruby-3.2.2-08fa6df8 tags: - gitlab-org diff --git a/dockerfiles/single.Dockerfile b/dockerfiles/single.Dockerfile index 9d2f9253..e171e601 100644 --- a/dockerfiles/single.Dockerfile +++ b/dockerfiles/single.Dockerfile @@ -2,7 +2,7 @@ # and rename it to X.Y.Dockerfile, where X.Y the major.minor GitLab version. # #- Start of builder build stage -# -FROM ruby:3.2.2-alpine3.17 as builder +FROM ruby:3.2.2-alpine3.18 as builder # Set versions as build args to fetch corresponding branches ARG VER @@ -67,15 +67,14 @@ RUN if [ "$SEARCH_BACKEND" = "lunr" ]; then make build-lunr-index; fi # # 1. Normalize the links in /source/public using version $VER. # 2. Minify the files in /source/public into /dest, creating /dest/public. Must run last. -# 3. Rename /dest/public to /dest/$VER -RUN /source/scripts/normalize-links.sh /source/public $VER \ - && mkdir /dest \ - && /source/scripts/minify-assets.sh /dest /source/public \ - && mv /dest/public "/dest/${VER}" - -# Make an index.html and 404.html which will redirect / to /${VER}/ -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>" > /dest/index.html \ - && 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>" > /dest/404.html +# A trailing slash in the source path will copy all files inside the target directory, +# while omitting the trainling slash will copy the directory as well. +# We want the trailing slash. More info: +# https://github.com/tdewolff/minify/blob/master/cmd/minify/README.md#directories +# +RUN scripts/normalize-links.sh public $VER \ + && mkdir dest/ \ + && scripts/minify-assets.sh dest/ public/ #- End of builder build stage -# @@ -88,7 +87,11 @@ FROM nginx:stable-alpine # Clean out any existing HTML files, and copy the HTML from the builder stage # to the default location for NGINX. RUN rm -rf /usr/share/nginx/html/* -COPY --from=builder /dest /usr/share/nginx/html +COPY --from=builder /source/dest /usr/share/nginx/html/${VER} + +# Make an index.html and 404.html which will redirect / to /${VER}/ +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>" > /usr/share/nginx/html/index.html \ + && 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>" > /usr/share/nginx/html/404.html # Copy the NGINX config COPY dockerfiles/nginx-overrides.conf /etc/nginx/conf.d/default.conf diff --git a/scripts/minify-assets.sh b/scripts/minify-assets.sh index edcb3288..4510b3e9 100755 --- a/scripts/minify-assets.sh +++ b/scripts/minify-assets.sh @@ -43,6 +43,9 @@ if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --match="\.html$|\.css$|\.json|\.svg$" -o "$ SIZE_BEFORE_MINIFY=$(du -sh "$SOURCE" | awk '{print $1}') SIZE_AFTER_MINIFY=$(du -sh "$DEST" | awk '{print $1}') # Print size results + printf "${COLOR_GREEN}INFO: Minified with " + $MINIFY_BIN --version + printf "${COLOR_RESET}" printf "${COLOR_GREEN}INFO: Size before minifying: $SIZE_BEFORE_MINIFY ${COLOR_RESET}\n" printf "${COLOR_GREEN}INFO: Size after minifying: $SIZE_AFTER_MINIFY ${COLOR_RESET}\n" @@ -53,8 +56,7 @@ if $MINIFY_BIN "${MINIFY_FLAGS[@]}" --match="\.html$|\.css$|\.json|\.svg$" -o "$ SOURCE_FILES_COUNT=$(find "$SOURCE" -type f | wc -l) DEST_FILES_COUNT=$(find "$DEST" -type f | wc -l) SOURCE_DIR_COUNT=$(find "$SOURCE" -type d | wc -l) - # Destination is always one directory deeper (more) than source, so we subtract one - DEST_DIR_COUNT=$(($(find "$DEST" -type d | wc -l) - 1)) + DEST_DIR_COUNT=$(find "$DEST" -type d | wc -l) printf "${COLOR_GREEN}INFO: Checking that the number of source and destination files is the same...${COLOR_RESET}\n" if [[ $SOURCE_FILES_COUNT -eq $DEST_FILES_COUNT ]]; then printf "${COLOR_GREEN}SUCCESS: File count in $SOURCE and $DEST: $SOURCE_FILES_COUNT/$DEST_FILES_COUNT ${COLOR_RESET}\n" |