Google Cloud Build - 如何缓存 Bazel?
Google Cloud Build - How to Cache Bazel?
我最近开始将 Cloud Build 与 Bazel 结合使用。
所以我有一个基本的 cloudbuild.yaml
steps:
- id: 'run unit tests'
name: gcr.io/cloud-builders/bazel
args: ['test', '//...']
它运行我的 Bazel 项目的所有测试。
但是正如您从这个屏幕截图中看到的,每个构建大约需要 4 分钟,尽管我没有触及任何会影响我的测试的代码。
本地 运行 第一次测试大约需要 1 分钟。但是运行第二次测试,在Bazels缓存的帮助下,只需要几秒钟。
所以我的目标是将 Bazel 缓存与 Google Cloud Build
一起使用
更新
正如 Thierry Falvo I'v looked into those recommendations 所建议的那样。因此,我尝试将以下内容添加到我的 cloudbuild.yaml
:
steps:
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://cents-ideas-build-cache/bazel-bin', 'bazel-bin']
- id: 'run unit tests'
name: gcr.io/cloud-builders/bazel
args: ['test', '//...']
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'bazel-bin', 'gs://cents-ideas-build-cache/bazel-bin']
尽管我创建了存储桶和文件夹,但出现此错误:
CommandException: No URLs matched
我认为与其缓存离散结果(工件),不如使用 GCS(云存储)作为 bazel remote cache。
- name: gcr.io/cloud-builders/bazel
args: ['test', '--remote_cache=https://storage.googleapis.com/<bucketname>', '--google_default_credentials', '--test_output=errors', '//...']
我最近开始将 Cloud Build 与 Bazel 结合使用。
所以我有一个基本的 cloudbuild.yaml
steps:
- id: 'run unit tests'
name: gcr.io/cloud-builders/bazel
args: ['test', '//...']
它运行我的 Bazel 项目的所有测试。
但是正如您从这个屏幕截图中看到的,每个构建大约需要 4 分钟,尽管我没有触及任何会影响我的测试的代码。
本地 运行 第一次测试大约需要 1 分钟。但是运行第二次测试,在Bazels缓存的帮助下,只需要几秒钟。
所以我的目标是将 Bazel 缓存与 Google Cloud Build
一起使用更新
正如 Thierry Falvo I'v looked into those recommendations 所建议的那样。因此,我尝试将以下内容添加到我的 cloudbuild.yaml
:
steps:
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'gs://cents-ideas-build-cache/bazel-bin', 'bazel-bin']
- id: 'run unit tests'
name: gcr.io/cloud-builders/bazel
args: ['test', '//...']
- name: gcr.io/cloud-builders/gsutil
args: ['cp', 'bazel-bin', 'gs://cents-ideas-build-cache/bazel-bin']
尽管我创建了存储桶和文件夹,但出现此错误:
CommandException: No URLs matched
我认为与其缓存离散结果(工件),不如使用 GCS(云存储)作为 bazel remote cache。
- name: gcr.io/cloud-builders/bazel
args: ['test', '--remote_cache=https://storage.googleapis.com/<bucketname>', '--google_default_credentials', '--test_output=errors', '//...']