| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fa0ab38 commit 418e9cf
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,8 +71,6 @@ test --test_output=errors | |||
| 71 | 71 | # any bazel target. This is a temporary flag until codebase is permanently switched to Ivy. | |
| 72 | 72 | build --define=compile=legacy | |
| 73 | 73 | ||
| 74 | - build --google_default_credentials | ||
| 75 | - | ||
| 76 | 74 | ####################### | |
| 77 | 75 | # Remote HTTP Caching # | |
| 78 | 76 | ####################### | |
@@ -86,6 +84,7 @@ build --remote_upload_local_results=false | |||
| 86 | 84 | # --config=-http-caching # | |
| 87 | 85 | ###################################### | |
| 88 | 86 | build:remote-http-caching --remote_upload_local_results=true | |
| 87 | + build:remote-http-caching --google_default_credentials | ||
| 89 | 88 | ||
| 90 | 89 | ################################## | |
| 91 | 90 | # Remote Build Execution support # | |
@@ -99,6 +98,7 @@ import %workspace%/third_party/github.com/bazelbuild/bazel-toolchains/bazelrc/.b | |||
| 99 | 98 | # Increase the default number of jobs by 50% because our build has lots of | |
| 100 | 99 | # parallelism | |
| 101 | 100 | build:remote --jobs=150 | |
| 101 | + build:remote --google_default_credentials | ||
| 102 | 102 | ||
| 103 | 103 | # Toolchain and platform related flags | |
| 104 | 104 | build:remote --host_javabase=@rbe_ubuntu1604_angular//java:jdk | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,12 +169,14 @@ It will automatically recognize `*.bazel` and `*.bzl` files. | |||
| 169 | 169 | ### Remote Build Execution and Remote Caching | |
| 170 | 170 | Bazel builds in the Angular repository use a shared http cache. When a build occurs a hash of the inputs is computed | |
| 171 | 171 | 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. | ||
| 173 | 175 | ||
| 174 | 176 | ### --config=remote-http-caching flag | |
| 175 | 177 | The `--config=remote-http-caching` flag can be added to enable uploading of build results to the shared http cache. This flag | |
| 176 | 178 | can be added to the `.bazelrc.user` file using the script at `scripts/local-dev/setup-rbe.sh`. | |
| 177 | 179 | ||
| 178 | 180 | ### --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 | ||
| 180 | 182 | the `.bazelrc.user` file using the script at `scripts/local-dev/setup-rbe.sh`. | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,15 @@ | |||
| 1 | 1 | #!/bin/bash | |
| 2 | 2 | # A script for automatically configuring a user's local dev | |
| 3 | 3 | # environment to use Remote Build Execution. | |
| 4 | - | ||
| 5 | 4 | # Short cuts to set output as bold and normal | |
| 6 | 5 | bold=$(tput bold) | |
| 7 | 6 | normal=$(tput sgr0) | |
| 8 | 7 | ||
| 8 | + ########################################################### | ||
| 9 | + # Setup/Confirm Environment # | ||
| 10 | + ########################################################### | ||
| 11 | + # The full path location of the script | ||
| 12 | + full_script_path="$(pwd)/$(dirname ${BASH_SOURCE[0]})" | ||
| 9 | 13 | # Determine the root directory of the Angular github repo. | |
| 10 | 14 | project_directory=$(git rev-parse --show-toplevel 2> /dev/null) | |
| 11 | 15 | if [[ $? -ne 0 ]]; then | |
@@ -20,32 +24,49 @@ if [ ! -x "$(command -v gcloud)" ]; then | |||
| 20 | 24 | exit 1 | |
| 21 | 25 | fi | |
| 22 | 26 | ||
| 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() { | ||
| 29 | 35 | gcloud auth application-default login | |
| 30 | 36 | if [[ $? -ne 0 ]]; then | |
| 31 | 37 | echo "gcloud login failed. Aborting" | |
| 32 | 38 | exit 2 | |
| 33 | 39 | 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 | + } | ||
| 44 | 41 | ||
| 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 | + } | ||
| 49 | 70 | ||
| 50 | 71 | # Prompts to add a flag to the .bazelrc.user file if its not already in place | |
| 51 | 72 | function add_flag() { | |
@@ -62,14 +83,23 @@ function add_flag() { | |||
| 62 | 83 | echo | |
| 63 | 84 | } | |
| 64 | 85 | ||
| 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 | + | ||
| 65 | 95 | # Add extra line space before config setup. | |
| 66 | 96 | 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 | + | ||
| 67 | 102 | # Remote HTTP Caching | |
| 68 | 103 | echo "The ${bold}remote-http-caching${normal} flag enables uploading build results to the http cache," | |
| 69 | 104 | echo "but not does enable remote builds" | |
| 70 | 105 | 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" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments