@@ -13,6 +13,7 @@ import (
13
13
"io/ioutil"
14
14
"log"
15
15
"net/http"
16
+ "net/http/httputil"
16
17
"net/url"
17
18
"os"
18
19
"os/exec"
@@ -29,12 +30,12 @@ var (
29
30
)
30
31
31
32
type watchConfig struct {
32
- repo string // "https://go.googlesource.com/go"
33
- dash string // "https://build.golang.org/" (must end in /)
34
- interval time.Duration // Polling interval
35
- mirrorBase string // "https://github.com/golang/" or empty to disable mirroring
36
- netHost bool // run docker container in the host's network namespace
37
- httpAddr string
33
+ repo string // "https://go.googlesource.com/go"
34
+ dash string // "https://build.golang.org/" (must end in /)
35
+ interval time.Duration // Polling interval
36
+ mirror bool // whether to enable mirroring to github
37
+ netHost bool // run docker container in the host's network namespace
38
+ httpAddr string
38
39
}
39
40
40
41
type imageInfo struct {
@@ -59,16 +60,16 @@ var images = map[string]*imageInfo{
59
60
const gitArchiveAddr = "127.0.0.1:21536" // 21536 == keys above WATCH
60
61
61
62
func startWatchers () {
62
- mirrorBase := "https://github.com/golang/"
63
+ mirror := true
63
64
if inStaging {
64
- mirrorBase = "" // don't mirror from dev cluster
65
+ mirror = false
65
66
}
66
67
addWatcher (watchConfig {
67
- repo : "https://go.googlesource.com/go" ,
68
- dash : dashBase (),
69
- mirrorBase : mirrorBase ,
70
- netHost : true ,
71
- httpAddr : gitArchiveAddr ,
68
+ repo : "https://go.googlesource.com/go" ,
69
+ dash : dashBase (),
70
+ mirror : mirror ,
71
+ netHost : true ,
72
+ httpAddr : gitArchiveAddr ,
72
73
})
73
74
if false {
74
75
// TODO(cmang,adg): only use one watcher or the other, depending on which build
@@ -122,15 +123,32 @@ func (conf watchConfig) dockerRunArgs() (args []string) {
122
123
log .Fatalf ("Failed to created watcher's git cache dir: %v" , err )
123
124
}
124
125
126
+ args = append (args , "-v" , os .Args [0 ]+ ":/usr/local/bin/watcher" )
127
+ args = append (args , "-v" , watcherGitCacheDir + ":" + watcherGitCacheDir )
128
+
129
+ // Bind mount in gopherbot's private ed25519 ssh key from the PEM contents
130
+ // in the GCE metadata. (Appending a newline, else it's invalid)
131
+ if priv , err := metadata .ProjectAttributeValue ("github-ssh" ); err == nil {
132
+ file := "/tmp/id_ed25519.gopherbot.ssh"
133
+ if _ , err := os .Stat (file ); err != nil {
134
+ if err := ioutil .WriteFile (file , []byte (priv + "\n " ), 0600 ); err != nil {
135
+ log .Fatal (err )
136
+ }
137
+ }
138
+ log .Printf ("added gopherbot ssh key" )
139
+ args = append (args , "-v" , file + ":/root/.ssh/id_ed25519" )
140
+ } else {
141
+ log .Printf ("no gopherbot ssh key found in GCE metadata: %v" , err )
142
+ }
143
+
144
+ // Bind mount in the key for the build.golang.org private token.
125
145
if key := masterKey (); len (key ) > 0 {
126
146
tmpKey := "/tmp/watcher.buildkey"
127
147
if _ , err := os .Stat (tmpKey ); err != nil {
128
148
if err := ioutil .WriteFile (tmpKey , key , 0600 ); err != nil {
129
149
log .Fatal (err )
130
150
}
131
151
}
132
- args = append (args , "-v" , os .Args [0 ]+ ":/usr/local/bin/watcher" )
133
- args = append (args , "-v" , watcherGitCacheDir + ":" + watcherGitCacheDir )
134
152
// Images may look for .gobuildkey in / or /root, so provide both.
135
153
// TODO(adg): fix images that look in the wrong place.
136
154
args = append (args , "-v" , tmpKey + ":/.gobuildkey" )
@@ -148,13 +166,8 @@ func (conf watchConfig) dockerRunArgs() (args []string) {
148
166
"-watcher.poll=" + conf .interval .String (),
149
167
"-watcher.http=" + conf .httpAddr ,
150
168
)
151
- if conf .mirrorBase != "" {
152
- dst , err := url .Parse (conf .mirrorBase )
153
- if err != nil {
154
- log .Fatalf ("Bad mirror destination URL: %q" , conf .mirrorBase )
155
- }
156
- dst .User = url .UserPassword (mirrorCred ())
157
- args = append (args , "-watcher.mirror=" + dst .String ())
169
+ if conf .mirror {
170
+ args = append (args , "-watcher.mirror" )
158
171
}
159
172
return
160
173
}
@@ -224,7 +237,7 @@ var (
224
237
225
238
var matchTokens = regexp .MustCompile (`\b[0-9a-f]{40}\b` )
226
239
227
- func handleDebugWatcher (w http.ResponseWriter , r * http.Request ) {
240
+ func handleDebugWatcherLogs (w http.ResponseWriter , r * http.Request ) {
228
241
w .Header ().Set ("Content-Type" , "text/plain; charset=utf-8" )
229
242
watchLogMu .Lock ()
230
243
defer watchLogMu .Unlock ()
@@ -237,6 +250,26 @@ func handleDebugWatcher(w http.ResponseWriter, r *http.Request) {
237
250
}
238
251
}
239
252
253
+ // watcherProxy is the proxy which forwards from
254
+ // http://farmer.golang.org/ to the watcher (git cache+sync) child
255
+ // process listening on http://127.0.0.1:21536. This is used for
256
+ // /debug/watcher/<reponame> status pages, which are served at the
257
+ // same URL paths for both the farmer.golang.org host and the internal
258
+ // backend.
259
+ var watcherProxy * httputil.ReverseProxy
260
+
261
+ func init () {
262
+ u , err := url .Parse ("http://" + gitArchiveAddr )
263
+ if err != nil {
264
+ log .Fatal (err )
265
+ }
266
+ watcherProxy = httputil .NewSingleHostReverseProxy (u )
267
+ }
268
+
269
+ func handleDebugWatcher (w http.ResponseWriter , r * http.Request ) {
270
+ watcherProxy .ServeHTTP (w , r )
271
+ }
272
+
240
273
func startWatching (conf watchConfig ) (err error ) {
241
274
defer func () {
242
275
if err != nil {
0 commit comments