From e11f42dfaaa836f4337103c85aea3ae77c3591ed Mon Sep 17 00:00:00 2001 From: Evan Read Date: Thu, 26 May 2022 10:01:31 +1000 Subject: Test linting Docker image and add some refinements --- .gitlab-ci.yml | 59 +++++++++++++++++++++--- dockerfiles/gitlab-docs-lint-html.Dockerfile | 41 ++++++++-------- dockerfiles/gitlab-docs-lint-markdown.Dockerfile | 44 +++++++++--------- 3 files changed, 92 insertions(+), 52 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5a9bd8a0..7ef79bb8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -578,7 +578,7 @@ pages: DOCKER_TLS_CERTDIR: "/certs" # -# GitLab docs lint image containing all test tools +# Build and deploy the GitLab Docs linting (Markdown) Docker image # image:docs-lint-markdown: extends: @@ -593,12 +593,35 @@ image:docs-lint-markdown: --build-arg ALPINE_VERSION=${ALPINE_VERSION} --build-arg VALE_VERSION=${VALE_VERSION} --build-arg MARKDOWNLINT_VERSION=${MARKDOWNLINT_VERSION} - --build-arg CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} -t $IMAGE_NAME -f $DOCKERFILE . - docker push $IMAGE_NAME environment: name: registry/docs-lint-markdown +# +# Test the GitLab Docs linting (Markdown) Docker image if changes are made to its Dockerfile +# +test:image:docs-lint-markdown: + extends: + - .docker_prepare + stage: test + needs: [] + variables: + DOCKERFILE: dockerfiles/gitlab-docs-lint-markdown.Dockerfile + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + - $DOCKERFILE + script: + - docker build + --build-arg ALPINE_VERSION=${ALPINE_VERSION} + --build-arg VALE_VERSION=${VALE_VERSION} + --build-arg MARKDOWNLINT_VERSION=${MARKDOWNLINT_VERSION} + --file $DOCKERFILE . + +# +# Build and deploy the GitLab Docs linting (HTML) Docker image +# image:docs-lint-html: extends: - .rules_scheduled_manual @@ -611,14 +634,33 @@ image:docs-lint-html: - docker build --build-arg RUBY_VERSION=${RUBY_VERSION} --build-arg ALPINE_VERSION=${ALPINE_VERSION} - --build-arg CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME} -t $IMAGE_NAME -f $DOCKERFILE . - docker push $IMAGE_NAME environment: name: registry/docs-lint-html # -# Build and deploy the GitLab docs base Docker image +# Test the GitLab Docs linting (HTML) Docker image if changes are made to its Dockerfile +# +test:image:docs-lint-html: + extends: + - .docker_prepare + stage: test + needs: [] + variables: + DOCKERFILE: dockerfiles/gitlab-docs-lint-html.Dockerfile + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + - $DOCKERFILE + script: + - docker build + --build-arg RUBY_VERSION=${RUBY_VERSION} + --build-arg ALPINE_VERSION=${ALPINE_VERSION} + --file $DOCKERFILE . + +# +# Build and deploy the GitLab Docs base Docker image # image:gitlab-docs-base: extends: @@ -635,18 +677,21 @@ image:gitlab-docs-base: name: registry/docs-base # -# Test the GitLab docs base Docker image if changes made to its Dockerfile +# Test the GitLab docs base Docker image if changes are made to its Dockerfile # test:image:gitlab-docs-base: extends: - .docker_prepare stage: test needs: [] + variables: + DOCKERFILE: dockerfiles/gitlab-docs-base.Dockerfile rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" changes: - - dockerfiles/gitlab-docs-base.Dockerfile - script: docker build -f dockerfiles/gitlab-docs-base.Dockerfile . + - $DOCKERFILE + script: + - docker build --file $DOCKERFILE . # # Helper Docker image containing all build dependencies. diff --git a/dockerfiles/gitlab-docs-lint-html.Dockerfile b/dockerfiles/gitlab-docs-lint-html.Dockerfile index fdb0d2fe..730baa97 100644 --- a/dockerfiles/gitlab-docs-lint-html.Dockerfile +++ b/dockerfiles/gitlab-docs-lint-html.Dockerfile @@ -1,20 +1,13 @@ -############################ +# GitLab Docs linting (HTML) Docker image # -# Image that contains the dependencies to run the lints. -# It downloads the gitlab-docs repository based on the -# branch the Docker image is invoked from. -# Based on Alpine. -# -############################ - -# RUBY_VERSION and ALPINE_VERSION are defined in .gitlab-ci.yml +# RUBY_VERSION and ALPINE_VERSION are defined in ../.gitlab-ci.yml ARG RUBY_VERSION ARG ALPINE_VERSION FROM ruby:${RUBY_VERSION}-alpine${ALPINE_VERSION} # Install dependencies -RUN apk add --no-cache -U \ +RUN printf "\n\e[32mINFO: Installing dependencies..\e[39m\n" && apk add --no-cache -U \ bash \ build-base \ curl \ @@ -34,24 +27,28 @@ RUN apk add --no-cache -U \ xz-dev \ yarn \ && echo 'gem: --no-document' >> /etc/gemrc \ - && gem update --system 3.3.13 - -# Set up needed environment variables that are called with --build-arg when -# the Docker image is built (see .gitlab-ci.yml). -ARG CI_COMMIT_REF_NAME -# If CI_COMMIT_REF_NAME is not set (local development), set it to main -ENV CI_COMMIT_REF_NAME ${CI_COMMIT_REF_NAME:-main} + && gem update --system 3.3.13 \ + && printf "\n\e[32mINFO: Dependency versions:\e[39m\n" \ + && echo "Ruby: $(ruby --version)" \ + && echo "RubyGems: $(gem --version)" \ + && echo "Node.js: $(node --version)" \ + && echo "Yarn: $(yarn --version)" \ + && printf "\n" WORKDIR /tmp -RUN wget --quiet https://gitlab.com/gitlab-org/gitlab-docs/-/archive/$CI_COMMIT_REF_NAME/gitlab-docs-$CI_COMMIT_REF_NAME.tar.bz2 \ - && tar xvjf gitlab-docs-$CI_COMMIT_REF_NAME.tar.bz2 \ - && mv gitlab-docs-$CI_COMMIT_REF_NAME gitlab-docs \ - && rm gitlab-docs-$CI_COMMIT_REF_NAME.tar.bz2 +# Fetch gitlab-docs +RUN printf "\n\e[32mINFO: Fetching gitlab-docs from main branch..\e[39m\n" \ + && wget --quiet https://gitlab.com/gitlab-org/gitlab-docs/-/archive/main/gitlab-docs-main.tar.bz2 \ + && tar xvjf gitlab-docs-main.tar.bz2 \ + && mv gitlab-docs-main gitlab-docs \ + && rm gitlab-docs-main.tar.bz2 WORKDIR /tmp/gitlab-docs/ -RUN yarn install --frozen-lockfile \ +# Install gitlab-docs dependencies +RUN printf "\n\e[32mINFO: Installing Node.js and Ruby dependencies..\e[39m\n" \ + && yarn install --frozen-lockfile \ && yarn cache clean --all \ && bundle update --bundler \ && bundle install --jobs 4 diff --git a/dockerfiles/gitlab-docs-lint-markdown.Dockerfile b/dockerfiles/gitlab-docs-lint-markdown.Dockerfile index 6d4caa2e..226e023f 100644 --- a/dockerfiles/gitlab-docs-lint-markdown.Dockerfile +++ b/dockerfiles/gitlab-docs-lint-markdown.Dockerfile @@ -1,10 +1,6 @@ -############################ +# GitLab Docs linting (Markdown) Docker image # -# Image that contains the doc lint tools. -# -############################ - -# ALPINE_VERSION is defined in .gitlab-ci.yml +# ALPINE_VERSION is defined in ../.gitlab-ci.yml ARG ALPINE_VERSION FROM alpine:${ALPINE_VERSION} @@ -14,7 +10,7 @@ ARG VALE_VERSION ARG MARKDOWNLINT_VERSION # Install dependencies -RUN apk add --no-cache -U \ +RUN printf "\n\e[32mINFO: Installing dependencies..\e[39m\n" && apk add --no-cache -U \ bash \ build-base \ curl \ @@ -29,19 +25,21 @@ RUN apk add --no-cache -U \ openssl \ pngquant \ tar \ - yarn - -# Install vale -SHELL ["/bin/ash", "-eo", "pipefail", "-c"] -RUN curl -sfL https://install.goreleaser.com/github.com/ValeLint/vale.sh | sh -s v${VALE_VERSION} - -# Set up needed environment variables that are called with --build-arg when -# the Docker image is built (see .gitlab-ci.yml). -ARG CI_COMMIT_REF_NAME -# If CI_COMMIT_REF_NAME is not set (local development), set it to master -ENV CI_COMMIT_REF_NAME ${CI_COMMIT_REF_NAME:-master} - -WORKDIR /tmp - -# markdownlint-cli pinned to control when new versions are put in place. -RUN yarn global add markdownlint-cli@${MARKDOWNLINT_VERSION} && yarn cache clean + yarn \ + && printf "\n\e[32mINFO: Dependency versions:\e[39m\n" \ + && echo "Node.js: $(node --version)" \ + && echo "Yarn: $(yarn --version)" \ + && printf "\n" + +# Install Vale +RUN printf "\n\e[32mINFO: Installing Vale %s..\e[39m\n" "${VALE_VERSION}" \ + && wget --quiet https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz \ + && tar -xvzf vale_${VALE_VERSION}_Linux_64-bit.tar.gz -C bin \ + && echo "Vale: $(vale --version)" \ + && printf "\n" + +# Install markdownlint-cli +RUN printf "\n\e[32mINFO: Installing markdownlint-cli %s..\e[39m\n" "${MARKDOWNLINT_VERSION}" \ + && yarn global add markdownlint-cli@${MARKDOWNLINT_VERSION} && yarn cache clean \ + && echo "markdownlint-cli: $(markdownlint --version)" \ + && printf "\n" -- cgit v1.2.3