diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2021-04-26 14:48:15 +0300 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2022-05-30 02:33:01 +0300 |
commit | 9e0e3fea3f316f9cf2e9efc952ea0e5f73be3df4 (patch) | |
tree | ea4e34cb40f731cf895b4d1d1481e69de2463ba7 | |
parent | 60aefa74ca12a5aa690cb64196013836bd4f960a (diff) |
Make single.Dockerfile a standalone Dockerfile
-rw-r--r-- | dockerfiles/single.Dockerfile | 125 |
1 files changed, 108 insertions, 17 deletions
diff --git a/dockerfiles/single.Dockerfile b/dockerfiles/single.Dockerfile index 020303ae..ad1614f5 100644 --- a/dockerfiles/single.Dockerfile +++ b/dockerfiles/single.Dockerfile @@ -1,22 +1,113 @@ # # Copy this Dockerfile to the root of each branch you want to create an archive +# and rename it to X.Y.Dockerfile, where X.Y the major.minor GitLab version. # +#- Start of minifier stage -# + +# +# 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 \ + && export GO111MODULE=on \ + && go get -d github.com/tdewolff/minify/v2@latest \ + && go build -v -o /minify github.com/tdewolff/minify/cmd/minify + +#- End of minifier stage -# + +#- Start of builder stage -# + +FROM ruby:2.7.5-alpine3.15 AS builder + +# Copy minifier binary from the minifier stage +COPY --from=minifier /minify /usr/local/bin/minify + # Set to the version for this archive (must match the branch name) -ARG VER=X.Y - -# Replace the versions to march the stable branches of the upstream projects -ARG BRANCH_EE=X-Y-stable-ee -ARG BRANCH_OMNIBUS=X-Y-stable -ARG BRANCH_RUNNER=X-Y-stable -ARG BRANCH_CHARTS=W-Z-stable - -# This image comes from the builder.onbuild.Dockerfile file -# https://gitlab.com/gitlab-org/gitlab-docs/blob/main/dockerfiles/Dockerfile.builder.onbuild -# Build the website -FROM registry.gitlab.com/gitlab-org/gitlab-docs:builder-onbuild AS builder - -# This image comes from the nginx.onbuild.Dockerfile file -# https://gitlab.com/gitlab-org/gitlab-docs/blob/main/dockerfiles/Dockerfile.nginx.onbuild -# Copy the generated HTML files to a smaller image -FROM registry.gitlab.com/gitlab-org/gitlab-docs:nginx-onbuild +ENV VER=X.Y +ENV CI_COMMIT_REF_NAME=X.Y + +# Replace the versions to match the stable branches of the upstream projects +ENV BRANCH_EE=X-Y-stable-ee +ENV BRANCH_OMNIBUS=X-Y-stable +ENV BRANCH_RUNNER=X-Y-stable +ENV BRANCH_CHARTS=W-Z-stable + +# Set NANOC_ENV to production +ENV NANOC_ENV=production + +# +# Install Nanoc dependencies and tools that +# are needed to build the docs site and run the tests. +# +RUN apk add --no-cache -U \ + bash \ + build-base \ + curl \ + git \ + gnupg \ + go \ + grep \ + gzip \ + jq \ + libcurl \ + libxslt \ + libxslt-dev \ + nodejs \ + openssl \ + pngquant \ + ruby-dev \ + tar \ + xz \ + xz-dev \ + yarn \ + && echo 'gem: --no-document' >> /etc/gemrc \ + && gem update --system 3.3.13 + +# Build the docs from this branch +COPY . /source/ +WORKDIR /source + +RUN yarn install --frozen-lockfile \ + && yarn cache clean \ + && bundle config set --local deployment true \ + && gem install bundler --version $(tail -n 1 Gemfile.lock) \ + && bundle install --jobs 4 \ + && bundle exec rake setup_git default \ + && bundle exec nanoc compile -VV + +# Move generated HTML to /site +RUN mkdir /site \ + && mv public /site/${VER} + +# Do some HTML post-processing on the archive, compress images, and minify assets +RUN /source/scripts/normalize-links.sh /site ${VER} \ + && /source/scripts/compress_images.sh /site ${VER} \ + && /source/scripts/minify-assets.sh /site ${VER} # ATTENTION: This should be the last script to run + +# 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>" > /site/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>" > /site/404.html + +#- End of builder build stage -# + +#- Start of NGINX stage -# +# +# Copy the ending HTML files from the previous 'builder' stage and copy them +# to an NGINX Docker image. +# +FROM nginx: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 /site /usr/share/nginx/html + +# Copy the Nginx config +COPY dockerfiles/nginx-overrides.conf /etc/nginx/conf.d/default.conf + +# Start Nginx to serve the archive at / (which will redirect to the version-specific dir) +CMD ["sh", "-c", "echo 'GitLab docs are viewable at: http://0.0.0.0:4000'; exec nginx -g 'daemon off;'"] + +#- End of NGINX stage -# |