Intro

After setting up my CI/CD setup I quickly noticed some small issues I had with performance. The way I was using my pipelines was not really efficient. Every step inside the .gitlab-ci.yml file made the gitlab-runner pull a docker image from upstream… This could sometimes take a few minutes which is not ideal. There is also a limit on the amount of pulls you can do, so I needed a solution for this.

Setup

A great fix for this, is to pre-pull these images and make use of a local docker registry. That way my gitlab-runner can just make use of the pre-pulled images.

A quick docker-compose to setup the registry was quickly made:

---
version: "3"

services:
  registry:
    image: registry
    container_name: registry
    ports:
      - 5000:5000
    volumes:
      - ./registry_images:/var/lib/registry
    restart: unless-stopped

Now I just have to start the container and check if it’s running:

docker-compose up -d
docker ps

ss -tulp | grep 5000

Provide images to registry

After the setup I can just pull images and push them to my registry:

docker pull alpine
docker tag alpine $REGISTRY_IP:5000/alpine
docker push $REGISTRY_IP:5000/alpine

docker pull nginx
docker tag nginx $REGISTRY_IP:5000/nginx
docker push $REGISTRY_IP:5000/nginx

docker pull hugo
docker tag nginx $REGISTRY_IP:5000/hugo
docker push $REGISTRY_IP:5000/hugo

Use the registry

Ok now that the images are in my registry, I can make my gitlab-runner use them. This is done pretty easily inside the .gitlab-ci.yml file inside my repository by just changing the image location:

build:
  stage: Build
  image: $REGISTRY_IP:5000/hugo
  script:
    # Build the website   
    - hugo
  artifacts:
    paths:
      - ./public

Checking the pipeline now inside the GUI shows the improvement!

docker_registry

Worth it.