mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #927 from dotcloud/nicer-build-output
* Builder: nicer output for 'docker build'
This commit is contained in:
commit
edbd3da33a
3 changed files with 23 additions and 9 deletions
1
FIXME
1
FIXME
|
@ -16,7 +16,6 @@ to put them - so we put them here :)
|
||||||
* Unify build commands and regular commands
|
* Unify build commands and regular commands
|
||||||
* Move source code into src/ subdir for clarity
|
* Move source code into src/ subdir for clarity
|
||||||
* Clean up the Makefile, it's a mess
|
* Clean up the Makefile, it's a mess
|
||||||
* docker buidl: show short IDs
|
|
||||||
* docker build: on non-existent local path for ADD, don't show full absolute path on the host
|
* docker build: on non-existent local path for ADD, don't show full absolute path on the host
|
||||||
* mount into /dockerinit rather than /sbin/init
|
* mount into /dockerinit rather than /sbin/init
|
||||||
* docker tag foo REPO:TAG
|
* docker tag foo REPO:TAG
|
||||||
|
|
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 {
|
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cache != nil {
|
} else if cache != nil {
|
||||||
|
fmt.Fprintf(b.out, " ---> Using cache\n")
|
||||||
utils.Debugf("[BUILDER] Use cached version")
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
b.image = cache.ID
|
b.image = cache.ID
|
||||||
return nil
|
return nil
|
||||||
|
@ -185,6 +186,7 @@ func (b *buildFile) CmdAdd(args string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.tmpContainers[container.ID] = struct{}{}
|
b.tmpContainers[container.ID] = struct{}{}
|
||||||
|
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID))
|
||||||
|
|
||||||
if err := container.EnsureMounted(); err != nil {
|
if err := container.EnsureMounted(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -235,6 +237,7 @@ func (b *buildFile) run() (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
b.tmpContainers[c.ID] = struct{}{}
|
b.tmpContainers[c.ID] = struct{}{}
|
||||||
|
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(c.ID))
|
||||||
|
|
||||||
//start the container
|
//start the container
|
||||||
if err := c.Start(); err != nil {
|
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 {
|
if cache, err := b.srv.ImageGetCached(b.image, b.config); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if cache != nil {
|
} else if cache != nil {
|
||||||
|
fmt.Fprintf(b.out, " ---> Using cache\n")
|
||||||
utils.Debugf("[BUILDER] Use cached version")
|
utils.Debugf("[BUILDER] Use cached version")
|
||||||
b.image = cache.ID
|
b.image = cache.ID
|
||||||
return nil
|
return nil
|
||||||
|
@ -274,6 +278,7 @@ func (b *buildFile) commit(id string, autoCmd []string, comment string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
b.tmpContainers[container.ID] = struct{}{}
|
b.tmpContainers[container.ID] = struct{}{}
|
||||||
|
fmt.Fprintf(b.out, " ---> Running in %s\n", utils.TruncateID(container.ID))
|
||||||
|
|
||||||
if err := container.EnsureMounted(); err != nil {
|
if err := container.EnsureMounted(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -314,6 +319,7 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
||||||
b.context = name
|
b.context = name
|
||||||
}
|
}
|
||||||
file := bufio.NewReader(dockerfile)
|
file := bufio.NewReader(dockerfile)
|
||||||
|
stepN := 0
|
||||||
for {
|
for {
|
||||||
line, err := file.ReadString('\n')
|
line, err := file.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -334,12 +340,13 @@ func (b *buildFile) Build(dockerfile, context io.Reader) (string, error) {
|
||||||
}
|
}
|
||||||
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
instruction := strings.ToLower(strings.Trim(tmp[0], " "))
|
||||||
arguments := strings.Trim(tmp[1], " ")
|
arguments := strings.Trim(tmp[1], " ")
|
||||||
|
stepN += 1
|
||||||
fmt.Fprintf(b.out, "%s %s (%s)\n", strings.ToUpper(instruction), arguments, b.image)
|
// 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:]))
|
method, exists := reflect.TypeOf(b).MethodByName("Cmd" + strings.ToUpper(instruction[:1]) + strings.ToLower(instruction[1:]))
|
||||||
if !exists {
|
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
|
continue
|
||||||
}
|
}
|
||||||
ret := method.Func.Call([]reflect.Value{reflect.ValueOf(b), reflect.ValueOf(arguments)})[0].Interface()
|
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)
|
return "", ret.(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(b.out, "===> %v\n", b.image)
|
fmt.Fprintf(b.out, " ---> %v\n", utils.TruncateID(b.image))
|
||||||
}
|
}
|
||||||
if 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 b.image, nil
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("An error occured during the build\n")
|
return "", fmt.Errorf("An error occured during the build\n")
|
||||||
|
|
|
@ -15,10 +15,18 @@ steps and commit them along the way, giving you a final image.
|
||||||
1. Usage
|
1. Usage
|
||||||
========
|
========
|
||||||
|
|
||||||
To use Docker Builder, assemble the steps into a text file (commonly referred to
|
To build an image from a source repository, create a description file called `Dockerfile`
|
||||||
as a Dockerfile) and supply this to `docker build` on STDIN, like so:
|
at the root of your repository. This file will describe the steps to assemble
|
||||||
|
the image.
|
||||||
|
|
||||||
``docker build - < Dockerfile``
|
Then call `docker build` with the path of your source repository as argument:
|
||||||
|
|
||||||
|
``docker build .``
|
||||||
|
|
||||||
|
You can specify a repository and tag at which to save the new image if the
|
||||||
|
build succeeds:
|
||||||
|
|
||||||
|
``docker build -t shykes/myapp .``
|
||||||
|
|
||||||
Docker will run your steps one-by-one, committing the result if necessary,
|
Docker will run your steps one-by-one, committing the result if necessary,
|
||||||
before finally outputting the ID of your new image.
|
before finally outputting the ID of your new image.
|
||||||
|
|
Loading…
Reference in a new issue