Reduce build time with Docker
One weird trick to reduce build time! CI services hate him!
This is a fairly simple way to reduce your build time if you spend a lot of time bundling dependencies prior to performing tests or deployments in CI.
The trick is to bundle any build dependencies into a Docker image so that you don’t have to install them each time you run a job.
Let’s take a look at my .gitlab-ci.yml
file that I used in “GitLab Review Apps with Zeit’s Now.sh service”:
As you can see above, I’m installing build dependencies for now
with npm install -g now --silent
in both the start_review
and stop_review
pipeline stages. This is unnecessary and is done every single time a job runs (not DRY). If you run enough builds, that’s a significant amount of time wasted.
Let’s build a simple Docker image that includes the now
dependency:
With a simple .gitlab-ci.yml
file to push the image to the GitLab container registry:
Now, instead of pulling from image: node
in our initial .gitlab-ci.yml
, we can use image: my.registry/hugo/now-image:latest
and remove the section of our .gitlab-ci.yml
where we install our build dependencies, because they’re already bundled!
Now we’ve shaved a bit of time off our builds 👌
If you liked this post, have questions or queries, or can help me make it better, please tweet me!
On the web
📝 10 May 2025 at 14:07 - So it turns out that rotavating tilling is really bloody...
Sat May 10 2025 by Kev QuirkCommitting XML horrors to style my blogroll
Sat May 10 2025 by nicholas.cloudThe Space Merchants
Fri May 9 2025 by joelchrono's websiteMoving my personal infrastructure to Kubernetes (single-node k3s)
Sun Apr 20 2025 by Stan's blogVisualizing Chess Bitboards
Sun Apr 13 2025 by Andrew Healey's Blog
Generated by openring