Skip to content

Commit

Permalink
Merge pull request #535 from convox/build-enhancements
Browse files Browse the repository at this point in the history
Build enhancements
  • Loading branch information
Noah Zoschke committed Apr 11, 2016
2 parents e3d4b81 + aec4fee commit 75e4d51
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
27 changes: 21 additions & 6 deletions api/controllers/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,34 @@ func BuildUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
return httperr.Server(err)
}

b.Ended = time.Now()
b.Manifest = r.FormValue("manifest")
b.Reason = r.FormValue("reason")
b.Status = r.FormValue("status")
if d := r.FormValue("description"); d != "" {
b.Description = d
}

if m := r.FormValue("manifest"); m != "" {
b.Manifest = m
}

if r := r.FormValue("reason"); r != "" {
b.Reason = r
}

if s := r.FormValue("status"); s != "" {
b.Status = s
b.Ended = time.Now()
}

// if build was successful create a release
if b.Status == "complete" && b.Manifest != "" {
_, err := provider.BuildRelease(b)
if err != nil {
return httperr.Server(err)
}
} else {
provider.BuildSave(b)
}

err = provider.BuildSave(b)
if err != nil {
return httperr.Server(err)
}

return RenderJson(rw, b)
Expand Down
42 changes: 42 additions & 0 deletions api/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,48 @@ paths:
description: not found
schema:
$ref: '#/definitions/error'
put:
description: Update build status
parameters:
- name: app
description: app name
type: string
in: path
required: true
- name: build
description: build id
type: string
in: path
required: true
- name: description
description: build description
type: string
in: formData
required: false
- name: manifest
description: release manifest extracted during build
type: string
in: formData
required: false
- name: reason
description: reason with status "failed"
type: string
in: formData
required: false
- name: status
description: final build status "complete" or "failed"
type: string
in: formData
required: false
responses:
200:
description: build
schema:
$ref: '#/definitions/build'
404:
description: not found
schema:
$ref: '#/definitions/error'
/apps/{app}/environment:
get:
description: List environment for an app
Expand Down
27 changes: 17 additions & 10 deletions api/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (
Stderr = io.Writer(os.Stderr)
Execer = exec.Command
SignalWaiter = waitForSignal

regexValidProcessName = regexp.MustCompile(`\A[a-zA-Z0-9][-a-zA-Z0-9]{0,29}\z`) // 'web', '1', 'web-1' valid; '-', 'web_1' invalid
)

var (
Expand Down Expand Up @@ -157,6 +159,10 @@ func Read(dir, filename string) (*Manifest, error) {
}

for name, entry := range m {
if !regexValidProcessName.MatchString(name) {
return &m, fmt.Errorf("process name %q is invalid. It should contain only alphanumeric characters and dashes.", name)
}

for i, volume := range entry.Volumes {
parts := strings.Split(volume, ":")

Expand Down Expand Up @@ -218,7 +224,6 @@ func (m *Manifest) Build(app, dir string, cache bool) []error {
builds := map[string]string{}
pulls := []string{}
tags := map[string]string{}
dockerfiles := map[string]string{}

for name, entry := range *m {
tag := fmt.Sprintf("%s/%s", app, name)
Expand All @@ -232,21 +237,22 @@ func (m *Manifest) Build(app, dir string, cache bool) []error {
}

sym, err := filepath.EvalSymlinks(abs)

if err != nil {
return []error{err}
}
if _, ok := builds[sym]; !ok {
builds[sym] = randomString("convox-", 10)

df := "Dockerfile"
if entry.Dockerfile != "" {
df = entry.Dockerfile
}

tags[tag] = builds[sym]
sym = filepath.Join(sym, df)

// Dockerfile can only be specified if Build is also specified
if entry.Dockerfile != "" {
dockerfiles[sym] = entry.Dockerfile
if _, ok := builds[sym]; !ok {
builds[sym] = randomString("convox-", 10)
}

tags[tag] = builds[sym]
case entry.Image != "":
err := Execer("docker", "inspect", entry.Image).Run()

Expand All @@ -260,8 +266,9 @@ func (m *Manifest) Build(app, dir string, cache bool) []error {

errors := []error{}

for source, tag := range builds {
err := buildSync(source, tag, cache, dockerfiles[source])
for path, tag := range builds {
source, dockerfile := filepath.Split(path)
err := buildSync(source, tag, cache, dockerfile)

if err != nil {
return []error{err}
Expand Down

0 comments on commit 75e4d51

Please sign in to comment.