1

我使用gcr.io/cloud-builders/bazel在Google容器构建上构建我的图像。如何加快谷歌云平台上的bazel构建

从日志看来,它似乎花费大部分时间为bazel设置工作区。这个工作空间不会因构建而改变,所以我认为可以预先计算并存储在一个新的图像中。

如何加快Google云端平台上的这些bazel版本?

Already have image (with digest): gcr.io/cloud-builders/bazel 
Extracting Bazel installation... 
........................ 
Loading: 
Loading: 0 packages loaded 
Loading: 0 packages loaded 
Loading: 0 packages loaded 
Loading: 0 packages loaded 
Loading: 0 packages loaded 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: com_github_golang_protobuf : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: com_github_golang_glog : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: org_golang_google_grpc : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: org_golang_x_net : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: com_github_gogo_protobuf : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: com_github_grpc_ecosystem_grpc_gateway : new_go_repository is deprecated. Please migrate to go_repository soon. 
WARNING: /builder/home/.cache/bazel/_bazel_root/eab0d61a99b6696edb3d2aff87b585e8/external/io_bazel_rules_go/go/def.bzl:137:3: DEPRECATED: org_golang_google_genproto : new_go_repository is deprecated. Please migrate to go_repository soon. 
Analyzing: target //:docker (4 packages loaded) 
Analyzing: target //:docker (5 packages loaded) 
Analyzing: target //:docker (6 packages loaded) 
Analyzing: target //:docker (76 packages loaded) 
Analyzing: target //:docker (78 packages loaded) 
Analyzing: target //:docker (78 packages loaded) 
Analyzing: target //:docker (79 packages loaded) 
Analyzing: target //:docker (79 packages loaded) 
Analyzing: target //:docker (80 packages loaded) 
Analyzing: target //:docker (160 packages loaded) 
Analyzing: target //:docker (160 packages loaded) 
Analyzing: target //:docker (160 packages loaded) 
Analyzing: target //:docker (160 packages loaded) 
Analyzing: target //:docker (174 packages loaded) 
Analyzing: target //:docker (174 packages loaded) 
Analyzing: target //:docker (211 packages loaded) 
INFO: Analysed target //:docker (286 packages loaded). 
INFO: Found 1 target... 
[0/1] BazelWorkspaceStatusAction stable-status.txt 
[17/19] SHA256 external/golang/image/002.tar.gz.nogz.sha256 
[42/281] no action running 
[51/290] no action running 
[63/302] no action running 
[80/319] no action running 
[101/340] no action running 
[118/358] no action running 
[138/378] no action running 
[168/407] Compiling external/com_github_google_protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc [for host]; 0s linux-sandbox 
[200/439] Compiling external/com_github_google_protobuf/src/google/protobuf/extension_set.cc [for host]; 1s linux-sandbox 
INFO: From ProtoCompile assets/assets/assets.pb.gw.go: 
assets/assets/assets.proto: warning: Import recipes.proto but not used. 
INFO: From ProtoCompile assets/assets/assets.swagger.json: 
assets/assets/assets.proto: warning: Import recipes.proto but not used. 
INFO: From ProtoCompile assets/assets/assets.pb.go: 
assets/assets/assets.proto: warning: Import recipes.proto but not used. 
[522/697] GoCompile vendor/github.com/gorilla/mux/~lib~/go_default_library.o; 0s linux-sandbox 
Target //:docker up-to-date: 
bazel-bin/docker-layer.tar 
INFO: Elapsed time: 331.343s, Critical Path: 13.73s 
INFO: Build completed successfully, 737 total actions 

编辑:添加cloudbuild文件

cloudbuild.yaml:

steps: 
- name: gcr.io/cloud-builders/bazel 
    args: ['run', '//:docker'] 
- name: gcr.io/cloud-builders/docker 
    args: ['tag', 'bazel:docker', '${_IMAGE_TAG}'] 
images: ['${_IMAGE_TAG}'] 
+0

你如何运行它?发布完整的命令? –

+0

添加了我正在使用的cloudbuild文件 – fabrizioM

+0

从最初查看所有可用文档的信息可以看出,在这种情况下,缓存或卷没有任何功能可以帮助您。所以最好的是要求Google支持 –

回答

4

集装箱生成器不提供这是一个内置在这个时候,但你可以自己做。

  1. 将一个或多个volumes添加到构建步骤,以输出您希望在以后的构建中还原的信息。 (请参阅documentation on volumes。)
  2. 如有必要,请修改这些构建步骤以将要保留的数据输出到卷提供的路径中。
  3. 在随后的构建步骤中,使用gsutilbuild step将卷中的所有数据保存到GCS存储桶。 (你当然也可以使用一些其他的工具将它保存到其他地方,如果你想。)

在以后的版本中,使用gsutil将数据恢复到所需的量,并装入容积为后续建立一步。