1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:18:35 -06:00

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 <adg@golang.org>
This commit is contained in:
Brad Fitzpatrick 2014-12-18 15:40:08 +11:00 committed by Brad Fitzpatrick
parent 443d37c586
commit f56df04f2d
3 changed files with 44 additions and 19 deletions

16
cmd/tipgodoc/Dockerfile Normal file
View File

@ -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

15
cmd/tipgodoc/app.yaml Normal file
View File

@ -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

View File

@ -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