Skip to content

Commit b00b977

Browse files
ianlancetaylorIan Lance Taylor
authored and
Ian Lance Taylor
committed
internal/coordinator/remote: set up enviroment for SSH clients
Fixes golang/go#32430 Change-Id: I84281077328c864fb3ba6f81e3a4453848ce741e Reviewed-on: https://go-review.googlesource.com/c/build/+/418104 Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Jenny Rakoczy <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 529c4e3 commit b00b977

File tree

1 file changed

+27
-0
lines changed
  • internal/coordinator/remote

1 file changed

+27
-0
lines changed

internal/coordinator/remote/ssh.go

+27
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func (ss *SSHServer) legacyIncomingSSHPostAuth(s gssh.Session, rb *Buildlet) {
332332
}
333333
}()
334334
go func() {
335+
ss.setupRemoteSSHEnv(bconf, workDir, f)
335336
io.Copy(f, s) // stdin
336337
}()
337338
io.Copy(s, f) // stdout
@@ -476,13 +477,39 @@ func (ss *SSHServer) IncomingSSHPostAuth(s gssh.Session, rs *Session) {
476477
}
477478
}()
478479
go func() {
480+
ss.setupRemoteSSHEnv(bconf, workDir, f)
479481
io.Copy(f, s) // stdin
480482
}()
481483
io.Copy(s, f) // stdout
482484
cmd.Process.Kill()
483485
cmd.Wait()
484486
}
485487

488+
// setupRemoteSSHEnv sets up environment variables on the remote system.
489+
// This makes the new SSH session easier to use for Go testing.
490+
func (ss *SSHServer) setupRemoteSSHEnv(bconf *dashboard.BuildConfig, workDir string, f io.Writer) {
491+
switch bconf.GOOS() {
492+
default:
493+
// A Unix system.
494+
for _, env := range bconf.Env() {
495+
fmt.Fprintln(f, env)
496+
}
497+
fmt.Fprintf(f, "GOPATH=%s/gopath\n", workDir)
498+
fmt.Fprintf(f, "PATH=$PATH:%s/go/bin\n", workDir)
499+
fmt.Fprintf(f, "export GOPATH PATH\n")
500+
fmt.Fprintf(f, "cd %s/go/src\n", workDir)
501+
case "windows":
502+
for _, env := range bconf.Env() {
503+
fmt.Fprintf(f, "set %s\n", env)
504+
}
505+
fmt.Fprintf(f, `set GOPATH=%s\gopath`+"\n", workDir)
506+
fmt.Fprintf(f, `set PATH=$PATH;%s\go\bin`+"\n", workDir)
507+
fmt.Fprintf(f, `cd %s\go\src`+"\n", workDir)
508+
case "plan9":
509+
// TODO
510+
}
511+
}
512+
486513
// WriteSSHPrivateKeyToTempFile writes a key to a temporary file on the local file system. It also
487514
// sets the permissions on the file to what is expected by OpenSSH implementations of SSH.
488515
func WriteSSHPrivateKeyToTempFile(key []byte) (path string, err error) {

0 commit comments

Comments
 (0)