|
@@ -28,8 +28,8 @@ type buildFile struct {
|
|
|
maintainer string
|
|
|
config *Config
|
|
|
context string
|
|
|
+ verbose bool
|
|
|
|
|
|
- lastContainer *Container
|
|
|
tmpContainers map[string]struct{}
|
|
|
tmpImages map[string]struct{}
|
|
|
|
|
@@ -254,7 +254,6 @@ func (b *buildFile) CmdAdd(args string) error {
|
|
|
return err
|
|
|
}
|
|
|
b.tmpContainers[container.ID] = struct{}{}
|
|
|
- b.lastContainer = container
|
|
|
|
|
|
if err := container.EnsureMounted(); err != nil {
|
|
|
return err
|
|
@@ -290,7 +289,6 @@ func (b *buildFile) run() (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
b.tmpContainers[c.ID] = struct{}{}
|
|
|
- b.lastContainer = c
|
|
|
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID))
|
|
|
|
|
|
// override the entry point that may have been picked up from the base image
|
|
@@ -303,6 +301,13 @@ func (b *buildFile) run() (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
+ if b.verbose {
|
|
|
+ err = <-c.Attach(nil, nil, b.out, b.out)
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Wait for it to finish
|
|
|
if ret := c.Wait(); ret != 0 {
|
|
|
return "", fmt.Errorf("The command %v returned a non-zero code: %d", b.config.Cmd, ret)
|
|
@@ -337,7 +342,6 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
|
|
return err
|
|
|
}
|
|
|
b.tmpContainers[container.ID] = struct{}{}
|
|
|
- b.lastContainer = container
|
|
|
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID))
|
|
|
id = container.ID
|
|
|
if err := container.EnsureMounted(); err != nil {
|
|
@@ -365,29 +369,6 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
|
|
}
|
|
|
|
|
|
func (b *buildFile) Build(context io.Reader) (string, error) {
|
|
|
- defer func() {
|
|
|
- // If we have an error and a container, the display the logs
|
|
|
- if b.lastContainer != nil {
|
|
|
- fmt.Fprintf(b.out, "******** Logs from last container (%s) *******\n", b.lastContainer.ShortID())
|
|
|
-
|
|
|
- cLog, err := b.lastContainer.ReadLog("stdout")
|
|
|
- if err != nil {
|
|
|
- utils.Debugf("Error reading logs (stdout): %s", err)
|
|
|
- }
|
|
|
- if _, err := io.Copy(b.out, cLog); err != nil {
|
|
|
- utils.Debugf("Error streaming logs (stdout): %s", err)
|
|
|
- }
|
|
|
- cLog, err = b.lastContainer.ReadLog("stderr")
|
|
|
- if err != nil {
|
|
|
- utils.Debugf("Error reading logs (stderr): %s", err)
|
|
|
- }
|
|
|
- if _, err := io.Copy(b.out, cLog); err != nil {
|
|
|
- utils.Debugf("Error streaming logs (stderr): %s", err)
|
|
|
- }
|
|
|
- fmt.Fprintf(b.out, "************* End of logs for %s *************\n", b.lastContainer.ShortID())
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
// FIXME: @creack any reason for using /tmp instead of ""?
|
|
|
// FIXME: @creack "name" is a terrible variable name
|
|
|
name, err := ioutil.TempDir("/tmp", "docker-build")
|
|
@@ -440,7 +421,6 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
|
|
return "", ret.(error)
|
|
|
}
|
|
|
|
|
|
- b.lastContainer = nil
|
|
|
fmt.Fprintf(b.out, " ---> %v\n", utils.TruncateID(b.image))
|
|
|
}
|
|
|
if b.image != "" {
|
|
@@ -450,7 +430,7 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
|
|
return "", fmt.Errorf("An error occured during the build\n")
|
|
|
}
|
|
|
|
|
|
-func NewBuildFile(srv *Server, out io.Writer) BuildFile {
|
|
|
+func NewBuildFile(srv *Server, out io.Writer, verbose bool) BuildFile {
|
|
|
return &buildFile{
|
|
|
builder: NewBuilder(srv.runtime),
|
|
|
runtime: srv.runtime,
|
|
@@ -459,5 +439,6 @@ func NewBuildFile(srv *Server, out io.Writer) BuildFile {
|
|
|
out: out,
|
|
|
tmpContainers: make(map[string]struct{}),
|
|
|
tmpImages: make(map[string]struct{}),
|
|
|
+ verbose: verbose,
|
|
|
}
|
|
|
}
|