1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #24978 from yongtang/24912-build-with-progress

Add hint of progress to the output of `docker build`
This commit is contained in:
Doug Davis 2016-08-18 16:10:48 -04:00 committed by GitHub
commit 282b0aff08
5 changed files with 24 additions and 8 deletions

View file

@ -233,6 +233,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
}
var shortImgID string
total := len(b.dockerfile.Children)
for i, n := range b.dockerfile.Children {
select {
case <-b.clientCtx.Done():
@ -242,7 +243,7 @@ func (b *Builder) build(stdout io.Writer, stderr io.Writer, out io.Writer) (stri
default:
// Not cancelled yet, keep going...
}
if err := b.dispatch(i, n); err != nil {
if err := b.dispatch(i, total, n); err != nil {
if b.options.ForceRemove {
b.clearTmp()
}
@ -320,8 +321,9 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
b.Stderr = ioutil.Discard
b.disableCommit = true
total := len(ast.Children)
for i, n := range ast.Children {
if err := b.dispatch(i, n); err != nil {
if err := b.dispatch(i, total, n); err != nil {
return nil, err
}
}

View file

@ -93,7 +93,7 @@ func init() {
// such as `RUN` in ONBUILD RUN foo. There is special case logic in here to
// deal with that, at least until it becomes more of a general concern with new
// features.
func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
func (b *Builder) dispatch(stepN int, stepTotal int, ast *parser.Node) error {
cmd := ast.Value
upperCasedCmd := strings.ToUpper(cmd)
@ -107,7 +107,7 @@ func (b *Builder) dispatch(stepN int, ast *parser.Node) error {
original := ast.Original
flags := ast.Flags
strList := []string{}
msg := fmt.Sprintf("Step %d : %s", stepN+1, upperCasedCmd)
msg := fmt.Sprintf("Step %d/%d : %s", stepN+1, stepTotal, upperCasedCmd)
if len(ast.Flags) > 0 {
msg += " " + strings.Join(ast.Flags, " ")

View file

@ -184,7 +184,7 @@ func executeTestCase(t *testing.T, testCase dispatchTestCase) {
b := &Builder{runConfig: config, options: options, Stdout: ioutil.Discard, context: context}
err = b.dispatch(0, n.Children[0])
err = b.dispatch(0, len(n.Children), n.Children[0])
if err == nil {
t.Fatalf("No error when executing test %s", testCase.name)

View file

@ -434,6 +434,7 @@ func (b *Builder) processImageFrom(img builder.Image) error {
return err
}
total := len(ast.Children)
for i, n := range ast.Children {
switch strings.ToUpper(n.Value) {
case "ONBUILD":
@ -442,7 +443,7 @@ func (b *Builder) processImageFrom(img builder.Image) error {
return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", n.Value)
}
if err := b.dispatch(i, n); err != nil {
if err := b.dispatch(i, total, n); err != nil {
return err
}
}

View file

@ -5417,7 +5417,7 @@ func (s *DockerSuite) TestBuildNoDupOutput(c *check.C) {
c.Fatalf("Build should have worked: %q", err)
}
exp := "\nStep 2 : RUN env\n"
exp := "\nStep 2/2 : RUN env\n"
if !strings.Contains(out, exp) {
c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp)
}
@ -5434,7 +5434,7 @@ func (s *DockerSuite) TestBuildStartsFromOne(c *check.C) {
c.Fatalf("Build should have worked: %q", err)
}
exp := "\nStep 1 : FROM busybox\n"
exp := "\nStep 1/1 : FROM busybox\n"
if !strings.Contains(out, exp) {
c.Fatalf("Bad output\nGot:%s\n\nExpected to contain:%s\n", out, exp)
}
@ -6981,3 +6981,16 @@ func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) {
c.Fatalf("CMD was not escaped Config.Cmd: got %v", res)
}
}
// Test case for #24912.
func (s *DockerSuite) TestBuildStepsWithProgress(c *check.C) {
name := "testbuildstepswithprogress"
totalRun := 5
_, out, err := buildImageWithOut(name, "FROM busybox\n"+strings.Repeat("RUN echo foo\n", totalRun), true)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, fmt.Sprintf("Step 1/%d : FROM busybox", 1+totalRun))
for i := 2; i <= 1+totalRun; i++ {
c.Assert(out, checker.Contains, fmt.Sprintf("Step %d/%d : RUN echo foo", i, 1+totalRun))
}
}