cmd/buildlet: use tmpfs workdir if flag value is unspecified

Fixes golang/go#21839
Updates golang/go#22592

Change-Id: Ia96236c61847193f930564b4dd5e0d7965e89945
Reviewed-on: https://go-review.googlesource.com/77370
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Brad Fitzpatrick 2017-11-13 21:01:33 +00:00
Родитель eca02d2d17
Коммит 3da79c29d0
1 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@ -152,6 +152,9 @@ func main() {
if onGCE {
fixMTU()
}
if *workDir == "" && runtime.GOOS == "linux" {
setLinuxWorkdirToTmpfs()
}
if *workDir == "" {
switch runtime.GOOS {
case "windows":
@ -1666,3 +1669,16 @@ func appendSSHAuthorizedKey(sshUser, authKey string) error {
}
return nil
}
// setLinuxWorkdirToTmpfs sets the *workDir (--workdir) flag to /workdir
// if the flag is empty and /workdir is a tmpfs mount, as it is on the various
// hosts that use rundockerbuildlet.
func setLinuxWorkdirToTmpfs() {
if *workDir != "" {
return
}
mounts, _ := ioutil.ReadFile("/proc/mounts")
if bytes.Contains(mounts, []byte("\ntmpfs /workdir tmpfs ")) {
*workDir = "/workdir"
}
}