Application Development

Build containers faster with Cloud Build with Kaniko

At Google, we believe that fast builds are key to developer productivity. A recent internal study showed that our largest source of wasted engineering time comes from builds that take 2-10 minutes. We're not the only ones to notice this. In another study, Stripe found that companies waste $300 billion from lost developer productivity every year. And most importantly, our customers notice this as well! Faster builds and caching have been some of the most requested features for Cloud Build since we launched it in July.

Today, we're excited to announce a new feature for Cloud Build that caches container build artifacts, resulting in much faster build times. Based on Kaniko, an open-source tool for building container images from a Dockerfile, this feature stores and indexes intermediate layers inside of Google Container Registry, so they are available for use by subsequent builds. This feature is available for testing in Cloud SDK Release 229.0.0.

To try it out, run:

  $ gcloud config set builds/use_kaniko True

and then (from a directory with a Dockerfile in it) send a build with:

  $ gcloud build submit --tag=gcr.io/[PROJECT_ID]/foo

This cache is based on the exact Dockerfile and source context used by the build, and follows the general Dockerfile caching patterns. To learn more about how to optimize a Dockerfile for caching, see this documentation on leveraging the build cache. This cache is scoped on a "per-repository" basis, and has a six-hour TTL by default. This can be configured by running:

  $ gcloud config set builds/kaniko_cache_ttl <# of hours>

You can also use Kaniko instead of "docker build" in your cloudbuild.yaml config to take advantage of these caching improvements:

  steps:
- name: gcr.io/kaniko-project/executor
  args:
  - --destination=gcr.io/$PROJECT_ID/foo
  - --cache=true
  - --cache-ttl=6h

This is one of the first of many features we're rolling out in Cloud Build to automatically make your builds faster, smarter and more secure. Please try it out and let us know if you have any feedback by joining the Kaniko users Google Group.