Skip to content

Commit def60fb

Browse files
committed
build: create script for setting up RBE in local dev environment
1 parent 86aad59 commit def60fb

File tree

5 files changed

+122
-44
lines changed

5 files changed

+122
-44
lines changed

.bazelrc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,52 @@ build --strategy=AngularTemplateCompile=worker
5858
# Use the legacy AOT compiler strategy. We don't want to compile with Ivy nor with "ngtsc" which
5959
# does not generate factory files which are needed for AOT.
6060
build --define=compile=legacy
61+
62+
################################
63+
# Remote Execution Setup #
64+
################################
65+
66+
# Use the Angular team internal GCP instance for remote execution.
67+
build:remote --remote_instance_name=projects/internal-200822/instances/default_instance
68+
build:remote --project_id=internal-200822
69+
70+
# Setup the build strategy for various types of actions. Mixing "local" and "remote"
71+
# can cause unexpected results and we want to run everything remotely if possible.
72+
build:remote --spawn_strategy=remote
73+
build:remote --strategy=Javac=remote
74+
build:remote --strategy=Closure=remote
75+
build:remote --strategy=Genrule=remote
76+
build:remote --define=EXECUTOR=remote
77+
78+
# Setup the remote build execution servers.
79+
build:remote --remote_cache=remotebuildexecution.googleapis.com
80+
build:remote --remote_executor=remotebuildexecution.googleapis.com
81+
build:remote --tls_enabled=true
82+
build:remote --auth_enabled=true
83+
84+
# Setup the toolchain and platform for the remote build execution. The platform
85+
# is automatically configured by the "rbe_autoconfig" rule in the project workpsace.
86+
build:remote --crosstool_top=@rbe_default//cc:toolchain
87+
build:remote --host_javabase=@rbe_default//java:jdk
88+
build:remote --javabase=@rbe_default//java:jdk
89+
build:remote --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
90+
build:remote --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8
91+
build:remote --extra_execution_platforms=//tools:rbe_platform
92+
build:remote --host_platform=//tools:rbe_platform
93+
build:remote --platforms=//tools:rbe_platform
94+
build:remote --extra_toolchains=@rbe_default//config:cc-toolchain
95+
96+
# Setup Build Event Service
97+
build:remote --bes_backend=buildeventservice.googleapis.com
98+
build:remote --bes_timeout=30s
99+
build:remote --bes_results_url="https://source.cloud.google.com/results/invocations/"
100+
101+
# Set remote caching settings
102+
build:remote --remote_accept_cached=true
103+
104+
################################
105+
# Local Environment Setup #
106+
################################
107+
# Load any settings which are specific to the current user. Needs to be *last* statement
108+
# in this config, as the user configuration should be able to overwrite flags from this file.
109+
try-import .bazelrc.user

.circleci/base-rbe-bazelrc

Lines changed: 0 additions & 30 deletions
This file was deleted.

.circleci/bazel.rc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,3 @@
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 --repository_cache=/home/circleci/bazel_repository_cache
8-
9-
########################################
10-
# Remote Build Execution support on CI #
11-
########################################
12-
13-
# Load base settings for remote build execution.
14-
import %workspace%/.circleci/base-rbe-bazelrc
15-
16-
# Use the Angular team internal GCP instance for remote execution.
17-
build:remote --remote_instance_name=projects/internal-200822/instances/default_instance
18-
build:remote --project_id=internal-200822
19-
20-
# Always read from remote cache on CI.
21-
build:remote --remote_accept_cached=true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ testem.log
4242
/.chrome
4343
/.git
4444
/.firebase
45+
/.bazelrc.user

scripts/local-dev/setup-rbe.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
# A script for automatically configuring a user's local dev
3+
# environment to use Remote Build Execution.
4+
5+
# Determine the root directory of the Angular github repo.
6+
GITHUB_DIRECTORY_ROOT=$(git rev-parse --show-toplevel 2> /dev/null);
7+
if [[ $? -ne 0 ]]; then
8+
echo "This command must be run from within the cloned \"angular/components\" repository."
9+
exit 1;
10+
fi
11+
12+
# Confirm gcloud installed and available as a command.
13+
if [ ! -x "$(command -v gcloud)" ]; then
14+
echo "gcloud command is not available. Please install gcloud before continuing."
15+
exit 1;
16+
fi
17+
18+
# Confirm the parameter provided to the script is a directory
19+
if [[ ! -d $1 ]]; then
20+
echo -e "Invalid command syntax.
21+
22+
\e[1mUsage:\e[0m $0 <ServiceAccountKeyLocation>
23+
24+
\e[1mExample:\e[0m $0 ~/my_key_storage_directory/
25+
26+
The directory provided will be used to store the GCP service account key
27+
for the angular-local-dev service account. This key will then be used to
28+
authenticate for usage of the Remote Build Execution system and Remote Caching.
29+
";
30+
exit 1;
31+
fi
32+
ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY=$(readlink -f $1)
33+
if [[ ! -d $ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY ]]; then
34+
echo "Can't find the absolute directory path"
35+
exit 1;
36+
fi
37+
38+
# Confirm the user is already logged into gcloud, if they aren't
39+
# attempt to login
40+
echo "Checking gcloud login state."
41+
gcloud auth print-identity-token &> /dev/null;
42+
if [[ $? -ne 0 ]]; then
43+
echo "Not currently logged into gcloud. Starting gcloud login now."
44+
gcloud auth login;
45+
if [[ $? -ne 0 ]]; then
46+
echo "gcloud login failed. Aborting.";
47+
exit 2
48+
fi
49+
fi
50+
51+
# Create the service account key in the provided directory.
52+
echo "Checking provided directory for a service account key."
53+
JSON_KEY_FILEPATH="$ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY/angular-local-dev-key.json";
54+
if [[ -f $JSON_KEY_FILEPATH ]]; then
55+
echo "Angular Local Dev key already exists, reusing this key."
56+
else
57+
gcloud iam service-accounts keys create $JSON_KEY_FILEPATH \
58+
--iam-account angular-local-dev@internal-200822.iam.gserviceaccount.com \
59+
--quiet --verbosity none --project internal-200822;
60+
echo $?;
61+
if [[ $? -ne 0 ]]; then
62+
echo "Downloading service account key failed. Aborting."
63+
exit 2;
64+
fi
65+
fi
66+
67+
# The full path to the .bazelrc.user file
68+
BAZELRC_USER_FILEPATH="$GITHUB_DIRECTORY_ROOT/.bazelrc.user";
69+
# Create the bazelrc.user file, echo the config flags into the file.
70+
touch $BAZELRC_USER_FILEPATH;
71+
echo "build --config=remote" >> $BAZELRC_USER_FILEPATH;
72+
echo "build --google_credentials=$JSON_KEY_FILEPATH" >> $BAZELRC_USER_FILEPATH;

0 commit comments

Comments
 (0)