Skip to content

Commit

Permalink
docker build: dump output when the build fails
Browse files Browse the repository at this point in the history
  • Loading branch information
draganm committed Nov 5, 2019
1 parent 29bc6f6 commit 8ecb35b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion resource/docker/build/docker_build_resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package build

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -110,6 +111,8 @@ func resourceCreate(d *schema.ResourceData, m interface{}) error {

lastID := ""

output := new(bytes.Buffer)

for {
msg := jsonmessage.JSONMessage{}
err = dec.Decode(&msg)
Expand All @@ -123,12 +126,14 @@ func resourceCreate(d *schema.ResourceData, m interface{}) error {

matches := builtRegexp.FindStringSubmatch(msg.Stream)

output.WriteString(msg.Stream)

if len(matches) > 1 {
lastID = matches[1]
}

if msg.Error != nil {
return errors.Errorf("error code %d building image: %s", msg.Error.Code, msg.Error.Message)
return errors.Errorf("error code %d building image: %s, output:\n%s", msg.Error.Code, msg.Error.Message, output.String())
}
}

Expand Down

0 comments on commit 8ecb35b

Please sign in to comment.