From f56df04f2d7e93934b304f818b899500aa5b50ac Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 18 Dec 2014 15:40:08 +1100 Subject: [PATCH] cmd/tipgodoc: make tipgodoc run on App Engine Managed VMs At least in theory. We don't totally have it working yet. It does run locally in the dev environment, though, which should be the same as production, since it builds the Docker container locally. But we're getting problems when pushing it to production. Also some minor tweaks to the code with Andrew. Change-Id: Id192669dbc8d3f86d9c8dad79764abd66e983895 Reviewed-on: https://go-review.googlesource.com/1761 Reviewed-by: Andrew Gerrand --- cmd/tipgodoc/Dockerfile | 16 ++++++++++++++++ cmd/tipgodoc/app.yaml | 15 +++++++++++++++ cmd/tipgodoc/tip.go | 32 +++++++++++++------------------- 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 cmd/tipgodoc/Dockerfile create mode 100644 cmd/tipgodoc/app.yaml diff --git a/cmd/tipgodoc/Dockerfile b/cmd/tipgodoc/Dockerfile new file mode 100644 index 0000000000..46de828af1 --- /dev/null +++ b/cmd/tipgodoc/Dockerfile @@ -0,0 +1,16 @@ +# Dockerfile extending the generic Go image with application files for a +# single application. +FROM google/appengine-go + +RUN apt-get update +RUN apt-get install --no-install-recommends -y -q curl build-essential git +RUN mkdir /goroot && curl https://storage.googleapis.com/golang/go1.2.2.linux-amd64.tar.gz | tar xvzf - -C /goroot --strip-components=1 +RUN mkdir /gopath + +ENV GOROOT /goroot +ENV GOPATH /gopath +ENV PATH $PATH:$GOROOT/bin:$GOPATH/bin + +WORKDIR /app +ADD . /app +RUN /bin/bash /app/_ah/build.sh diff --git a/cmd/tipgodoc/app.yaml b/cmd/tipgodoc/app.yaml new file mode 100644 index 0000000000..f877672152 --- /dev/null +++ b/cmd/tipgodoc/app.yaml @@ -0,0 +1,15 @@ +version: tip +runtime: go +api_version: go1 +vm: true + +manual_scaling: + instances: 1 + +handlers: +- url: /.* + script: _go_app + +health_check: + enable_health_check: False + diff --git a/cmd/tipgodoc/tip.go b/cmd/tipgodoc/tip.go index 96ca21c6b8..12a3f4db88 100644 --- a/cmd/tipgodoc/tip.go +++ b/cmd/tipgodoc/tip.go @@ -9,7 +9,6 @@ package main import ( "bufio" "encoding/json" - "flag" "fmt" "io" "io/ioutil" @@ -26,23 +25,16 @@ import ( const metaURL = "https://go.googlesource.com/?b=master&format=JSON" -var ( - pollInterval = flag.Duration("poll", 10*time.Second, "Remote repo poll interval") - listenAddr = flag.String("listen", "localhost:8080", "HTTP listen address") -) - -func main() { - flag.Parse() +func init() { p := new(Proxy) go p.run() http.Handle("/", p) - log.Fatal(http.ListenAndServe(*listenAddr, nil)) } type Proxy struct { - mu sync.Mutex // owns the followin' + mu sync.Mutex // protects the followin' proxy *httputil.ReverseProxy - last string // signature of gorepo+toolsrepo + cur string // signature of gorepo+toolsrepo side string } @@ -51,7 +43,7 @@ func (p *Proxy) run() { p.side = "a" for { p.poll() - time.Sleep(*pollInterval) + time.Sleep(30 * time.Second) } } @@ -62,15 +54,18 @@ func (p *Proxy) poll() { return } + sig := heads["go"] + "-" + heads["tools"] + p.mu.Lock() + changes := sig != p.cur curSide := p.side - lastSig := p.last + p.cur = sig p.mu.Unlock() - sig := heads["go"] + "-" + heads["tools"] - if sig == lastSig { + if !changes { return } + newSide := "b" if curSide == "b" { newSide = "a" @@ -91,7 +86,6 @@ func (p *Proxy) poll() { } p.side = newSide p.proxy = httputil.NewSingleHostReverseProxy(u) - p.last = sig } func initSide(side, goHash, toolsHash string) (hostport string, err error) { @@ -112,7 +106,7 @@ func initSide(side, goHash, toolsHash string) (hostport string, err error) { env := []string{"GOROOT=" + goDir, "GOPATH=" + filepath.Join(dir, "gopath")} - make := exec.Command("./make.bash") + make := exec.Command(filepath.Join(goDir, "src/make.bash")) make.Stdout = os.Stdout make.Stderr = os.Stderr make.Dir = filepath.Join(goDir, "src") @@ -209,7 +203,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { proxy := p.proxy p.mu.Unlock() if proxy == nil { - http.Error(w, "not ready", http.StatusInternalServerError) + http.Error(w, "tip.golang.org is currently starting up, compiling tip", http.StatusInternalServerError) return } proxy.ServeHTTP(w, r) @@ -218,7 +212,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (p *Proxy) serveStatus(w http.ResponseWriter, r *http.Request) { p.mu.Lock() defer p.mu.Unlock() - fmt.Fprintf(w, "side=%v\nlast=%v\n", p.side, p.last) + fmt.Fprintf(w, "side=%v\ncurrent=%v\n", p.side, p.cur) } // gerritMetaMap returns the map from repo name (e.g. "go") to its