FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

build: address comments, restructure setup-rbe.sh script (#33109) · javascriptStudy111/angular@418e9cf · GitHub

Commit 418e9cf

Browse files
authored andcommitted
build: address comments, restructure setup-rbe.sh script (angular#33109)
PR Close angular#33109
1 parent fa0ab38 commit 418e9cf

4 files changed

Lines changed: 86 additions & 30 deletions

File tree

‎.bazelrc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ test --test_output=errors
7171
# any bazel target. This is a temporary flag until codebase is permanently switched to Ivy.
7272
build --define=compile=legacy
7373

74-
build --google_default_credentials
75-
7674
#######################
7775
# Remote HTTP Caching #
7876
#######################
@@ -86,6 +84,7 @@ build --remote_upload_local_results=false
8684
# --config=-http-caching #
8785
######################################
8886
build:remote-http-caching --remote_upload_local_results=true
87+
build:remote-http-caching --google_default_credentials
8988

9089
##################################
9190
# Remote Build Execution support #
@@ -99,6 +98,7 @@ import %workspace%/third_party/github.com/bazelbuild/bazel-toolchains/bazelrc/.b
9998
# Increase the default number of jobs by 50% because our build has lots of
10099
# parallelism
101100
build:remote --jobs=150
101+
build:remote --google_default_credentials
102102

103103
# Toolchain and platform related flags
104104
build:remote --host_javabase=@rbe_ubuntu1604_angular//java:jdk

‎docs/DEVELOPER.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ It will automatically recognize `*.bazel` and `*.bzl` files.
169169
### Remote Build Execution and Remote Caching
170170
Bazel builds in the Angular repository use a shared http cache. When a build occurs a hash of the inputs is computed
171171
and checked against available outputs in the shared http cache. If an output is found, it is used as the output for the
172-
build action rather than performing the build locally.
172+
build action rather than performing the build locally.
173+
174+
> Remote Build Execution and uploading to the Remote Cache requires authentication as a google.com or angular.io account.
173175
174176
### --config=remote-http-caching flag
175177
The `--config=remote-http-caching` flag can be added to enable uploading of build results to the shared http cache. This flag
176178
can be added to the `.bazelrc.user` file using the script at `scripts/local-dev/setup-rbe.sh`.
177179

178180
### --config=remote flag
179-
The `--config=remote-http-caching` flag can be added to enable remote execution of builds. This flag can be added to
181+
The `--config=remote` flag can be added to enable remote execution of builds. This flag can be added to
180182
the `.bazelrc.user` file using the script at `scripts/local-dev/setup-rbe.sh`.

‎scripts/local-dev/get-email‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Retrieves the email value from a json object. This assumes
5+
* the email attributes is at the base of the object, as returned
6+
* by Google Cloud's tokeninfo api.
7+
*/
8+
9+
// Read information being piped in.
10+
var stdin = process.openStdin();
11+
// Stored data stream.
12+
var data = "";
13+
14+
// Store each chunk of the stream in data.
15+
stdin.on('data', chunk => data += chunk);
16+
17+
// After stream ends, parse data and get value requested.
18+
stdin.on('end', () => {
19+
// The JSON object, to be accessed.
20+
let output = JSON.parse(data);
21+
22+
// Print the output to STDOUT.
23+
console.log(output['email']);
24+
});

‎scripts/local-dev/setup-rbe.sh‎

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/bin/bash
22
# A script for automatically configuring a user's local dev
33
# environment to use Remote Build Execution.
4-
54
# Short cuts to set output as bold and normal
65
bold=$(tput bold)
76
normal=$(tput sgr0)
87

8+
###########################################################
9+
# Setup/Confirm Environment #
10+
###########################################################
11+
# The full path location of the script
12+
full_script_path="$(pwd)/$(dirname ${BASH_SOURCE[0]})"
913
# Determine the root directory of the Angular github repo.
1014
project_directory=$(git rev-parse --show-toplevel 2> /dev/null)
1115
if [[ $? -ne 0 ]]; then
@@ -20,32 +24,49 @@ if [ ! -x "$(command -v gcloud)" ]; then
2024
exit 1
2125
fi
2226

23-
# Confirm the user is already logged into gcloud, if they aren't
24-
# attempt to login
25-
echo "Checking gcloud login state"
26-
gcloud auth application-default print-access-token &> /dev/null
27-
if [[ $? -ne 0 ]]; then
28-
echo "Not currently logged into gcloud. Starting gcloud login now"
27+
# The full path to the .bazelrc.user file
28+
bazelrc_user_filepath="$project_directory/.bazelrc.user"
29+
30+
###########################################################
31+
# Action Functions #
32+
###########################################################
33+
# Log into gcloud
34+
function gcloud_login() {
2935
gcloud auth application-default login
3036
if [[ $? -ne 0 ]]; then
3137
echo "gcloud login failed. Aborting"
3238
exit 2
3339
fi
34-
fi
35-
access_token=$(gcloud auth application-default print-access-token)
36-
current_account=$(curl -s https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$access_token | jq -r '.email')
37-
if [[ ! $current_account =~ (angular\.io$)|(google\.com$) ]]; then
38-
echo "Currently an angular.io or google.com account must be used for remote Bazel usage"
39-
echo "Please login instead using the correct account with the following command, then rerun"
40-
echo " gcloud auth application-default login"
41-
exit 3
42-
fi
43-
echo "Logged in as $current_account";
40+
}
4441

45-
# The full path to the .bazelrc.user file
46-
bazelrc_user_filepath="$project_directory/.bazelrc.user"
47-
# Create the bazelrc.user file, echo the config flags into the file.
48-
touch $bazelrc_user_filepath
42+
# Confirm the user is already logged into gcloud, if they aren't
43+
# attempt to login. After login, confirm the logged in account
44+
# is from the correct domain.
45+
function confirm_gcloud_login() {
46+
echo "Checking gcloud login state"
47+
gcloud auth application-default print-access-token &> /dev/null
48+
if [[ $? -ne 0 ]]; then
49+
echo "Not currently logged into gcloud. Starting gcloud login now"
50+
gcloud_login
51+
fi
52+
access_token=$(gcloud auth application-default print-access-token)
53+
current_account=$(curl -s https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=$access_token | node $full_script_path/get-email)
54+
if [[ ! $current_account =~ (angular\.io$)|(google\.com$) ]]; then
55+
echo "Logged in as $current_account";
56+
echo "An angular.io or google.com account must be used for remote Bazel usage."
57+
echo "Please login instead using an account from one of these domains."
58+
read -p "Rerun login command now? [Y/y]"
59+
if [[ $REPLY =~ ^[Yy]$ ]]; then
60+
gcloud_login
61+
confirm_gcloud_login
62+
return
63+
else
64+
echo "Exiting..."
65+
exit 3
66+
fi
67+
fi
68+
echo "Logged in as $current_account";
69+
}
4970

5071
# Prompts to add a flag to the .bazelrc.user file if its not already in place
5172
function add_flag() {
@@ -62,14 +83,23 @@ function add_flag() {
6283
echo
6384
}
6485

86+
###########################################################
87+
# RBE Setup Script #
88+
###########################################################
89+
# Create the bazelrc.user file, echo the config flags into the file.
90+
touch $bazelrc_user_filepath
91+
92+
# Ensure default credentials are valid.
93+
confirm_gcloud_login
94+
6595
# Add extra line space before config setup.
6696
echo
97+
# Remote builds
98+
echo "The ${bold}remote${normal} flag enables RBE, builds run remotely when possible and caching"
99+
echo "occurs in the RBE context"
100+
add_flag "build --config=remote"
101+
67102
# Remote HTTP Caching
68103
echo "The ${bold}remote-http-caching${normal} flag enables uploading build results to the http cache,"
69104
echo "but not does enable remote builds"
70105
add_flag "build --config=remote-http-caching"
71-
72-
# Remote builds
73-
echo "The ${bold}remote${normal} flag enables RBE, builds occurs remotely when possible and caching"
74-
echo "occurs in the RBE context"
75-
add_flag "build --config=remote"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL