diff options
-rw-r--r-- | .gitlab/ci/docker-images.gitlab-ci.yml | 67 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | dockerfiles/single.Dockerfile | 9 | ||||
-rwxr-xr-x | scripts/check-lunr-index.sh | 46 |
4 files changed, 122 insertions, 6 deletions
diff --git a/.gitlab/ci/docker-images.gitlab-ci.yml b/.gitlab/ci/docker-images.gitlab-ci.yml index 7669479b..c163b78c 100644 --- a/.gitlab/ci/docker-images.gitlab-ci.yml +++ b/.gitlab/ci/docker-images.gitlab-ci.yml @@ -230,9 +230,9 @@ image:docs-single: cache: {} dependencies: [] variables: - NANOC_ENV: 'production' IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME DOCKERFILE: $CI_COMMIT_REF_NAME.Dockerfile + NANOC_ENV: production environment: name: registry/$CI_COMMIT_REF_SLUG script: @@ -250,15 +250,78 @@ test:image:docs-single: - .docker_prepare stage: test variables: + GITLAB_VERSION: '15.5' DOCKERFILE: dockerfiles/single.Dockerfile + IMAGE_NAME: $CI_REGISTRY_IMAGE:$GITLAB_VERSION + NANOC_ENV: test + needs: [] + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + - $DOCKERFILE + script: + - docker build + --build-arg NANOC_ENV=${NANOC_ENV} + --build-arg VER=${GITLAB_VERSION} + --build-arg ALGOLIA_SEARCH="true" + --tag $IMAGE_NAME + --file $DOCKERFILE . +# +# Final Docker image containing a single version with lunr.js enabled +# It is based on single.Dockerfile for each branch +# +image:docs-single-lunrjs: + extends: + - .docker_prepare + stage: pre-deploy + artifacts: {} + cache: {} + dependencies: [] + variables: + IMAGE_NAME: $CI_REGISTRY_IMAGE/archives:$CI_COMMIT_REF_NAME + DOCKERFILE: $CI_COMMIT_REF_NAME.Dockerfile + NANOC_ENV: production + environment: + name: registry-archives/$CI_COMMIT_REF_SLUG + script: + - docker build + --build-arg NANOC_ENV=${NANOC_ENV} + --build-arg VER=${CI_COMMIT_REF_NAME} + --build-arg ALGOLIA_SEARCH="false" + --tag $IMAGE_NAME + --file $DOCKERFILE . + - docker push $IMAGE_NAME + # Only branches with versions like 10.4 + rules: + - if: '$CI_COMMIT_BRANCH =~ /^\d{1,2}\.\d{1,2}$/' + +# +# Test the GitLab docs single version Docker image with lunr.js enabled +# if changes made to its Dockerfile +# +test:image:docs-single-lunrjs: + extends: + - .docker_prepare + stage: test + variables: GITLAB_VERSION: '15.5' + IMAGE_NAME: $CI_REGISTRY_IMAGE/archives:$GITLAB_VERSION + DOCKERFILE: dockerfiles/single.Dockerfile + NANOC_ENV: test needs: [] rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" changes: - $DOCKERFILE script: - - docker build --file $DOCKERFILE --build-arg VER=${GITLAB_VERSION} . + - apk add --no-cache -U make bash + - docker build + --build-arg NANOC_ENV=${NANOC_ENV} + --build-arg VER=${GITLAB_VERSION} + --build-arg ALGOLIA_SEARCH="false" + --tag $IMAGE_NAME + --file $DOCKERFILE . + - make check-lunr-index # # Build master containing the online archives and latest docs (on schedules) @@ -105,9 +105,13 @@ clean: @rm -rf tmp public build-lunr-index: - @printf "\n$(INFO)INFO: Building offline search index..$(INFO_END)\n" + @printf "\n$(INFO)INFO: Building offline search index..$(END)\n" node scripts/lunr/preindex.js +check-lunr-index: + @printf "\n$(INFO)INFO: Checking if lunr.js is enabled...$(END)\n" + @scripts/check-lunr-index.sh + internal-links-check: clone-all-docs-projects compile @printf "\n$(INFO)INFO: Checking all internal links...$(END)\n" @bundle exec nanoc check internal_links diff --git a/dockerfiles/single.Dockerfile b/dockerfiles/single.Dockerfile index 49c58393..1bebdbf8 100644 --- a/dockerfiles/single.Dockerfile +++ b/dockerfiles/single.Dockerfile @@ -26,11 +26,12 @@ COPY --from=minifier /minify /usr/local/bin/minify # Set versions as build args to fetch corresponding branches ARG VER +ARG ALGOLIA_SEARCH +ARG NANOC_ENV ENV CI_COMMIT_REF_NAME=$VER - -# Set NANOC_ENV to production -ENV NANOC_ENV=production +ENV ALGOLIA_SEARCH=$ALGOLIA_SEARCH +ENV NANOC_ENV=$NANOC_ENV # # Install Nanoc dependencies and tools that @@ -78,6 +79,8 @@ RUN yarn install --frozen-lockfile \ && bundle exec rake default \ && bundle exec nanoc compile -VV +RUN if [ "$ALGOLIA_SEARCH" = "false" ]; then make build-lunr-index; fi + # Move generated HTML to /site RUN mkdir /site \ && mv public "/site/${VER}" diff --git a/scripts/check-lunr-index.sh b/scripts/check-lunr-index.sh new file mode 100755 index 00000000..b3019e2d --- /dev/null +++ b/scripts/check-lunr-index.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +COLOR_RED="\e[31m" +COLOR_GREEN="\e[32m" +COLOR_RESET="\e[39m" + +# +# The following checks are performed: +# +# - index_check: checks if the lunr.js index is built. There's two files when the +# index is built: 'lunr-index.json' and 'lunr-map.json'. +# - dev_check: when ALGOLIA_SEARCH is set to 'false' the div we're looking for +# is set to 'js-lunr-form'. Otherwise, it's set to 'docsearch' by default. +# This is defined in +# https://gitlab.com/gitlab-org/gitlab-docs/-/blob/83ebc0de813c6e916b522a9203a6182d7425dd20/content/index.erb#L20-24. +# + +if [ "$CI" = "true" ]; +then + div_check=$(docker run --rm "$IMAGE_NAME" grep -o js-lunr-form "/usr/share/nginx/html/$GITLAB_VERSION/index.html") + index_check=$(docker run --rm "$IMAGE_NAME" ls "/usr/share/nginx/html/$GITLAB_VERSION/assets/javascripts/lunr-index.json" | wc -l) +else + div_check=$(grep -o js-lunr-form public/index.html) + index_check=$(ls public/assets/javascripts/lunr-index.json | wc -l) +fi + +if [ $index_check != 1 ]; +then + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: lunr.js index is not built!\n" + printf " Did you forget to run 'make build-lunr-index'?\n" + printf " For more information, see https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/docsearch.md#lunrjs-search${COLOR_RESET}\n" + exit 1; +else + if [ "$div_check" != "js-lunr-form" ]; + then + # shellcheck disable=2059 + printf "${COLOR_RED}ERROR: lunr.js index is found, but not enabled!\n" + printf " Did you forget to build the site with ALGOLIA_SEARCH='false'?\n" + printf " For more information, see https://gitlab.com/gitlab-org/gitlab-docs/-/blob/main/doc/docsearch.md#lunrjs-search${COLOR_RESET}\n" + exit 1; + else + # shellcheck disable=2059 + printf "${COLOR_GREEN}INFO: lunr.js is found and enabled!${COLOR_RESET}\n" + fi +fi |