buildenv, cmd/coordinator: make DashBase a property of the Environment

Change-Id: I6621cfaf12541f9910255048edd49301a1b2deba
Reviewed-on: https://go-review.googlesource.com/29398
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/buildenv/envs.go b/buildenv/envs.go
index 5154b2a..ff6e4bf 100644
--- a/buildenv/envs.go
+++ b/buildenv/envs.go
@@ -67,6 +67,9 @@
 	// will be set to a random value at runtime.
 	KubePassword string
 
+	// DashURL is the base URL of the build dashboard, ending in a slash.
+	DashURL string
+
 	// CoordinatorURL is the location from which the coordinator
 	// binary will be downloaded.
 	// This is only used by cmd/coordinator/buildongce/create.go when
@@ -109,6 +112,15 @@
 	return e.Zone[:strings.LastIndex(e.Zone, "-")]
 }
 
+// DashBase returns the base URL of the build dashboard, ending in a slash.
+func (e Environment) DashBase() string {
+	// TODO(quentin): Should we really default to production? That's what the old code did.
+	if e.DashURL != "" {
+		return e.DashURL
+	}
+	return Production.DashURL
+}
+
 // ByProjectID returns an Environment for the specified
 // project ID. It is currently limited to the symbolic-datum-552
 // and go-dashboard-dev projects.
@@ -144,6 +156,7 @@
 	KubeMaxNodes:    2,
 	KubeName:        "buildlets",
 	KubeMachineType: "n1-standard-32",
+	DashURL:         "https://go-dashboard-dev.appspot.com/",
 	CoordinatorURL:  "https://storage.googleapis.com/dev-go-builder-data/coordinator",
 	CoordinatorName: "farmer",
 	BuildletBucket:  "dev-go-builder-data",
@@ -164,6 +177,7 @@
 	KubeMaxNodes:    5,
 	KubeName:        "buildlets",
 	KubeMachineType: "n1-standard-32",
+	DashURL:         "https://build.golang.org/",
 	CoordinatorURL:  "https://storage.googleapis.com/go-builder-data/coordinator",
 	CoordinatorName: "farmer",
 	BuildletBucket:  "go-builder-data",
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index 088ad9e..8900c52 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -663,7 +663,7 @@
 
 func findWork(work chan<- builderRev) error {
 	var bs types.BuildStatus
-	res, err := http.Get(dashBase() + "?mode=json")
+	res, err := http.Get(buildEnv.DashBase() + "?mode=json")
 	if err != nil {
 		return err
 	}
diff --git a/cmd/coordinator/dash.go b/cmd/coordinator/dash.go
index 18366ce..cdbe33b 100644
--- a/cmd/coordinator/dash.go
+++ b/cmd/coordinator/dash.go
@@ -25,17 +25,6 @@
 	"cloud.google.com/go/compute/metadata"
 )
 
-// dashBase returns the base URL of the build dashboard.
-// It must be called after initGCE (so not at init time).
-func dashBase() string {
-	// TODO(bradfitz,evanbrown): use buildenv instead of global variable.
-	// In fact, kill the inStaging variable altogether.
-	if inStaging {
-		return "https://go-dashboard-dev.appspot.com/"
-	}
-	return "https://build.golang.org/"
-}
-
 // dash is copied from the builder binary. It runs the given method and command on the dashboard.
 //
 // TODO(bradfitz,adg): unify this somewhere?
@@ -55,7 +44,7 @@
 	}
 	var r *http.Response
 	var err error
-	cmd = dashBase() + cmd + "?" + argsCopy.Encode()
+	cmd = buildEnv.DashBase() + cmd + "?" + argsCopy.Encode()
 	switch meth {
 	case "GET":
 		if req != nil {
@@ -157,7 +146,7 @@
 		args.Set("hash", st.subRev)
 		args.Set("gohash", st.rev)
 	}
-	u := dashBase() + "building?" + args.Encode()
+	u := buildEnv.DashBase() + "building?" + args.Encode()
 	for {
 		st.mu.Lock()
 		done := st.done
diff --git a/cmd/coordinator/watcher.go b/cmd/coordinator/watcher.go
index 72acdf8..ca6f1fe 100644
--- a/cmd/coordinator/watcher.go
+++ b/cmd/coordinator/watcher.go
@@ -66,7 +66,7 @@
 	}
 	addWatcher(watchConfig{
 		repo:     "https://go.googlesource.com/go",
-		dash:     dashBase(),
+		dash:     buildEnv.DashBase(),
 		mirror:   mirror,
 		netHost:  true,
 		httpAddr: gitArchiveAddr,
@@ -74,7 +74,7 @@
 	if false {
 		// TODO(cmang,adg): only use one watcher or the other, depending on which build
 		// coordinator is in use.
-		addWatcher(watchConfig{repo: "https://go.googlesource.com/gofrontend", dash: dashBase() + "gccgo/"})
+		addWatcher(watchConfig{repo: "https://go.googlesource.com/gofrontend", dash: buildEnv.DashBase() + "gccgo/"})
 	}
 
 	stopWatchers() // clean up before we start new ones