Skip to content

Commit 8af161d

Browse files
committed
bazel: enable remote build on mesolite from linux
We are merging EngFlow clusters. This transitions to using the mesolite cluster for running remote builds from gceworkers. Part of: DEVINF-1489 Release note: None
1 parent 1e2f0e2 commit 8af161d

File tree

4 files changed

+71
-21
lines changed

4 files changed

+71
-21
lines changed

.bazelrc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,16 @@ build:engflowbase --remote_upload_local_results=false
147147
build:engflowbase --remote_download_toplevel
148148
build:engflowbase --test_env=GO_TEST_WRAP_TESTV=1
149149
build:engflowbase --config=lintonbuild
150+
build:engflowbase --remote_cache=grpcs://mesolite.cluster.engflow.com
151+
build:engflowbase --remote_executor=grpcs://mesolite.cluster.engflow.com
152+
build:engflowbase --bes_backend=grpcs://mesolite.cluster.engflow.com
150153
test:engflowbase --test_env=REMOTE_EXEC=1
151154
test:engflowbase --test_env=GOTRACEBACK=all
152155
build:engflow --config=engflowbase
153-
build:engflow --remote_cache=grpcs://tanzanite.cluster.engflow.com
154-
build:engflow --remote_executor=grpcs://tanzanite.cluster.engflow.com
155-
build:engflow --bes_backend=grpcs://tanzanite.cluster.engflow.com
156-
build:engflow --bes_results_url=https://tanzanite.cluster.engflow.com/invocation/
156+
build:engflow --bes_results_url=https://mesolite.cluster.engflow.com/invocations/private
157+
build:engflow --remote_instance_name=private
158+
build:engflow --bes_instance_name=private
157159
build:engflowpublic --config=engflowbase
158-
build:engflowpublic --remote_cache=grpcs://mesolite.cluster.engflow.com
159-
build:engflowpublic --remote_executor=grpcs://mesolite.cluster.engflow.com
160-
build:engflowpublic --bes_backend=grpcs://mesolite.cluster.engflow.com
161160
build:engflowpublic --bes_results_url=https://mesolite.cluster.engflow.com/invocation/
162161

163162
try-import %workspace%/.bazelrc.user

dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88
set -euo pipefail
99

1010
# Bump this counter to force rebuilding `dev` on all machines.
11-
DEV_VERSION=112
11+
DEV_VERSION=113
1212

1313
THIS_DIR=$(cd "$(dirname "$0")" && pwd)
1414
BINARY_DIR=$THIS_DIR/bin/dev-versions

pkg/cmd/dev/doctor.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// doctorStatusVersion is the current "version" of the status checks
3131
// performed by `dev doctor``. Increasing it will force doctor to be re-run
3232
// before other dev commands can be run.
33-
doctorStatusVersion = 11
33+
doctorStatusVersion = 12
3434

3535
noCacheFlag = "no-cache"
3636
interactiveFlag = "interactive"
@@ -276,8 +276,15 @@ Make sure one of the following lines is in the file %s/.bazelrc.user:
276276
if d.checkUsingConfig(cfg.workspace, "dev") {
277277
return "In --remote mode, you cannot use the `dev` build configuration."
278278
}
279-
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --jobs=200") {
280-
return fmt.Sprintf("Make sure the following line is in %s/.bazelrc.user: build:engflow --jobs=200", cfg.workspace)
279+
requiredLines := []string{
280+
"build:engflow --jobs=200",
281+
"build:engflow --credential_helper=mesolite.cluster.engflow.com=engflow_auth",
282+
"build:engflow --remote_execution_priority=-1",
283+
}
284+
for _, line := range requiredLines {
285+
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, line) {
286+
return fmt.Sprintf("Make sure the following line is in %s/.bazelrc.user: %s", cfg.workspace, line)
287+
}
281288
}
282289
return ""
283290
},
@@ -304,13 +311,19 @@ Make sure one of the following lines is in the file %s/.bazelrc.user:
304311
return err
305312
}
306313
}
307-
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --jobs=200") {
308-
err := d.addLineToBazelRcUser(cfg.workspace, "build:engflow --jobs=200")
309-
if err != nil {
310-
return err
314+
requiredLines := []string{
315+
"build:engflow --jobs=200",
316+
"build:engflow --credential_helper=mesolite.cluster.engflow.com=engflow_auth",
317+
"build:engflow --remote_execution_priority=-1",
318+
}
319+
for _, line := range requiredLines {
320+
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, line) {
321+
err := d.addLineToBazelRcUser(cfg.workspace, line)
322+
if err != nil {
323+
return err
324+
}
311325
}
312326
}
313-
314327
return nil
315328
},
316329
remoteOnly: true,
@@ -359,13 +372,16 @@ slightly slower and introduce a noticeable delay in first-time build setup.`
359372
},
360373
},
361374
{
362-
name: "engflow_certificates",
375+
name: "engflow_auth",
363376
check: func(d *dev, ctx context.Context, cfg doctorConfig) string {
364-
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --tls_client_certificate=") {
365-
return fmt.Sprintf("Must specify the --tls_client_certificate to use for EngFlow builds in %s/.bazelrc.user. This is a line of the form: `build:engflow --tls_client_certificate=/path/to/file`.", cfg.workspace)
377+
if !d.checkFileExistsUnderHomedir(".config/engflow_auth/tokens/mesolite.cluster.engflow.com") {
378+
return "Make sure you've installed engflow_auth (https://github.com/EngFlow/auth), added it to your PATH, and login using `engflow_auth login -store=file https://mesolite.cluster.engflow.com`."
379+
}
380+
if d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --tls_client_certificate=") {
381+
return fmt.Sprintf("Please remove the --tls_client_certificate line from %s/.bazelrc.user. It is no longer necessary when using engflow_auth.", cfg.workspace)
366382
}
367-
if !d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --tls_client_key=") {
368-
return fmt.Sprintf("Must specify the --tls_client_key to use for EngFlow builds in %s/.bazelrc.user. This is a line of the form: `build:engflow --tls_client_key=/path/to/file`.", cfg.workspace)
383+
if d.checkLinePresenceInBazelRcUser(cfg.workspace, "build:engflow --tls_client_key=") {
384+
return fmt.Sprintf("Please remove the --tls_client_key line from %s/.bazelrc.user. It is no longer necessary when using engflow_auth.", cfg.workspace)
369385
}
370386
return ""
371387
},
@@ -924,3 +940,18 @@ func (d *dev) removeAllPrefixesInFile(filename, prefixToRemove string) error {
924940
outStr = strings.TrimSpace(outStr) + "\n"
925941
return d.os.WriteFile(filename, outStr)
926942
}
943+
944+
// checkFileExistsUnderHomedir checks whether the given file or path is present
945+
// under the home directory. If it is, this function returns true. Otherwise,
946+
// it returns false.
947+
func (d *dev) checkFileExistsUnderHomedir(expectedFile string) bool {
948+
homeDir, err := os.UserHomeDir()
949+
if err != nil {
950+
return false
951+
}
952+
exists, err := d.os.Exists(filepath.Join(homeDir, expectedFile))
953+
if err != nil {
954+
return false
955+
}
956+
return exists
957+
}

pkg/cmd/dev/io/os/os.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,26 @@ func (o *OS) IsDir(dirname string) (bool, error) {
296296
return strconv.ParseBool(strings.TrimSpace(output))
297297
}
298298

299+
// Exists wraps around os.Stat, which returns the os.FileInfo of the named
300+
// path. Exists returns true if and only if it exists. If there is an error,
301+
// it will return false and the error.
302+
func (o *OS) Exists(filename string) (bool, error) {
303+
command := fmt.Sprintf("cat %s", filename)
304+
if !o.knobs.silent {
305+
o.logger.Print(command)
306+
}
307+
308+
output, _ := o.Next(command, func() (output string, err error) {
309+
_, err = os.Stat(filename)
310+
exists := !errors.Is(err, fs.ErrNotExist)
311+
if exists && err != nil {
312+
return "false", err
313+
}
314+
return strconv.FormatBool(exists), nil
315+
})
316+
return strconv.ParseBool(strings.TrimSpace(output))
317+
}
318+
299319
// ReadFile wraps around os.ReadFile, reading a file from disk and
300320
// returning the contents.
301321
func (o *OS) ReadFile(filename string) (string, error) {

0 commit comments

Comments
 (0)