diff options
-rw-r--r-- | .dockerignore | 27 | ||||
-rw-r--r-- | .gitlab-ci.yml | 80 | ||||
-rw-r--r-- | Dockerfile.archive | 20 | ||||
-rw-r--r-- | dockerfiles/Dockerfile.bootstrap | 35 | ||||
-rw-r--r-- | dockerfiles/Dockerfile.builder.onbuild | 28 | ||||
-rw-r--r-- | dockerfiles/Dockerfile.nginx.onbuild | 19 | ||||
-rw-r--r-- | dockerfiles/README.md | 30 | ||||
-rw-r--r-- | dockerfiles/nginx-overrides.conf | 9 | ||||
-rwxr-xr-x | scripts/normalize-links.sh | 32 |
9 files changed, 272 insertions, 8 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..e36c1791 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# For projects using nanoc (https://nanoc.ws/) + +# Default location for output is output/, but we use public/ +output/ +public/ + +# Make sure the content directories aren't added +content/ce +content/ee +content/omnibus +content/runner +content/doc +content/docs + +# Temporary file directory +tmp/ + +# Crash Log +crash.log + +# dot files +.sass-cache/ +.git/ +.bundle/ +.DS_Store +.dockerignore +.gitlab diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 864372b5..717b0c4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,11 @@ image: ruby:2.5 stages: + - images - build - test - deploy + - docker-stable before_script: - ruby -v @@ -25,7 +27,7 @@ variables: - public expire_in: 1w cache: - key: "$CI_BUILD_NAME-$CI_BUILD_REF_NAME" + key: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME" paths: - tmp/ - vendor/ruby @@ -55,7 +57,7 @@ internal_links: - nanoc check internal_links allow_failure: true cache: - key: "$CI_BUILD_NAME-$CI_BUILD_REF_NAME" + key: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME" paths: - vendor/ruby tags: @@ -73,7 +75,7 @@ scss_lint: script: - bundle exec scss-lint cache: - key: "$CI_BUILD_NAME-$CI_BUILD_REF_NAME" + key: "$CI_JOB_NAME-$CI_COMMIT_REF_NAME" paths: - vendor/ruby tags: @@ -95,10 +97,10 @@ review: before_script: [] cache: {} script: - - rsync -av --delete public /srv/nginx/pages/$CI_BUILD_REF_SLUG + - rsync -av --delete public /srv/nginx/pages/$CI_COMMIT_REF_SLUG environment: - name: review/$CI_BUILD_REF_SLUG - url: http://$CI_BUILD_REF_SLUG.$APPS_DOMAIN + name: review/$CI_COMMIT_REF_SLUG + url: http://$CI_COMMIT_REF_SLUG.$APPS_DOMAIN on_stop: review_stop only: - branches@gitlab-com/gitlab-docs @@ -118,10 +120,10 @@ review_stop: before_script: [] cache: {} script: - - rm -rf public /srv/nginx/pages/$CI_BUILD_REF_SLUG + - rm -rf public /srv/nginx/pages/$CI_COMMIT_REF_SLUG when: manual environment: - name: review/$CI_BUILD_REF_SLUG + name: review/$CI_COMMIT_REF_SLUG action: stop only: - branches@gitlab-com/gitlab-docs @@ -154,3 +156,65 @@ pages: - docker dependencies: - compile_master + +######################## +# Docker images builds # +######################## + +.docker_build: &docker_build + image: docker:latest + services: + - docker:dind + before_script: + - docker info + - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY + +image:bootstrap: + stage: images + <<: *docker_build + variables: + DOCKER_DRIVER: overlay2 + IMAGE_NAME: $CI_REGISTRY_IMAGE:bootstrap + script: + - docker build -t $IMAGE_NAME -f dockerfiles/Dockerfile.bootstrap . + - docker push $IMAGE_NAME + when: manual + +image:builder-onbuild: + stage: images + <<: *docker_build + variables: + DOCKER_DRIVER: overlay2 + IMAGE_NAME: $CI_REGISTRY_IMAGE:builder-onbuild + GIT_STRATEGY: none + script: + - docker build -t $IMAGE_NAME -f dockerfiles/Dockerfile.builder.onbuild . + - docker push $IMAGE_NAME + when: manual + +image:nginx-onbuild: + stage: images + <<: *docker_build + variables: + DOCKER_DRIVER: overlay2 + IMAGE_NAME: $CI_REGISTRY_IMAGE:nginx-onbuild + GIT_STRATEGY: none + script: + - docker build -t $IMAGE_NAME -f dockerfiles/Dockerfile.nginx.onbuild . + - docker push $IMAGE_NAME + when: manual + +# To be run only on stable branches. +image:docs-stable: + stage: docker-stable + <<: *docker_build + variables: + DOCKER_DRIVER: overlay2 + IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG + GIT_STRATEGY: none + script: + - docker build -t $IMAGE_NAME . + - docker push $IMAGE_NAME + # Only single or double digits separated with a dot. + only: + - /^\d{1,2}\.\d{1,2}$/ diff --git a/Dockerfile.archive b/Dockerfile.archive new file mode 100644 index 00000000..843ebd54 --- /dev/null +++ b/Dockerfile.archive @@ -0,0 +1,20 @@ +# +# Copy this Dockerfile to each branch you want to create an archive +# + +# Set to the version for this archive (must match the branch name) +ARG VER=10.4 + +# Replace the versions to march the stable branches of the upstream projects +ARG BRANCH_EE=10-4-stable-ee +ARG BRANCH_CE=10-4-stable +ARG BRANCH_OMNIBUS=10-4-stable +ARG BRANCH_RUNNER=10-4-stable + +# This image comes from the Dockerfile.builder.onbuild file +# https://gitlab.com/gitlab-com/gitlab-docs/blob/master/dockerfiles/Dockerfile.builder.onbuild +FROM registry.gitlab.com/gitlab-com/gitlab-docs:builder-onbuild AS builder + +# This image comes from the Dockerfile.nginx.onbuild file +# https://gitlab.com/gitlab-com/gitlab-docs/blob/master/dockerfiles/Dockerfile.nginx.onbuild +FROM registry.gitlab.com/gitlab-com/gitlab-docs:nginx-onbuild diff --git a/dockerfiles/Dockerfile.bootstrap b/dockerfiles/Dockerfile.bootstrap new file mode 100644 index 00000000..ae776e46 --- /dev/null +++ b/dockerfiles/Dockerfile.bootstrap @@ -0,0 +1,35 @@ +# +# This is the Nanoc boostrap Dockerfile which builds an image that contains +# all Nanoc's runtime dependencies and gems. +# + +FROM ruby:2.5-alpine + +# Install packages needed at build and run time +RUN apk add --no-cache --virtual build-deps \ + build-base \ + ruby-dev \ + libxslt-dev + +# 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 + +# Install gems +RUN NOKOGIRI_USE_SYSTEM_LIBRARIES=1 bundle install --jobs 4 + +# Cleanup +RUN apk del build-deps \ + && rm -rf /usr/lib/ruby/gems/*/cache/*.gem \ + && rm -rf /usr/src/Gemfile* + +# Install packages needed at build and run time +RUN apk add --no-cache libxslt libcurl openssl git grep bash + +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 new file mode 100644 index 00000000..02606155 --- /dev/null +++ b/dockerfiles/Dockerfile.builder.onbuild @@ -0,0 +1,28 @@ +# Get Nanoc bootstrap +FROM registry.gitlab.com/gitlab-com/gitlab-docs:bootstrap + +# Make the variables of the archive Dockerfiles accessible to this build-stage +ONBUILD ARG VER +ONBUILD ARG BRANCH_EE +ONBUILD ARG BRANCH_CE +ONBUILD ARG BRANCH_OMNIBUS +ONBUILD ARG BRANCH_RUNNER + +# Build the docs from this branch +ONBUILD COPY . /source/ +ONBUILD RUN bundle exec rake setup_git default +ONBUILD RUN bundle exec nanoc compile -VV + +# Move generated HTML to /site +ONBUILD RUN mkdir /site +ONBUILD RUN mv /source/public /site/${VER} + +# Remove tmp dir to save some space +ONBUILD RUN rm -rf /source/tmp + +# Do some HTML post-processing on the archive +ONBUILD RUN /scripts/normalize-links.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/dockerfiles/Dockerfile.nginx.onbuild b/dockerfiles/Dockerfile.nginx.onbuild new file mode 100644 index 00000000..34ebb7c8 --- /dev/null +++ b/dockerfiles/Dockerfile.nginx.onbuild @@ -0,0 +1,19 @@ +# Base image to use for building documentation archives +# this image uses "ONBUILD" to perform all required steps in the archives +# and relies upon its parent image having a layer called `builder`. + +FROM nginx:alpine + +# Make the version accessible to this build-stage, and copy it to an ENV so that it persists in the final image +ONBUILD ARG VER +ONBUILD ENV VER=$VER + +# Clean out any existing HTML files, and copy the HTML from the builder stage to the default location for Nginx +ONBUILD RUN rm -rf /usr/share/nginx/html/* +ONBUILD 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 echo -e "GitLab docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;' diff --git a/dockerfiles/README.md b/dockerfiles/README.md new file mode 100644 index 00000000..3e8b2b4e --- /dev/null +++ b/dockerfiles/README.md @@ -0,0 +1,30 @@ +# Dockerfiles used to build the docs site + +This directory contains all needed Dockerfiles to build and deploy the website. +It is heavily inspired by Docker's [publish tools](https://github.com/docker/docker.github.io/tree/publish-tools). + +## When to update the Dockerfiles + +| Dockerfile | Docker image | Description | +| ---------- | ------------ | ----------- | +| `Dockerfile.bootstrap` | `gitlab-docs:bootstrap` | This image contains all the dependencies that are needed to build the website. If the gems are updated and `Gemfile{,.lock}` changes, the image must be rebuilt. | + +## How to build the images + +For each image, there's a manual job under the `images` stage in +[`.gitlab-ci.yml`](../.gitlab-ci.yml). + +Build and tag all tooling images: + +```sh +docker build -t registry.gitlab.com/gitlab-com/gitlab-docs:bootstrap -f Dockerfile.bootstrap ../ +docker build -t registry.gitlab.com/gitlab-com/gitlab-docs:builder-onbuild -f Dockerfile.builder.onbuild ../ +docker build -t registry.gitlab.com/gitlab-com/gitlab-docs:nginx-onbuild -f Dockerfile.nginx.onbuild ../ +``` + +For each archive branch, build the archive's image: + +``` +git checkout 10-4-stable +docker build -t registry.gitlab.com/gitlab-com/gitlab-docs/docs:10.4 . +``` diff --git a/dockerfiles/nginx-overrides.conf b/dockerfiles/nginx-overrides.conf new file mode 100644 index 00000000..7564d0c9 --- /dev/null +++ b/dockerfiles/nginx-overrides.conf @@ -0,0 +1,9 @@ +server { + port_in_redirect off; + listen 4000; + error_page 403 404 /404.html; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } +}
\ No newline at end of file diff --git a/scripts/normalize-links.sh b/scripts/normalize-links.sh new file mode 100755 index 00000000..c31e37a1 --- /dev/null +++ b/scripts/normalize-links.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +TARGET="$1" +VER="$2" + +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 + +# Fix relative links for archive +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/ce/#/'"$VER"'/ce/#g' +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/ee/#/'"$VER"'/ee/#g' +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/runner/#/'"$VER"'/runner/#g' +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/omnibus/#/'"$VER"'/omnibus/#g' +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#="/assets/#/'"$VER"'/assets/#g' +find ${TARGET} -type f -name '*.html' -print0 | xargs -0 sed -i 's#<a href="/">#<a href="/'"$VER"'/">#g' + +# Symlink all README.html to index.html +for i in `find ${TARGET}/${VER} -name README.html`; do ln -sf README.html $(dirname $i)/index.html; done |