mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #21959 from coolljt0725/fix_21957
Fix docker load progressbar, fixes #21957
This commit is contained in:
commit
348d902768
4 changed files with 33 additions and 2 deletions
|
@ -41,7 +41,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
if response.JSON {
|
if response.Body != nil && response.JSON {
|
||||||
return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut, nil)
|
return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,7 +206,17 @@ func (s *imageRouter) postImagesLoad(ctx context.Context, w http.ResponseWriter,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
quiet := httputils.BoolValueOrDefault(r, "quiet", true)
|
quiet := httputils.BoolValueOrDefault(r, "quiet", true)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
if !quiet {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
output := ioutils.NewWriteFlusher(w)
|
||||||
|
defer output.Close()
|
||||||
|
if err := s.backend.LoadImage(r.Body, output, quiet); err != nil {
|
||||||
|
output.Write(streamformatter.NewJSONStreamFormatter().FormatError(err))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return s.backend.LoadImage(r.Body, w, quiet)
|
return s.backend.LoadImage(r.Body, w, quiet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
|
||||||
)
|
)
|
||||||
if !quiet {
|
if !quiet {
|
||||||
progressOutput = sf.NewProgressOutput(outStream, false)
|
progressOutput = sf.NewProgressOutput(outStream, false)
|
||||||
|
outStream = &streamformatter.StdoutFormatter{Writer: outStream, StreamFormatter: streamformatter.NewJSONStreamFormatter()}
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "docker-import-")
|
tmpDir, err := ioutil.TempDir("", "docker-import-")
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -65,3 +66,22 @@ func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
|
||||||
c.Assert(err, check.IsNil) //could not read tty output
|
c.Assert(err, check.IsNil) //could not read tty output
|
||||||
c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out))
|
c.Assert(string(buf[:n]), checker.Contains, "Cowardly refusing", check.Commentf("help output is not being yielded", out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestSaveAndLoadWithProgressBar(c *check.C) {
|
||||||
|
name := "test-load"
|
||||||
|
_, err := buildImage(name, `
|
||||||
|
FROM busybox
|
||||||
|
RUN touch aa
|
||||||
|
`, true)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
tmptar := name + ".tar"
|
||||||
|
dockerCmd(c, "save", "-o", tmptar, name)
|
||||||
|
defer os.Remove(tmptar)
|
||||||
|
|
||||||
|
dockerCmd(c, "rmi", name)
|
||||||
|
dockerCmd(c, "tag", "busybox", name)
|
||||||
|
out, _ := dockerCmd(c, "load", "-i", tmptar)
|
||||||
|
expected := fmt.Sprintf("The image %s:latest already exists, renaming the old one with ID", name)
|
||||||
|
c.Assert(out, checker.Contains, expected)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue