-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dashboard/buildlet: add Makefiles, and add Windows stage0 bootstrap b…
…inary Change-Id: I69938af38fb5c45c01598e9171e851a1c29790bc Reviewed-on: https://go-review.googlesource.com/2268 Reviewed-by: Andrew Gerrand <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
buildlet | ||
buildlet.*-* | ||
stage0/buildlet-stage0.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
buildlet: buildlet.go | ||
go build --tags=buildlet | ||
|
||
buildlet.openbsd-amd64: buildlet.go | ||
GOOS=openbsd GOARCH=amd64 go build -o $@ --tags=buildlet | ||
cat $@ | (cd ../coordinator/buildongce && go run create.go --write_object=go-builder-data/$@) | ||
|
||
buildlet.plan9-386: buildlet.go | ||
GOOS=plan9 GOARCH=386 go build -o $@ --tags=buildlet | ||
cat $@ | (cd ../coordinator/buildongce && go run create.go --write_object=go-builder-data/$@) | ||
|
||
buildlet.windows-amd64: buildlet.go | ||
GOOS=windows GOARCH=amd64 go build -o $@ --tags=buildlet | ||
cat $@ | (cd ../coordinator/buildongce && go run create.go --write_object=go-builder-data/$@) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
buildlet-stage0.windows-amd64: stage0.go | ||
GOOS=windows GOARCH=amd64 go build -o $@ --tags=stage0 | ||
cat $@ | (cd ../../coordinator/buildongce && go run create.go --write_object=go-builder-data/$@) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2015 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build stage0 | ||
|
||
// The stage0 command looks up the buildlet's URL from the GCE metadata | ||
// service, downloads it, and runs it. It's used primarily by Windows, | ||
// since it can be written in a couple lines of shell elsewhere. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"time" | ||
|
||
"google.golang.org/cloud/compute/metadata" | ||
) | ||
|
||
const attr = "buildlet-binary-url" | ||
|
||
func main() { | ||
buildletURL, err := metadata.InstanceAttributeValue(attr) | ||
if err != nil { | ||
sleepFatalf("Failed to look up %q attribute value: %v", attr, err) | ||
} | ||
target := filepath.FromSlash("./buildlet.exe") | ||
if err := download(target, buildletURL); err != nil { | ||
sleepFatalf("Downloading %s: %v", buildletURL, err) | ||
} | ||
cmd := exec.Command(target) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
if err := cmd.Run(); err != nil { | ||
sleepFatalf("Error running buildlet: %v", err) | ||
} | ||
} | ||
|
||
func sleepFatalf(format string, args ...interface{}) { | ||
log.Printf(format, args...) | ||
time.Sleep(time.Minute) // so user has time to see it in cmd.exe, maybe | ||
os.Exit(1) | ||
} | ||
|
||
func download(file, url string) error { | ||
log.Printf("Downloading %s to %s ...\n", url, file) | ||
res, err := http.Get(url) | ||
if err != nil { | ||
return fmt.Errorf("Error fetching %v: %v", url, err) | ||
} | ||
if res.StatusCode != 200 { | ||
return fmt.Errorf("HTTP status code of %s was %v", url, res.Status) | ||
} | ||
tmp := file + ".tmp" | ||
os.Remove(tmp) | ||
os.Remove(file) | ||
f, err := os.Create(tmp) | ||
if err != nil { | ||
return err | ||
} | ||
n, err := io.Copy(f, res.Body) | ||
res.Body.Close() | ||
if err != nil { | ||
return fmt.Errorf("Error reading %v: %v", url, err) | ||
} | ||
f.Close() | ||
err = os.Rename(tmp, file) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("Downloaded %s (%d bytes)", file, n) | ||
return nil | ||
} |