Skip to content

Commit 7f9d076

Browse files
kevinburkebradfitz
authored andcommitted
cmd/coordinator: fix local development environment
Previously the server would fail to start if a valid token could not be found. The local development environment still doesn't do much, but it should let you view and edit the HTML and confirm that the server starts, so ignore the error if we are running in dev mode. Add a short README explaining how to start and view the coordinator server locally. Fixes golang/go#19828. Fixes golang/go#18291. Change-Id: I91a3ce49e1e9ea18ca19f3867edb2c71fc1b5124 Reviewed-on: https://go-review.googlesource.com/39297 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent c8b3ea8 commit 7f9d076

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

cmd/coordinator/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Coordinator
2+
3+
## Running locally
4+
5+
Run
6+
7+
go install golang.org/x/build/cmd/coordinator && coordinator --mode=dev
8+
9+
to start a server on https://localhost:8119. Proceed past the TLS warning and
10+
you should get the homepage. Some features won't work when running locally,
11+
but you should be able to view the homepage and the builders page and do basic
12+
sanity checks.

cmd/coordinator/coordinator.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ func (fn loggerFunc) createSpan(event string, optText ...string) eventSpan {
264264
func main() {
265265
flag.Parse()
266266

267+
if Version == "" && *mode == "dev" {
268+
Version = "dev"
269+
}
267270
log.Printf("coordinator version %q starting", Version)
268271
err := initGCE()
269272
if err != nil {
@@ -281,7 +284,7 @@ func main() {
281284
err = initKube()
282285
if err != nil {
283286
kubeErr = err
284-
log.Printf("Kube support disabled due to eror initializing Kubernetes: %v", err)
287+
log.Printf("Kube support disabled due to error initializing Kubernetes: %v", err)
285288
}
286289

287290
go updateInstanceRecord()

cmd/coordinator/gce.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,19 @@ func initGCE() error {
120120

121121
dsClient, err = datastore.NewClient(ctx, buildEnv.ProjectName)
122122
if err != nil {
123-
// TODO(bradfitz): make fatal later, once working.
124-
log.Printf("Error creating datastore client: %v", err)
123+
if *mode == "dev" {
124+
log.Printf("Error creating datastore client: %v", err)
125+
} else {
126+
log.Fatalf("Error creating datastore client: %v", err)
127+
}
125128
}
126129

127130
tokenSource, err = google.DefaultTokenSource(ctx, compute.CloudPlatformScope)
128131
if err != nil {
132+
if *mode == "dev" {
133+
// don't try to do anything else with GCE, as it will likely fail
134+
return nil
135+
}
129136
log.Fatalf("failed to get a token source: %v", err)
130137
}
131138
httpClient := oauth2.NewClient(ctx, tokenSource)
@@ -197,7 +204,7 @@ func (p *gceBuildletPool) pollQuotaLoop() {
197204
return
198205
}
199206
if buildEnv.ProjectName == "" {
200-
log.Printf("pollQuotaLoop: no GCE project name confingured; not checking quota.")
207+
log.Printf("pollQuotaLoop: no GCE project name configured; not checking quota.")
201208
return
202209
}
203210
for {

0 commit comments

Comments
 (0)