gpt4 book ai didi

docker - 如何加速 Google Cloud Platform 上的 bazel 构建

转载 作者:行者123 更新时间:2023-12-02 05:40:52 24 4
gpt4 key购买 nike

我正在使用 gcr.io/cloud-builders/bazel 在 Google 容器构建上构建我的镜像。

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

如何加快 Google Cloud Platform 上这些 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}']

最佳答案

Container Builder 目前不提供此内置功能,但您可以自己完成。

  1. 将一个或多个添加到构建步骤,以输出您想要在以后构建中恢复的信息。 (参见documentation on volumes。)
  2. 如有必要,请修改这些构建步骤,以将要保留的数据输出到卷提供的路径中。
  3. 在后续构建步骤中,使用 gsutil build step将卷中的所有数据保存到GCS存储桶中。 (当然,如果您愿意,您可以使用其他实用程序将其保存到其他位置。)

在以后的构建中,使用 gsutil 将数据恢复到所需的卷,并将该卷挂载到后续构建步骤中。

关于docker - 如何加速 Google Cloud Platform 上的 bazel 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46457170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com