Skip to content

Commit 7fc1c0c

Browse files
committed
build: setup bazel remote execution
1 parent d22f48c commit 7fc1c0c

File tree

5 files changed

+182
-8
lines changed

5 files changed

+182
-8
lines changed

.circleci/base-rbe-bazelrc

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# ------------------------------
2+
# This file is taken from the "bazel-toolchains" repository and is used in order to reduce the
3+
# manual configuration overhead. https://github.com/bazelbuild/bazel-toolchains/tree/master/bazelrc
4+
# ------------------------------
5+
6+
# Copyright 2016 The Bazel Authors. All rights reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
# Depending on how many machines are in the remote execution instance, setting
21+
# this higher can make builds faster by allowing more jobs to run in parallel.
22+
# Setting it too high can result in jobs that timeout, however, while waiting
23+
# for a remote machine to execute them.
24+
build:remote --jobs=50
25+
26+
# Set several flags related to specifying the platform, toolchain and java
27+
# properties.
28+
# These flags are duplicated rather than imported from (for example)
29+
# %workspace%/configs/ubuntu16_04_clang/1.1/toolchain.bazelrc to make this
30+
# bazelrc a standalone file that can be copied more easily.
31+
# These flags should only be used as is for the rbe-ubuntu16-04 container
32+
# and need to be adapted to work with other toolchain containers.
33+
build:remote --host_javabase=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:jdk8
34+
build:remote --javabase=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:jdk8
35+
build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
36+
build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
37+
build:remote --crosstool_top=@bazel_toolchains//configs/ubuntu16_04_clang/1.1/bazel_0.18.0/default:toolchain
38+
build:remote --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
39+
# Platform flags:
40+
# The toolchain container used for execution is defined in the target indicated
41+
# by "extra_execution_platforms", "host_platform" and "platforms".
42+
# If you are using your own toolchain container, you need to create a platform
43+
# target with "constraint_values" that allow for the toolchain specified with
44+
# "extra_toolchains" to be selected (given constraints defined in
45+
# "exec_compatible_with").
46+
# More about platforms: https://docs.bazel.build/versions/master/platforms.html
47+
build:remote --extra_toolchains=@bazel_toolchains//configs/ubuntu16_04_clang/1.1/bazel_0.18.0/cpp:cc-toolchain-clang-x86_64-default
48+
build:remote --extra_execution_platforms=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:rbe_ubuntu1604
49+
build:remote --host_platform=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:rbe_ubuntu1604
50+
build:remote --platforms=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:rbe_ubuntu1604
51+
52+
# Set various strategies so that all actions execute remotely. Mixing remote
53+
# and local execution will lead to errors unless the toolchain and remote
54+
# machine exactly match the host machine.
55+
build:remote --spawn_strategy=remote
56+
build:remote --strategy=Javac=remote
57+
build:remote --strategy=Closure=remote
58+
build:remote --genrule_strategy=remote
59+
build:remote --define=EXECUTOR=remote
60+
61+
# Enable the remote cache so action results can be shared across machines,
62+
# developers, and workspaces.
63+
build:remote --remote_cache=remotebuildexecution.googleapis.com
64+
65+
# Enable remote execution so actions are performed on the remote systems.
66+
build:remote --remote_executor=remotebuildexecution.googleapis.com
67+
68+
# Enable encryption.
69+
build:remote --tls_enabled=true
70+
71+
# Enforce stricter environment rules, which eliminates some non-hermetic
72+
# behavior and therefore improves both the remote cache hit rate and the
73+
# correctness and repeatability of the build.
74+
build:remote --experimental_strict_action_env=true
75+
76+
# Set a higher timeout value, just in case.
77+
build:remote --remote_timeout=3600
78+
79+
# Enable authentication. This will pick up application default credentials by
80+
# default. You can use --auth_credentials=some_file.json to use a service
81+
# account credential instead.
82+
build:remote --auth_enabled=true
83+
84+
# Set flags for uploading to BES in order to view results in the Bazel Build
85+
# Results UI.
86+
build:results --bes_backend="buildeventservice.googleapis.com"
87+
build:results --bes_timeout=60s
88+
build:results --tls_enabled
89+
90+
# Output BES results url
91+
build:results --bes_results_url="https://source.cloud.google.com/results/invocations/"
92+
93+
# Set flags for uploading to BES without Remote Build Execution.
94+
build:results-local --bes_backend="buildeventservice.googleapis.com"
95+
build:results-local --bes_timeout=60s
96+
build:results-local --tls_enabled=true
97+
build:results-local --auth_enabled=true
98+
build:results-local --spawn_strategy=local
99+
build:results-local --remote_cache=remotebuildexecution.googleapis.com
100+
build:results-local --remote_timeout=3600
101+
build:results-local --bes_results_url="https://source.cloud.google.com/results/invocations/"
102+
103+
# The following flags are only necessary for local docker sandboxing
104+
# with the rbe-ubuntu16-04 container. Use of these flags is still experimental.
105+
build:docker-sandbox --host_javabase=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:jdk8
106+
build:docker-sandbox --javabase=@bazel_toolchains//configs/ubuntu16_04_clang/1.1:jdk8
107+
build:docker-sandbox --crosstool_top=@bazel_toolchains//configs/ubuntu16_04_clang/1.1/bazel_0.18.0/default:toolchain
108+
build:docker-sandbox --experimental_docker_image=gcr.io/cloud-marketplace/google/rbe-ubuntu16-04@sha256:9bd8ba020af33edb5f11eff0af2f63b3bcb168cd6566d7b27c6685e717787928
109+
build:docker-sandbox --spawn_strategy=docker
110+
build:docker-sandbox --strategy=Javac=docker
111+
build:docker-sandbox --strategy=Closure=docker
112+
build:docker-sandbox --genrule_strategy=docker
113+
build:docker-sandbox --define=EXECUTOR=remote
114+
build:docker-sandbox --experimental_docker_verbose
115+
build:docker-sandbox --experimental_enable_docker_sandbox
116+
117+
# The following flags enable the remote cache so action results can be shared
118+
# across machines, developers, and workspaces.
119+
build:remote-cache --remote_cache=remotebuildexecution.googleapis.com
120+
build:remote-cache --tls_enabled=true
121+
build:remote-cache --experimental_strict_action_env=true
122+
build:remote-cache --remote_timeout=3600
123+
build:remote-cache --auth_enabled=true
124+
build:remote-cache --spawn_strategy=standalone
125+
build:remote-cache --strategy=Javac=standalone
126+
build:remote-cache --strategy=Closure=standalone
127+
build:remote-cache --genrule_strategy=standalone

