Skip to content

Commit ef69bce

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

File tree

5 files changed

+113
-44
lines changed

5 files changed

+113
-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
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 "Invalid command syntax. Usage: ./script.sh <ServiceAccountKeyLocation>";
21+
exit 1;
22+
fi
23+
ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY=$(readlink -f $1)
24+
if [[ ! -d $ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY ]]; then
25+
echo "Can't find the absolute directory path"
26+
exit 1;
27+
fi
28+
29+
# Confirm the user is already logged into gcloud, if they aren't
30+
# attempt to login
31+
echo "Checking gcloud login state."
32+
gcloud auth print-identity-token &> /dev/null;
33+
if [[ $? -ne 0 ]]; then
34+
echo "Not currently logged into gcloud. Starting gcloud login now."
35+
gcloud auth login;
36+
if [[ $? -ne 0 ]]; then
37+
echo "gcloud login failed. Aborting.";
38+
exit 2
39+
fi
40+
fi
41+
42+
# Create the service account key in the provided directory.
43+
echo "Checking provided directory for a service account key."
44+
JSON_KEY_FILEPATH="$ABSOLUTE_PATH_TO_DIRECTORY_FOR_KEY/angular-local-dev-key.json";
45+
if [[ -f $JSON_KEY_FILEPATH ]]; then
46+
echo "Angular Local Dev key already exists, reusing this key."
47+
else
48+
gcloud iam service-accounts keys create $JSON_KEY_FILEPATH \
49+
--iam-account angular-local-dev@internal-200822.iam.gserviceaccount.com \
50+
--quiet --verbosity none --project internal-200822;
51+
echo $?;
52+
if [[ $? -ne 0 ]]; then
53+
echo "Downloading service account key failed. Aborting."
54+
exit 2;
55+
fi
56+
fi
57+
58+
# The full path to the .bazelrc.user file
59+
BAZELRC_USER_FILEPATH="$GITHUB_DIRECTORY_ROOT/.bazelrc.user";
60+
# Create the bazelrc.user file, echo the config flags into the file.
61+
touch $BAZELRC_USER_FILEPATH;
62+
echo "build --config=remote" >> $BAZELRC_USER_FILEPATH;
63+
echo "build --google_credentials=$JSON_KEY_FILEPATH" >> $BAZELRC_USER_FILEPATH;

0 commit comments

Comments
 (0)