DEV Community

Harsha Vaidya
Harsha Vaidya

Posted on

2 1

Save precious build time with custom Docker registry

At our company we have a relatively new product in development. On the DevOps side, we have a pretty simple workflow for the testing stage. It involves:

  1. Git repository triggers Jenkins build.
  2. Latest pull is taken from the repository
  3. Frontend is built using npm
  4. Backend Docker image is built (which contains frontend files)
  5. The image is pushed to Dockerhub
  6. Using Ansible, we run a script in the target server.

On the target server (on premises):

  1. Pull the latest image.
  2. Restart all related containers using Docker Compose.

This is a pretty simple CI/CD system. Nothing too complex. Our codebase is consistently growing and each build took around 20 minutes. We have around 5 builds per day on average with 6 devs working on the project. So, we realised it's high time we optimised the build system a bit to handle more builds per day and reduce time for building priority images.

So, we looked into our Jenkins' build log and found out that pushing and pulling from Dockerhub took the most time (around 10 minutes). Since our test servers are on premises, we decided that having a custom registry (available as a Docker image) is the best solution to save time. So I looked into the Registry documentation (which is very well written πŸ˜€) and deployed it on one of the test servers. Then, I tweaked the build script a little bit to accommodate for the changes and Voila! The build time reduced to 12 minutes flat!!

One of by-products of this effort was reduced image size. I noticed that I was adding node modules and git folders (newbie mistake πŸ˜›) into the image which were bloating the image resulting in unnecessary pushes and pulls of the layers of the image. The image size reduced to 5GB from 8GB. This decreased the build time to 10 minutes flat.

Some lessons learned:

  1. Sometimes cloud is too expensive in terms of time (network latency 😞 ).
  2. Always inspect your image sizes and keep them as low as possible.
  3. In certain situations, managing your own services instead of cloud is not a bad solution.
  4. Monitor builds periodically for rapidly changing codebases for redundancies which can be potentially delaying your builds.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay