Skip to content

Commit

Permalink
chore(NA): use new and more performant BuildBuddy servers (#130350)
Browse files Browse the repository at this point in the history
* chore(NA): use new and more performant BuildBuddy servers

* chore(NA): simple upgrade mechanism for new remote address servers

* docs(NA): missing note for future removal

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
mistic and kibanamachine authored Apr 18, 2022
1 parent c1d6690 commit 48ca660
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
8 changes: 0 additions & 8 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
# Import shared settings first so we can override below
import %workspace%/.bazelrc.common

# Remote cache settings for local env
# build --remote_cache=grpcs://cloud.buildbuddy.io
# build --incompatible_remote_results_ignore_disk=true
# build --noremote_upload_local_results
# build --remote_timeout=30
# build --remote_header=x-buildbuddy-api-key=3EYk49W2NefOx2n3yMze
# build --remote_accept_cached=true

# Enable this in case you want to share your build info
# build --build_metadata=VISIBILITY=PUBLIC
build --build_metadata=TEST_GROUPS=//packages
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/scripts/common/setup_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if [[ "${BAZEL_CACHE_MODE:-none}" == read* ]]; then
echo "[bazel] enabling caching"
cat <<EOF >> $KIBANA_DIR/.bazelrc
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://cloud.buildbuddy.io
build --remote_cache=grpcs://cloud.buildbuddy.io
build --bes_backend=grpcs://remote.buildbuddy.io
build --remote_cache=grpcs://remote.buildbuddy.io
build --remote_timeout=3600
build --remote_header=x-buildbuddy-api-key=$KIBANA_BUILDBUDDY_CI_API_KEY
EOF
Expand Down
31 changes: 28 additions & 3 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55910,6 +55910,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _child_process__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(342);
/* harmony import */ var _log__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(341);
/* harmony import */ var _fs__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(352);
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
Expand All @@ -55923,6 +55924,7 @@ __webpack_require__.r(__webpack_exports__);




async function isVaultAvailable() {
try {
await Object(_child_process__WEBPACK_IMPORTED_MODULE_3__["spawn"])('vault', ['--version'], {
Expand All @@ -55947,14 +55949,37 @@ async function isElasticCommitter() {
}
}

async function migrateToNewServersIfNeeded(settingsPath) {
if (!(await Object(_fs__WEBPACK_IMPORTED_MODULE_5__["isFile"])(settingsPath))) {
return false;
}

const readSettingsFile = await Object(_fs__WEBPACK_IMPORTED_MODULE_5__["readFile"])(settingsPath, 'utf8');
const newReadSettingsFile = readSettingsFile.replace(/cloud\.buildbuddy\.io/g, 'remote.buildbuddy.io');

if (newReadSettingsFile === readSettingsFile) {
return false;
}

Object(_fs__WEBPACK_IMPORTED_MODULE_5__["writeFile"])(settingsPath, newReadSettingsFile);
_log__WEBPACK_IMPORTED_MODULE_4__["log"].info(`[bazel_tools] upgrade remote cache settings to use new server address`);
return true;
}

async function setupRemoteCache(repoRootPath) {
// The remote cache is only for Elastic employees working locally (CI cache settings are handled elsewhere)
if (process.env.CI || !(await isElasticCommitter())) {
return;
}

_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] setting up remote cache settings if necessary`);
const settingsPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(repoRootPath, '.bazelrc.cache');
const settingsPath = Object(path__WEBPACK_IMPORTED_MODULE_2__["resolve"])(repoRootPath, '.bazelrc.cache'); // Checks if we should upgrade the servers used on .bazelrc.cache
//
// NOTE: this can be removed in the future once everyone is migrated into the new servers

if (await migrateToNewServersIfNeeded(settingsPath)) {
return;
}

if (Object(fs__WEBPACK_IMPORTED_MODULE_1__["existsSync"])(settingsPath)) {
_log__WEBPACK_IMPORTED_MODULE_4__["log"].debug(`[bazel_tools] remote cache settings already exist, skipping`);
Expand Down Expand Up @@ -55990,8 +56015,8 @@ async function setupRemoteCache(repoRootPath) {
# V1 - This file is automatically generated by 'yarn kbn bootstrap'
# To regenerate this file, delete it and run 'yarn kbn bootstrap' again.
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://cloud.buildbuddy.io
build --remote_cache=grpcs://cloud.buildbuddy.io
build --bes_backend=grpcs://remote.buildbuddy.io
build --remote_cache=grpcs://remote.buildbuddy.io
build --remote_timeout=3600
build --remote_header=${apiKey}
`;
Expand Down
32 changes: 30 additions & 2 deletions packages/kbn-pm/src/utils/bazel/setup_remote_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { existsSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { spawn } from '../child_process';
import { log } from '../log';
import { isFile, readFile, writeFile } from '../fs';

async function isVaultAvailable() {
try {
Expand All @@ -33,6 +34,26 @@ async function isElasticCommitter() {
}
}

async function migrateToNewServersIfNeeded(settingsPath: string) {
if (!(await isFile(settingsPath))) {
return false;
}

const readSettingsFile = await readFile(settingsPath, 'utf8');
const newReadSettingsFile = readSettingsFile.replace(
/cloud\.buildbuddy\.io/g,
'remote.buildbuddy.io'
);

if (newReadSettingsFile === readSettingsFile) {
return false;
}

writeFile(settingsPath, newReadSettingsFile);
log.info(`[bazel_tools] upgrade remote cache settings to use new server address`);
return true;
}

export async function setupRemoteCache(repoRootPath: string) {
// The remote cache is only for Elastic employees working locally (CI cache settings are handled elsewhere)
if (process.env.CI || !(await isElasticCommitter())) {
Expand All @@ -43,6 +64,13 @@ export async function setupRemoteCache(repoRootPath: string) {

const settingsPath = resolve(repoRootPath, '.bazelrc.cache');

// Checks if we should upgrade the servers used on .bazelrc.cache
//
// NOTE: this can be removed in the future once everyone is migrated into the new servers
if (await migrateToNewServersIfNeeded(settingsPath)) {
return;
}

if (existsSync(settingsPath)) {
log.debug(`[bazel_tools] remote cache settings already exist, skipping`);
return;
Expand Down Expand Up @@ -82,8 +110,8 @@ export async function setupRemoteCache(repoRootPath: string) {
# V1 - This file is automatically generated by 'yarn kbn bootstrap'
# To regenerate this file, delete it and run 'yarn kbn bootstrap' again.
build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://cloud.buildbuddy.io
build --remote_cache=grpcs://cloud.buildbuddy.io
build --bes_backend=grpcs://remote.buildbuddy.io
build --remote_cache=grpcs://remote.buildbuddy.io
build --remote_timeout=3600
build --remote_header=${apiKey}
`;
Expand Down

0 comments on commit 48ca660

Please sign in to comment.