Mexson Fernandes
17 April 202369% decrease in Gitlab runner time after caching Docker layers
Gitlab CI/CD pipeline has big support for all times of automation. Having switched from Github Actions to Gitlab due to having all stuff at one place, I had made a good choice. Recently I compiled a Nodejs app which had so many external packages. This lead to 22 minute average Gitlab runner time. I was going out of free 400 minutes per month.
Now lets see how its done.
docker pull $CI_REGISTRY_IMAGE:latest || true
Now lets build the image using same tag.
docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:latest .
Push the image.
docker push $CI_REGISTRY_IMAGE:latest-sias
In this job stage I am using docker:19.03.12
image.
Use this example:
build docker:
image: docker:19.03.12
stage: build
services:
- docker:19.03.12-dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:latest
.
- docker push $CI_REGISTRY_IMAGE:latest