mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Nicer output for 'docker build'
This commit is contained in:
parent
702c3538a4
commit
cb9d0fd3bc
1 changed files with 12 additions and 5 deletions
17
buildfile.go
17
buildfile.go
|
@ -101,6 +101,7 @@ func (b *buildFile) CmdRun(args string) error {
|
|||
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||
return err
|
||||
} else if cache != nil {
|
||||
fmt.Fprintf(b.out, " ---> Using cache\n")
|
||||
utils.Debugf("[BUILDER] Use cached version")
|
||||
b.image = cache.ID
|
||||
return nil
|
||||
|
@ -185,6 +186,7 @@ func (b *buildFile) CmdAdd(args string) error {
|
|||
return err
|
||||
}
|
||||
b.tmpContainers[container.ID] = struct{}{}
|
||||
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID))
|
||||
|
||||
if err := container.EnsureMounted(); err != nil {
|
||||
return err
|
||||
|
@ -235,6 +237,7 @@ func (b *buildFile) run() (string, error) {
|
|||
return "", err
|
||||
}
|
||||
b.tmpContainers[c.ID] = struct{}{}
|
||||
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID))
|
||||
|
||||
//start the container
|
||||
if err := c.Start(); err != nil {
|
||||
|
@ -261,6 +264,7 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
|||
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||
return err
|
||||
} else if cache != nil {
|
||||
fmt.Fprintf(b.out, " ---> Using cache\n")
|
||||
utils.Debugf("[BUILDER] Use cached version")
|
||||
b.image = cache.ID
|
||||
return nil
|
||||
|
@ -274,6 +278,7 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
|||
return err
|
||||
}
|
||||
b.tmpContainers[container.ID] = struct{}{}
|
||||
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID))
|
||||
|
||||
if err := container.EnsureMounted(); err != nil {
|
||||
return err
|
||||
|
@ -314,6 +319,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
|||
b.context = name
|
||||
}
|
||||
file := bufio.NewReader(dockerfile)
|
||||
stepN := 0
|
||||
for {
|
||||
line, err := file.ReadString('\n')
|
||||
if err != nil {
|
||||
|
@ -334,12 +340,13 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
|||
}
|
||||
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
||||
arguments := strings.Trim(tmp[1], " ")
|
||||
|
||||
fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
||||
stepN += 1
|
||||
// FIXME: only count known instructions as build steps
|
||||
fmt.Fprintf(b.out, "Step %d : %s %s\n", stepN, strings.ToUpper(instruction), arguments)
|
||||
|
||||
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
||||
if !exists {
|
||||
fmt.Fprintf(b.out, "Skipping unknown instruction %s\n", strings.ToUpper(instruction))
|
||||
fmt.Fprintf(b.out, "# Skipping unknown instruction %s\n", strings.ToUpper(instruction))
|
||||
continue
|
||||
}
|
||||
ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
|
||||
|
@ -347,10 +354,10 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
|||
return "", ret.(error)
|
||||
}
|
||||
|
||||
fmt.Fprintf(b.out, "===> %v\n", b.image)
|
||||
fmt.Fprintf(b.out, " ---> %v\n", utils.TruncateID(b.image))
|
||||
}
|
||||
if b.image != "" {
|
||||
fmt.Fprintf(b.out, "Build successful.\n===> %s\n", b.image)
|
||||
fmt.Fprintf(b.out, "Successfully built %s\n", utils.TruncateID(b.image))
|
||||
return b.image, nil
|
||||
}
|
||||
return "", fmt.Errorf("An error occured during the build\n")
|
||||
|
|
Loading…
Reference in a new issue