Skip to content

Commit

Permalink
Merge pull request #957 from convox/cert-random
Browse files Browse the repository at this point in the history
Stability updates for CI
  • Loading branch information
ddollar authored Aug 1, 2016
2 parents 094a452 + 0ad95db commit 955e71e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
56 changes: 35 additions & 21 deletions api/controllers/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,12 @@ 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"))

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
Expand Down Expand Up @@ -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{}
Expand Down
3 changes: 2 additions & 1 deletion api/models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"math/rand"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 955e71e

Please sign in to comment.