We'll see how to use the GitLab Docker Container Registry on GitLab.com

Remark: there are several ways to authenticating to the GitLab Container Registry. In this tutorial, we'll use 2 special variables:
CI_REGISTRY_USER and
CI_REGISTRY_PASSWORD
. This allows to automate building and deploying the Docker images and has read/write access to the Registry.

I will use Kaniko to build my images.

You need:

Use case

I write a lot of markdown documents. I store these documents on Gitlab.com and I would like to use GitLab CI to check if my document are well formed. So, Il will create a Docker image with tools to help me. For this tutorial I will use only one tool today and only one image. But in "the real life", I'm using this method with various tools I need for my day to day job, like: kubectl, helm, other linters, hey (an HTTP load generator), ...

So I will use this pproject: markdownlint. It's simple to use: mdl README.md

Initialize the project

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y \
    ruby
RUN gem install mdl
stages:
  - 🚧build-img

🐳build-img:
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  stage: 🚧build-img
  script: |
    echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG

Since you commit your files, GitLab CI will build the container image

I did the job directly on GitLab.com with the Web IDE. If you create the files locally, don't forget to push you changes 😉

Some minutes after, your image is built,

alt step1

Then this is your image, you can click to get the link of the image (eg: registry.gitlab.com/tanuki-core-tutorials/markdown.linter:latest)

alt step2

To use your new tool, use a project with markdown files, create a stage checking (or use the name you want) and add this job to your .gitlab-ci.yml file:

check-my-md-files:
  stage: checking
  image: registry.gitlab.com/tanuki-core-tutorials/markdown.linter:latest
  only:
    - merge_requests
  script: |
    mdl ./

Commit and create a Merge Request, let's run the CI, ... and you'll get the markdown style errors:

alt step3

🎉 That's all for today