Home > other >  Check whether a build is necessary during GitLab CI
Check whether a build is necessary during GitLab CI

Time:08-07

As part of CI on GitLab, we build a Docker image which is then pushed to the image repository and used for the following tasks. However, this happens every CI run, despite the fact most of the time it's building an identical image. How can we check whether a rebuild is necessary, and just pull the last build if not?

CodePudding user response:

As you haven't specified a lot of details about your setup, I leave some ideas and hints on how to tackle the issue.

Conditional CI Builds In case your code is located in a dedicated folder, it's quite easy to setup jobs based on rules as described here. That would skip the entire job and therefore you wouldn't rebuild the image.

Docker Layer Caching Docker itself can recognize if the image hasn't changed. It obviously depends on your exact Dockerfile, but if you pull your image before building it, the layer cache would skip the entire build. That would leave you with the CI job, but from my experience these finish in less than 1 minute. That's both cheap and fast.

Hope that helps.

  • Related