Cache Data in Google Cloudbuild

Viewed 1869

I would like to use Google Cloudbuild to run integration tests. Currently, my tests take 30 minutes to run. The main bottleneck is that the tests query lots of data from external sources. I don't mind reusing the same data every time I run the tests. Is there a way for me to cache that data somewhere local to Cloudbuild so that it loads much faster?

3 Answers

The only cache that I know in Cloud Build is Kaniko cache which allow to cache the layer of your container.

Cloud Build also have an internal cache for caching the "cloud builder" image, (the image that you set in the name of your steps). You can see that in your Cloud Build logs:

Starting Step #0
Step #0: Already have image (with digest): gcr.io/cloud-builders/gcloud

The only way that I see is to build a custom "cloud builder" container with all your static file in it. Cloud Build have to download it only once and it will be cached (I don't know the TTL). In any case, the download from GCR will be very quick.

However, when your files change, you have to rebuild it. This is a new CI pipeline in your project.

You could store a static copy of the requirements in a folder in GCS and use an rsync and GCP's internal bandwidth to pull the files before you execute your build. This is much quicker than pulling them from across the internet. Just add a step early in the build like this.

- name: gcr.io/cloud-builders/gsutil
  args: ['rsync', '-r', 'gs://my-cache-bucket/repository', 'local-cache-dir']
Related