From bdeaca482405113271bb20c9f36e55aab651691c Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 23 Sep 2022 16:18:49 +0000 Subject: [PATCH 1/2] feat(circleci-orb): command for setting up remote bazel execution --- .circleci/gcp_token | Bin 2352 -> 0 bytes circleci-orb/BUILD.bazel | 3 +- .../commands/setup-bazel-remote-exec.yml | 24 +++++++++ .../setup-bazel-remote-exec/BUILD.bazel | 47 ++++++++++++++++++ .../setup-bazel-remote-exec/constants.ts | 12 +++++ .../setup-bazel-remote-exec/encrypt.ts | 20 ++++++++ .../setup-bazel-remote-exec/gcp_token.data | Bin 0 -> 2331 bytes .../scripts/setup-bazel-remote-exec/index.ts | 40 +++++++++++++++ 8 files changed, 145 insertions(+), 1 deletion(-) delete mode 100644 .circleci/gcp_token create mode 100755 circleci-orb/commands/setup-bazel-remote-exec.yml create mode 100644 circleci-orb/scripts/setup-bazel-remote-exec/BUILD.bazel create mode 100644 circleci-orb/scripts/setup-bazel-remote-exec/constants.ts create mode 100644 circleci-orb/scripts/setup-bazel-remote-exec/encrypt.ts create mode 100644 circleci-orb/scripts/setup-bazel-remote-exec/gcp_token.data create mode 100644 circleci-orb/scripts/setup-bazel-remote-exec/index.ts diff --git a/.circleci/gcp_token b/.circleci/gcp_token deleted file mode 100644 index 74e0513d8637ebf7d0d6a6eaf2527c94c1bf3647..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2352 zcmV-03D5RZVQh3|WM5xK`&pBto30EKx3T|cd@+|w?aC@8)8cTCYVvIQ4|Ha0a)@Jg zW-ilCxvbY&+yDXLyD(YL2_<;Sr9^RwvUA7GEUipVfuN7o!5yEBI!Wy=bwrtnffNVt z$y%Lc)6%-42GaY?nj&b#m zHFPVasTNV0TkO{OL{0hHpg*$jLlx=$oKgM~qW=C{gAz*^`2iOa*Le8`Mlq>^2>tlw zd#rC&U~1#V6E`Q=^uShVY~50|R({Z0OnVl3?-i(bbky)h@m7C)9hi2Txrr)9eJ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_o&PbojeJUZLaGOpV)tl- zKqy7M-jvGo+CaimSOO=(*KT}`rR_$r9}<1p#%LmVVBIsG@g}d|1_^A1@;W@nTEhlNy9NOHsl{1J? zFVFqBG>lsSnV3sn5EY;*9Ti>M^e5`tLqve!6ME?!}jM% z(I6u+Hma0~vTIVGD}lMnB3i`|P>3zSeM8YSryZfM_GEU1%J#QLf6Xp;s8>j{t6W67!>j7?I_CmU_>p6wP&Z6{50z18^G9=HzdZCyf*JR#pZ)O||~Wa!X$dJMSgJS5v?L)_xi#)X&R?&rWE;Xhz*vouluZb_T)S z2Fynn)Y*DZ{&|N6S|Hlgkk7+ld^kpf4I_wIFw3engW2-g-V)k>dvx*@#zK1Iy*?cD zQ7o(#ZUAZ8v2#W_;9;SO>wM^4LtCvTq%oUdirv3VIF;-g^M5GCse9}Wv2C%A{9(m# zkD!29{~RFUc!u)}J?;qTASkO{v6sP!Szl^BDG9~IKB4I&ehRh#@Cb0`&QRP?@X000 z@Sk@}^pK7WvfYG5DxTSq@p!oG1 zLv#1!uWDE{TFw#DQ|YQ6)l8@^N?Zy diff --git a/circleci-orb/BUILD.bazel b/circleci-orb/BUILD.bazel index 5cb6a39fe..87b8a4c8a 100644 --- a/circleci-orb/BUILD.bazel +++ b/circleci-orb/BUILD.bazel @@ -2,7 +2,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") ORB_NAME = "angular/dev-infra" -ORB_VERSION = "1.0.2" +ORB_VERSION = "1.0.5" nodejs_binary( name = "pack_orb_script", @@ -17,6 +17,7 @@ filegroup( name = "orb_generated_files", srcs = [ "//circleci-orb/scripts/rebase-pr-on-target-branch:script", + "//circleci-orb/scripts/setup-bazel-remote-exec:script", ], ) diff --git a/circleci-orb/commands/setup-bazel-remote-exec.yml b/circleci-orb/commands/setup-bazel-remote-exec.yml new file mode 100755 index 000000000..b9fa7cb6e --- /dev/null +++ b/circleci-orb/commands/setup-bazel-remote-exec.yml @@ -0,0 +1,24 @@ +description: Setup Bazel remote execution + +parameters: + bazelrc: + type: string + default: '' + description: | + If specified, the given `bazelrc` file is being updated to always run + with the `--config=remote` flag. + shell: + type: string + default: '' + description: | + Shell to use for executing the command. Useful for Windows where a + non-bash shell is the default. + +steps: + - run: + environment: + BAZELRC_PATH: << parameters.bazelrc >> + NGAT: 'HlA2BJMJAXPDI1UAn5gytw==' + name: Setting up Bazel remote execution + shell: << parameters.shell >> + command: << include(../dist/bin/circleci-orb/scripts/setup-bazel-remote-exec/script.sh) >> diff --git a/circleci-orb/scripts/setup-bazel-remote-exec/BUILD.bazel b/circleci-orb/scripts/setup-bazel-remote-exec/BUILD.bazel new file mode 100644 index 000000000..97dbe9550 --- /dev/null +++ b/circleci-orb/scripts/setup-bazel-remote-exec/BUILD.bazel @@ -0,0 +1,47 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "nodejs_binary") +load("//tools:defaults.bzl", "esbuild", "ts_library") +load("//circleci-orb:index.bzl", "nodejs_script_to_sh_script") + +package(default_visibility = ["//circleci-orb:__subpackages__"]) + +copy_to_bin( + name = "gcp_token", + srcs = ["gcp_token.data"], +) + +ts_library( + name = "setup-bazel-remote-exec", + srcs = glob(["*.ts"]), + # TODO(devversion): Remove this when `ts_library` supports `.mts` extension. + devmode_module = "commonjs", + deps = [ + "@npm//@types/node", + ], +) + +nodejs_binary( + name = "encrypt", + data = [":setup-bazel-remote-exec"], + entry_point = ":encrypt.ts", +) + +esbuild( + name = "bundle", + srcs = [":gcp_token"], + args = { + "loader": { + ".data": "binary", + }, + }, + entry_point = "index.ts", + format = "iife", + minify = True, + sourcemap = "", + deps = [":setup-bazel-remote-exec"], +) + +nodejs_script_to_sh_script( + name = "script", + bundle_file = ":bundle.js", + output_file = "script.sh", +) diff --git a/circleci-orb/scripts/setup-bazel-remote-exec/constants.ts b/circleci-orb/scripts/setup-bazel-remote-exec/constants.ts new file mode 100644 index 000000000..01a56d96a --- /dev/null +++ b/circleci-orb/scripts/setup-bazel-remote-exec/constants.ts @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export const alg = 'aes-256-gcm'; +export const at = process.env.NGAT!; +export const k = process.env.CIRCLE_PROJECT_USERNAME!.padEnd(32, '<'); +export const iv = '000003213213123213'; diff --git a/circleci-orb/scripts/setup-bazel-remote-exec/encrypt.ts b/circleci-orb/scripts/setup-bazel-remote-exec/encrypt.ts new file mode 100644 index 000000000..bc04d3aa8 --- /dev/null +++ b/circleci-orb/scripts/setup-bazel-remote-exec/encrypt.ts @@ -0,0 +1,20 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {createCipheriv} from 'crypto'; +import {k, iv, alg} from './constants'; +import fs from 'fs'; + +const [inputPath, outputPath] = process.argv.slice(2); +const input = fs.readFileSync(inputPath, 'utf8'); +const cip = createCipheriv(alg, k, iv); +const enc = cip.update(input, 'utf8', 'binary') + cip.final('binary'); + +fs.writeFileSync(outputPath, enc, 'binary'); + +console.info('Auth tag:', cip.getAuthTag().toString('base64')); diff --git a/circleci-orb/scripts/setup-bazel-remote-exec/gcp_token.data b/circleci-orb/scripts/setup-bazel-remote-exec/gcp_token.data new file mode 100644 index 0000000000000000000000000000000000000000..d90cfa96d40ad0fc92eab98a57e514634077d607 GIT binary patch literal 2331 zcmV+$3FP)OjR)wxU>|_URlqLtV)Vc(Z(d8u0_q^s!+!LDhR@dzi3#Z1juwQi4B6>2Ztf3I_F-@%8Wr^fa zaZ`-BF7z|KU){_bJ6aA`vpz?cuas6m$IeNq3#ajcOZ@D`CiBpkUB_5a78p77O+YlZ()69 z7f2U#=L2BSL3;#5r?K2bca<;gl9Wxxi0oAP!F5Sz$unw`%~z|fRFE6n>bFi$41gprA6Oq)l-!N_>`;dt29?wk{YnOD-xTzTS2Cs-XTk#|FnJ~rG zMgNJt09ZkygG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-8r8U z;>;kU$ZEu{hS(9?gJgk$g^-yxRWQsvLHO)ePoZ&OyhmLs*mS*|YO15)zU@*H2#UXR zfw)rxPp)3o0F3GyBb?U1!KHtTmjV{ezoJ58Uu$rpMf0dW93QkZKPZy3qid|A?3789 zonK0YHEvv0Q_egaP=|NvtJ7s2kz879V3Th6plj1gZ~8A4T1`{O_3lO86hzu{&3u6i zg1_>|nGT=VXbi*`ks~Yi)*|>#Y>8*MCxf;0nEOgo9sr9b-0%%?a$z~uZVj^njX$R* z(^uIw_zP6L=YIO*Mr6JAQE8_$W~28F%Lhor*0IHaa#g`H!T@! zbawc#E@rb0yI~X3W(?H(#V);xz{E{0Yf`qJndR;d$V$HpJu0nxcEZdXz@c{A64H_}N(hWL&CX(P#VA$fC|`yS6*7h;24ck$Y{OW(RAki9(B{ZWD2!`M7Wb4~zH Bmbw4{ literal 0 HcmV?d00001 diff --git a/circleci-orb/scripts/setup-bazel-remote-exec/index.ts b/circleci-orb/scripts/setup-bazel-remote-exec/index.ts new file mode 100644 index 000000000..5653fc51e --- /dev/null +++ b/circleci-orb/scripts/setup-bazel-remote-exec/index.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +// @ts-ignore +import tokenRaw from './gcp_token.data'; +import {k, iv, alg, at} from './constants'; +import {createDecipheriv} from 'crypto'; +import path from 'path'; +import fs from 'fs'; +import os from 'os'; + +async function main(bazelRcPath: string | undefined) { + const t: Uint8Array = tokenRaw; + const dcip = createDecipheriv(alg, k, iv).setAuthTag(Buffer.from(at, 'base64')); + const dec = dcip.update(t, undefined, 'utf8') + dcip.final('utf8'); + + const destPath = + os.platform() === 'win32' + ? path.join(process.env.APPDATA!, 'gcloud/application_default_credentials.json') + : path.join(process.env.HOME!, '.config/gcloud/application_default_credentials.json'); + + await fs.promises.mkdir(path.dirname(destPath), {recursive: true}); + await fs.promises.writeFile(destPath, dec, 'utf8'); + + if (bazelRcPath) { + let content = await fs.promises.readFile(bazelRcPath, 'utf8'); + content += '\nbuild --config=remote'; + await fs.promises.writeFile(bazelRcPath, 'utf8'); + } +} + +main(process.env.BAZELRC_PATH).catch((e) => { + console.error(e); + process.exitCode = 1; +}); From c8699d4cb4a0d84cf17ec45c0ebd92bdca573ff2 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 23 Sep 2022 16:21:57 +0000 Subject: [PATCH 2/2] build: use remote execution setup command from orb --- .circleci/config.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 927f1eeb9..99f4454d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,7 @@ version: 2.1 orbs: buildalert: oss-tools/buildalert@0.1.0 win: circleci/windows@2.2.0 - devinfra: angular/dev-infra@1.0.1 + devinfra: angular/dev-infra@1.0.5 # **Note**: When updating the beginning of the cache key, also update the cache key to match # the new cache key prefix. This allows us to take advantage of CircleCI's fallback caching. @@ -16,8 +16,6 @@ var_1: &cache_key v2-{{arch}}-{{ checksum ".bazelversion" }}-{{ checksum "WORKSP # versions and ultimately cause the cache restoring to be slower. var_2: &cache_fallback_key v2-{{arch}}-{{ checksum ".bazelversion" }}- -var_3: &gcp_decrypt_token 'angular' - var_4: &restore_cache restore_cache: keys: @@ -37,8 +35,6 @@ var_6: &default_executor_settings resource_class: type: string default: medium - environment: - GCP_DECRYPT_TOKEN: *gcp_decrypt_token resource_class: << parameters.resource_class >> working_directory: ~/ng @@ -84,7 +80,7 @@ commands: description: 'Setting up Bazel configuration for CI' steps: - run: echo "import %workspace%/.circleci/linux-bazel.rc" >> ./.bazelrc - - run: ./.circleci/setup-bazel.sh + - devinfra/setup-bazel-remote-exec prepare_and_store_test_results: description: 'Prepare and upload test results'