Faster Docker builds using a remote BuildKit instance
Setting up a remote BuildKit instance on AWS can reduce Docker build times significantly. Key strategies include powerful hardware, layer caching, and Dockerfile optimization, benefiting small to medium-sized teams.
Read original articleDocker has transformed application development, but lengthy build times can hinder productivity. A recent blog post outlines how to set up a remote BuildKit instance on AWS to significantly reduce Docker build times. The author highlights three key strategies for optimizing builds: using powerful hardware, leveraging layer caching, and optimizing Dockerfiles. BuildKit, a modern backend for Docker, allows builds to be executed on a remote server, freeing local resources. By provisioning a compute-optimized EC2 instance and utilizing an EBS volume for persistent caching, teams can enhance build performance. The blog provides a step-by-step guide for setting up the remote BuildKit instance, including configuring GitHub Actions to connect to the BuildKit server. Initial tests showed a reduction in build time from over six minutes to just under two minutes when caching was utilized. However, the approach has limitations, including a lack of autoscaling, potential cost inefficiencies, and security risks associated with shared environments. Despite these drawbacks, the solution is effective for small to medium-sized teams looking to improve build performance.
- Setting up a remote BuildKit instance on AWS can significantly reduce Docker build times.
- Key optimization strategies include using powerful hardware, layer caching, and Dockerfile optimization.
- Initial tests showed a reduction in build time from 6:22 minutes to 1:34 minutes with caching.
- Limitations include lack of autoscaling, cost inefficiencies, and security risks in shared environments.
- The solution is particularly beneficial for small to medium-sized teams.
Related
Deep Dive into GitHub Actions Docker Builds with Docker Desktop
The beta release of Docker Desktop 4.31 introduces a feature enabling users to inspect GitHub Actions builds within the platform. It offers detailed performance metrics, cache utilization, and configuration details for enhanced visibility and collaboration.
From Cloud Chaos to FreeBSD Efficiency
A client shifted from expensive Kubernetes setups on AWS and GCP to cost-effective FreeBSD jails and VMs, improving control, cost savings, and performance. Real-world tests favored FreeBSD over cloud solutions, emphasizing efficient resource management.
Simple GitHub Actions Techniques
Denis Palnitsky's Medium article explores advanced GitHub Actions techniques like caching, reusable workflows, self-hosted runners, third-party managed runners, GitHub Container Registry, and local workflow debugging with Act. These strategies aim to enhance workflow efficiency and cost-effectiveness.
Runs-on: Self hosted, on-premise, GitHub Action runners
A new self-hosted runner solution, RunsOn, integrates with AWS to offer GitHub Actions users cost-effective and efficient CI/CD processes. Users benefit from faster builds, cost savings up to 80%, and customizable runner specifications.
We saved $5k a month with a single Grafana query
Checkly's platform team optimized costs by switching to Kubernetes pods from AWS ECS, reducing pod startup times by 300ms. This led to a 25% decrease in pod usage, saving $5.5k monthly.
- Several users discuss their own implementations of build optimization, including custom forks of BuildKit and alternative tools like Earthly and WarpBuild.
- There is a consensus on the importance of caching and efficient resource management to reduce build times.
- Some commenters express concerns about the costs associated with powerful cloud instances for builds.
- Users share insights on the challenges of CI/CD processes, particularly regarding test execution times.
- There is a desire for consistency in build service interfaces to facilitate switching between different cloud providers.
We've found that BuildKit has several inefficiencies preventing it from being as fast as it could be in the cloud, especially when dealing with simultaneous builds (common in CI). That led us to create our own optimized fork of BuildKit.
The number of fine-tuning knobs you can turn running a self-hosted BuildKit instance is limitless, but I also encourage everyone to try it as a fantastic learning exercise.
Of course, CI SaaSes implement a lot of caching on their end, but they also try to put people on the most anemic machines possible to try and capture those juicy margins.
We also currently have some jobs that build OCI images via the Docker/Podman CLI amd build using traditional Dockerfile/Containerfile scripts. For now those are centralized and run on just one host, on bare metal. I'd like to get those working via rootless Docker-in-Docker/Podman-in-Podman, but one thing that will be a little annoying with that is that we won't have any persistent caching at the Docker/Podman layer anymore. I suppose we'll end up using something like what's in the article to get that cache persistence back.
[1]: https://earthly.dev/
This should be protected with mTLS (https://docs.docker.com/build/drivers/remote/) or SSH (`endpoint: ssh://user@host`) to avoid potential cryptomining attack, etc.
I know it is out of style for some, but my microservice architecture, which has a dozen services, each takes about 1:30m to build, maybe 2m at most (if there is a slow Next.js build in there and a few thousand npm packages), and that is just on a 4 core GitHub Actions worker.
My microservices all build and deploy in parallel so this system doesn't get slower as you expand to more services.
(Open source template which shows how it works: https://github.com/bhouston/template-typescript-monorepo/act... )
As a side note: In my time running a CI infra co, we see that a majority of the workflow time for large teams comes from tests - which can have over 200 shards in some cases.
What’s the most common cause of builds taking this long in the first place…
Worst I have ever had was 5 minutes, but subsequent builds were reduced to under a minute due to build cache, creating multi-stage builds, and keeping the layers thin and optimizing the .dockerignore
Related
Deep Dive into GitHub Actions Docker Builds with Docker Desktop
The beta release of Docker Desktop 4.31 introduces a feature enabling users to inspect GitHub Actions builds within the platform. It offers detailed performance metrics, cache utilization, and configuration details for enhanced visibility and collaboration.
From Cloud Chaos to FreeBSD Efficiency
A client shifted from expensive Kubernetes setups on AWS and GCP to cost-effective FreeBSD jails and VMs, improving control, cost savings, and performance. Real-world tests favored FreeBSD over cloud solutions, emphasizing efficient resource management.
Simple GitHub Actions Techniques
Denis Palnitsky's Medium article explores advanced GitHub Actions techniques like caching, reusable workflows, self-hosted runners, third-party managed runners, GitHub Container Registry, and local workflow debugging with Act. These strategies aim to enhance workflow efficiency and cost-effectiveness.
Runs-on: Self hosted, on-premise, GitHub Action runners
A new self-hosted runner solution, RunsOn, integrates with AWS to offer GitHub Actions users cost-effective and efficient CI/CD processes. Users benefit from faster builds, cost savings up to 80%, and customizable runner specifications.
We saved $5k a month with a single Grafana query
Checkly's platform team optimized costs by switching to Kubernetes pods from AWS ECS, reducing pod startup times by 300ms. This led to a 25% decrease in pod usage, saving $5.5k monthly.