fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

indexserver: Make it possible to override hostname via envvar or flag

Quite a few of our environments will require us to set the hostname that we
advertise to Sourcegraph. For example deploy-sourcegraph-docker and our local
dev environment when testing sharding.

Change-Id: I7eb877114b7773aac8e4c623a4dc9bfa785b5ed8

+17 -15
+17 -15
cmd/zoekt-sourcegraph-indexserver/main.go
··· 65 65 // Interval is how often we sync with Sourcegraph. 66 66 Interval time.Duration 67 67 68 + // Hostname is the name we advertise to Sourcegraph when asking for the 69 + // list of repositories to index. 70 + Hostname string 71 + 68 72 // CPUCount is the amount of parallelism to use when indexing a 69 73 // repository. 70 74 CPUCount int ··· 105 109 go func() { 106 110 t := time.NewTicker(s.Interval) 107 111 for { 108 - hostname, err := os.Hostname() 109 - if err != nil { 110 - log.Println(err) 111 - <-t.C 112 - continue 113 - } 114 - 115 - repos, err := listRepos(hostname, s.Root) 112 + repos, err := listRepos(s.Hostname, s.Root) 116 113 if err != nil { 117 114 log.Println(err) 118 115 <-t.C ··· 391 388 } 392 389 } 393 390 394 - hostname, err := os.Hostname() 395 - if err != nil { 396 - http.Error(w, err.Error(), http.StatusInternalServerError) 397 - return 398 - } 399 - 400 - data.Repos, err = listRepos(hostname, s.Root) 391 + var err error 392 + data.Repos, err = listRepos(s.Hostname, s.Root) 401 393 if err != nil { 402 394 http.Error(w, err.Error(), http.StatusInternalServerError) 403 395 return ··· 516 508 } 517 509 } 518 510 511 + func hostnameBestEffort() string { 512 + if h := os.Getenv("HOSTNAME"); h != "" { 513 + return h 514 + } 515 + hostname, _ := os.Hostname() 516 + return hostname 517 + } 518 + 519 519 func main() { 520 520 root := flag.String("sourcegraph_url", "", "http://sourcegraph-frontend-internal or http://localhost:3090") 521 521 interval := flag.Duration("interval", 10*time.Minute, "sync with sourcegraph this often") 522 522 index := flag.String("index", build.DefaultDir, "set index directory to use") 523 523 listen := flag.String("listen", "", "listen on this address.") 524 + hostname := flag.String("hostname", hostnameBestEffort(), "the name we advertise to Sourcegraph when asking for the list of repositories to index. Can also be set via the HOSTNAME environment variable.") 524 525 cpuFraction := flag.Float64("cpu_fraction", 0.25, 525 526 "use this fraction of the cores for indexing.") 526 527 dbg := flag.Bool("debug", false, ··· 569 570 IndexDir: *index, 570 571 Interval: *interval, 571 572 CPUCount: cpuCount, 573 + Hostname: *hostname, 572 574 } 573 575 574 576 if *listen != "" {