From edd9cfce3fd78bac6172853c00538b7aeab88a2c Mon Sep 17 00:00:00 2001 From: David Dollar Date: Sun, 31 Jul 2016 22:28:16 -0400 Subject: [PATCH 1/3] randomize the cert name --- api/models/release.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/models/release.go b/api/models/release.go index 62978391c2..54d0b26a0a 100644 --- a/api/models/release.go +++ b/api/models/release.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "html/template" + "math/rand" "os" "os/exec" "regexp" @@ -271,7 +272,7 @@ func (r *Release) Promote() error { switch app.Parameters[protoParam] { case "https", "tls": if app.Parameters[certParam] == "" { - name := fmt.Sprintf("cert-%s-%d", os.Getenv("RACK"), time.Now().Unix()) + name := fmt.Sprintf("cert-%s-%d-%05d", os.Getenv("RACK"), time.Now().Unix(), rand.Intn(100000)) body, key, err := GenerateSelfSignedCertificate("*.*.elb.amazonaws.com") if err != nil { From e3251a24ecc178fecbd9639019274fc382e365d7 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Sun, 31 Jul 2016 22:48:00 -0400 Subject: [PATCH 2/3] try a few times to find the build host --- api/controllers/builds.go | 58 ++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/api/controllers/builds.go b/api/controllers/builds.go index 96dc27d40a..0d11fc4ca2 100644 --- a/api/controllers/builds.go +++ b/api/controllers/builds.go @@ -249,32 +249,13 @@ func BuildLogs(ws *websocket.Conn) *httperr.Error { // in production loop through docker hosts that the rack is running on // to find the build - if os.Getenv("DEVELOPMENT") != "true" { - pss, err := models.ListProcesses(os.Getenv("RACK")) - + if os.Getenv("DEVELOPMENT") != "truee" { + h, err := findBuildHost(build) if err != nil { return httperr.Server(err) } - for _, ps := range pss { - client, err := ps.Docker() - - if err != nil { - return httperr.Server(err) - } - - res, err := client.ListContainers(docker.ListContainersOptions{ - All: true, - Filters: map[string][]string{ - "name": []string{fmt.Sprintf("build-%s", build)}, - }, - }) - - if len(res) > 0 { - host = fmt.Sprintf("http://%s:2376", ps.Host) - break - } - } + host = h } // proxy to docker container logs @@ -341,6 +322,39 @@ ForLoop: return httperr.Server(err) } +// try to find the docker host that's running a build +// try a few times with a sleep +func findBuildHost(build string) (string, error) { + for i := 1; i < 5; i++ { + pss, err := models.ListProcesses(os.Getenv("RACK")) + if err != nil { + return "", httperr.Server(err) + } + + for _, ps := range pss { + client, err := ps.Docker() + if err != nil { + return "", httperr.Server(err) + } + + res, err := client.ListContainers(docker.ListContainersOptions{ + All: true, + Filters: map[string][]string{ + "name": []string{fmt.Sprintf("build-%s", build)}, + }, + }) + + if len(res) > 0 { + return fmt.Sprintf("http://%s:2376", ps.Host), nil + } + } + + time.Sleep(2 * time.Second) + } + + return "", fmt.Errorf("could not find build host") +} + func keepAlive(ws *websocket.Conn, quit chan bool) { c := time.Tick(5 * time.Second) b := []byte{} From 0ad95db253540ca494eb8e9c3832687b1b0813b9 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Sun, 31 Jul 2016 23:37:03 -0400 Subject: [PATCH 3/3] fix typo --- api/controllers/builds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/controllers/builds.go b/api/controllers/builds.go index 0d11fc4ca2..fa6df3d3fa 100644 --- a/api/controllers/builds.go +++ b/api/controllers/builds.go @@ -249,7 +249,7 @@ func BuildLogs(ws *websocket.Conn) *httperr.Error { // in production loop through docker hosts that the rack is running on // to find the build - if os.Getenv("DEVELOPMENT") != "truee" { + if os.Getenv("DEVELOPMENT") != "true" { h, err := findBuildHost(build) if err != nil { return httperr.Server(err)