.circleci/bazel.rc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,23 @@
55
# Save downloaded repositories in a location that can be cached by CircleCI. This helps us
66
# speeding up the analysis time significantly with Bazel managed node dependencies on the CI.
77
build --experimental_repository_cache=/home/circleci/bazel_repository_cache
8+
9+
########################################
10+
# Remote Build Execution support on CI #
11+
########################################
12+
13+
# Load default settings for Remote Build Execution.
14+
import %workspace%/.circleci/base-rbe-bazelrc
15+
16+
# Custom execution platform defined in the Angular repository. See:
17+
# https://github.com/angular/angular/blob/master/tools/BUILD.bazel#L21
18+
build:remote --extra_execution_platforms=@angular//tools:rbe_ubuntu1604-angular
19+
build:remote --host_platform=@angular//tools:rbe_ubuntu1604-angular
20+
build:remote --platforms=@angular//tools:rbe_ubuntu1604-angular
21+
22+
# Use the Angular team internal GCP instance for remote execution.
23+
build:remote --remote_instance_name=projects/internal-200822/instances/default_instance
24+
25+
# Do not accept remote cache *yet*. We need to understand the security risks of using prior build
26+
# artifacts. TODO(devversion): chat with Alex about the state of accepting cached artifacts.
27+
build:remote --remote_accept_cached=false

.circleci/config.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,38 @@ var_6: &save_cache
3939
- "node_modules"
4040
- "~/bazel_repository_cache"
4141

42+
var_7: &gcp_user "ej0iCiI7V3o9J2RlbnQnO2x6PScvLmdjJztRej0nIC9obyc7THo9J2VuIC0nO0V6PSdjYmMgJztyej0nQVNIXyc7S3o9J190b2snO2d6PSdOX0NSJztzej0nRU5WOyc7Uno9J21lL2MnO0J6PSdzc2wgJztGej0nLWQgLSc7QXo9J29wZW4nO0p6PScvZ2NwJztHej0naW4gLic7bno9J2VkZW4nO2F6PSdleHBvJzttej0ncF9jcic7Y3o9J09PR0wnO2R6PSdFX0FQJztUej0nZWNpLyc7WXo9JzsgZWMnO3F6PSc+ICRCJztrej0nb21lLyc7TXo9J2sgImEnO2h6PSdFREVOJztYej0naWFscyc7cHo9J3MiID4nO1Z6PSdfY3JlJztaej0naG8gIic7ZXo9J1BMSUMnO2l6PSdUSUFMJztiej0ncnQgRyc7Q3o9J2Flcy0nO296PSd0aWFsJztPej0nYXIiICc7ano9J1M9L2gnO1V6PScuZ2NwJztOej0nbmd1bCc7SXo9J2xlY2knO0R6PScyNTYtJztIej0nY2lyYyc7Zno9J0FUSU8nO1N6PSdpcmNsJztQej0nLW91dCc7"
43+
4244
# Job step that ensures that the node module dependencies are installed and up-to-date. We use
4345
# Yarn with the frozen lockfile option in order to make sure that lock file and package.json are
4446
# in sync. Unlike in Travis, we don't need to manually purge the node modules if stale because
4547
# CircleCI automatically discards the cache if the checksum of the lock file has changed.
46-
var_7: &yarn_install
48+
var_8: &yarn_install
4749
run: yarn install --frozen-lockfile --non-interactive
4850

