cmd/buildlet: download 1.4 bootstrap on SmartOS

Change-Id: Iafd9613ff09f9fbf0d3c715d2af87a55ac29d3ed
Reviewed-on: https://go-review.googlesource.com/22723
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ross Light 2016-05-03 11:23:15 -07:00 коммит произвёл Brad Fitzpatrick
Родитель cdc3b85f4c
Коммит 9649a7682c
1 изменённых файлов: 33 добавлений и 0 удалений

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

@ -39,6 +39,7 @@ import (
"golang.org/x/build/buildlet"
"golang.org/x/build/envutil"
"golang.org/x/build/internal/httpdl"
"golang.org/x/build/pargzip"
"google.golang.org/cloud/compute/metadata"
)
@ -137,6 +138,9 @@ func main() {
if _, err := os.Lstat(*workDir); err != nil {
log.Fatalf("invalid --workdir %q: %v", *workDir, err)
}
if runtime.GOOS == "solaris" && runtime.GOARCH == "amd64" {
downloadBootstrapGoroot("/root/go-solaris-amd64-bootstrap", "https://storage.googleapis.com/go-builder-data/gobootstrap-solaris-amd64.tar.gz")
}
http.HandleFunc("/", handleRoot)
http.HandleFunc("/debug/goroutines", handleGoroutines)
http.HandleFunc("/debug/x", handleX)
@ -165,6 +169,35 @@ func main() {
}
}
func downloadBootstrapGoroot(destDir, url string) {
tarPath := destDir + ".tar.gz"
origInfo, err := os.Stat(tarPath)
if err != nil && !os.IsNotExist(err) {
log.Fatalf("Checking for tar existence: %v", err)
}
if err := httpdl.Download(tarPath, url); err != nil {
log.Fatalf("Downloading %s to %s: %v", url, tarPath, err)
}
newInfo, err := os.Stat(tarPath)
if err != nil {
log.Fatalf("Stat after download: %v", err)
}
if os.SameFile(origInfo, newInfo) {
// The file on disk was unmodified, so we probably untarred it already.
return
}
f, err := os.Open(tarPath)
if err != nil {
log.Fatalf("Opening after download: %v", err)
}
defer f.Close()
if err := untar(f, destDir); err != nil {
os.Remove(tarPath)
os.RemoveAll(destDir)
log.Fatalf("Untarring %s: %v", url, err)
}
}
func listenForCoordinator() {
tlsCert, tlsKey := metadataValue("tls-cert"), metadataValue("tls-key")
if (tlsCert == "") != (tlsKey == "") {