r/cicd•
DorianTurba

Gitlab CI, always define the image to alpine

In a nutshell, always define the image key in your jobs (even for helloworld jobs) to something "-alpine", you might gain minutes on every CI run.

Let's say you are discovering Gitlab CI, and you write your hellowold job:

helloworld:
  script:
    - echo "helloworld"

Then, you commit and push, reload the pipeline page, and wait. You wait the 30 longest seconds of your life.

Those 30 seconds, I see it all the time. Let's say you want a Python hellowold job:

python-helloworld:
  image: python
  script:
    - python -c "print('Hello World')"

And here we go, 30 seconds again. For one job, for one echo or one print.

Let say we now have build jobs, tests jobs and deploy jobs. 3 stages. Lets assume everything inside might be parallelized (we are lucky), this means that we spend at least 1 minute and 30 seconds waiting... For nothing.

I will let you know a secret, guarded among the secret concil of the holy devops for centuries...

Here it is: >!Just use alpine!<

Let's go back to our previous example, and see how to do that:

helloworld:1/2:
  script:
    - echo "helloworld"

helloworld:2/2:
  image: alpine
  script:
    - echo "helloworld"

python-helloworld:1/2:
  image: python
  script:
    - python -c "print('Hello World')"

python-helloworld:2/2:
  image: python:alpine
  script:
    - python -c "print('Hello World')"

This will create 4 jobs. The two jobs suffixed 1/2 will take around 23 to 30 seconds to run, on gitlab.com runners. The one suffixed 2/2 will take around 7 to 9 seconds to run. This means that I usually don't even have the time to see the job being "running" that they are already finished by the time I go to my browser and reload the pipeline page after my commit and push.

This simple and very basic change is ridiculous, but, and I am not joking, happens A LOT, even on production and large companies, even with DevOps dedicated teams.

Why is it so fast? Because default image is ruby:3.1, this image and python are very large. alpine images are lightweight, with less tools available but it is quite often faster to use alpine and install the missing specific things you need than to go with EVERYHTING ELSE.

If you want to see by yourself the result of this little experiment, here is the pipeline on my ci test project: https://gitlab.com/dorianturba/zero-to-ci/-/pipelines/2874152788

The code is available here: https://gitlab.com/dorianturba/zero-to-ci/-/blob/3d7403e90cb1991cc16da88f2fcca4c6414f8152/.gitlab-ci.yml

Note: Sometime, you don't want to use alpine. If you are in those specific usecase, you already know it, and you probably also know what to do.

Posted Sep 23, 2026, 8:34 AM UTC

13
Loading comments…