4951
# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
5052
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
51-
var_8: &copy_bazel_config
53+
var_9: &copy_bazel_config
5254
# Set up the CircleCI specific bazel configuration.
5355
run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc
5456

5557
# Sets up a different Docker image that includes a moe recent Firefox version which
5658
# is needed for headless testing.
57-
var_9: &docker-firefox-image
59+
var_10: &docker-firefox-image
5860
# TODO(devversion): Temporarily use a image that includes Firefox 62 because the
5961
# ngcontainer image does include an old Firefox version that does not support headless.
6062
- image: circleci/node:11.4.0-browsers
6163

6264
# Attaches the release output which has been stored in the workspace to the current job.
6365
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
64-
var_10: &attach_release_output
66+
var_11: &attach_release_output
6567
attach_workspace:
6668
at: dist/releases
6769

68-
6970
# Branch filter that we can specify for jobs that should only run on publish branches. This filter
7071
# is used to ensure that not all upstream branches will be published as Github builds
7172
# (e.g. revert branches, feature branches)
72-
var_11: &publish_branches_filter
73+
var_12: &publish_branches_filter
7374
branches:
7475
only:
7576
- master
@@ -83,11 +84,18 @@ var_11: &publish_branches_filter
8384
# In order to reduce duplication we use a YAML anchor that just always excludes the "_presubmit"
8485
# branch. We don't want to run Circle for the temporary "_presubmit" branch which is reserved
8586
# for the caretaker.
86-
var_12: &ignore_presubmit_branch_filter
87+
var_13: &ignore_presubmit_branch_filter
8788
branches:
8889
ignore:
8990
- "_presubmit"
9091

92+
# Runs a script that sets up the Bazel remote execution. This will be used by jobs that run
93+
# Bazel primarily and should benefit from remote caching and execution.
94+
var_14: &setup_bazel_remote_execution
95+
run:
96+
name: "Setup bazel RBE remote execution"
97+
command: ./scripts/circleci/bazel/setup-remote-execution.sh
98+
9199
# -----------------------------
92100
# Container version of CircleCI
93101
# -----------------------------
@@ -105,10 +113,13 @@ jobs:
105113
bazel_build_test:
106114
<<: *job_defaults
107115
resource_class: xlarge
116+
environment:
117+
GCP_USER: *gcp_user
108118
steps:
109119
- *checkout_code
110120
- *restore_cache
111121
- *copy_bazel_config
122+
- *setup_bazel_remote_execution
112123

113124
- run: bazel build src/...
114125
- run: bazel test src/...
@@ -122,11 +133,15 @@ jobs:
122133
# This job fails whenever an API has been updated but not explicitly approved through goldens.
123134
# --------------------------------------------------------------------------------------------
124135
api_golden_checks:
125-
resource_class: xlarge
126136
<<: *job_defaults
137+
resource_class: xlarge
138+
environment:
139+
GCP_USER: *gcp_user
127140
steps:
128141
- *checkout_code
129142
- *restore_cache
143+
- *copy_bazel_config
144+
- *setup_bazel_remote_execution
130145

131146
- run: bazel test tools/public_api_guard/...
132147

.circleci/gcp_token

2.31 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
if [[ -z "${GCP_USER}" ]]; then
4+
echo "Please specify the \"GCP_USER\" environment variable when setting up remote execution"
5+
exit 1
6+
fi
7+
8+
# Setup Bazel execution by decoding the GCP token.
9+
z="\n";Ez='CP_U';gz='z$dz';Az='eval';Uz='z$Nz';Hz='base';Iz='64 -';nz='$Iz$';dz='z$Zz';Jz='d); ';Xz='z$Rz';Nz='Dz$E';pz='z$nz';iz='fz$g';Kz=' "$A';Mz='$Cz$';Dz='"${G';Vz='$Oz$';hz='$ez$';Pz='$Gz$';Fz='SER}';jz='z$hz';rz='pz$q';Sz='$Kz$';fz='bz$c';az='z$Vz';sz='z$rz';lz='jz$k';Oz='z$Fz';Wz='Pz$Q';oz='lz$m';Lz='z$Bz';Zz='Tz$U';qz='$oz$';Rz='z$Jz';Tz='Lz$M';ez='$az$';Cz='cho ';mz='z$Hz';Yz='$Sz$';bz='$Wz$';kz='$iz$';Qz='Hz$I';Gz='" | ';cz='Xz$Y';Bz=' $(e';tz='$sz"'; eval "$Az$Bz$Cz$Dz$Ez$Fz$Gz$Hz$Iz$Jz$Az$Kz$Lz$Mz$Nz$Oz$Pz$Qz$Rz$Sz$Tz$Uz$Vz$Wz$Xz$Yz$Zz$az$bz$cz$dz$ez$fz$gz$hz$iz$jz$kz$lz$mz$nz$oz$pz$qz$rz$sz$tz"
10+
11+
# Update the global Bazel configuration to always use remote execution.
12+
sudo bash -c "echo 'build --config=remote' >> /etc/bazel.bazelrc"

0 commit comments

Comments
 (0)