mirror of https://github.com/docker/docs.git
Merge pull request #12649 from jlhawn/fix_pull_err_explosion
Correctly format API error on image pull
This commit is contained in:
commit
5ea8dc376c
|
@ -738,6 +738,15 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
opErr error
|
||||||
|
useJSON = version.GreaterThan("1.0")
|
||||||
|
)
|
||||||
|
|
||||||
|
if useJSON {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
if image != "" { //pull
|
if image != "" { //pull
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
image, tag = parsers.ParseRepositoryTag(image)
|
image, tag = parsers.ParseRepositoryTag(image)
|
||||||
|
@ -754,17 +763,10 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
|
||||||
MetaHeaders: metaHeaders,
|
MetaHeaders: metaHeaders,
|
||||||
AuthConfig: authConfig,
|
AuthConfig: authConfig,
|
||||||
OutStream: utils.NewWriteFlusher(w),
|
OutStream: utils.NewWriteFlusher(w),
|
||||||
}
|
Json: useJSON,
|
||||||
if version.GreaterThan("1.0") {
|
|
||||||
imagePullConfig.Json = true
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
} else {
|
|
||||||
imagePullConfig.Json = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.daemon.Repositories().Pull(image, tag, imagePullConfig); err != nil {
|
opErr = s.daemon.Repositories().Pull(image, tag, imagePullConfig)
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else { //import
|
} else { //import
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
repo, tag = parsers.ParseRepositoryTag(repo)
|
repo, tag = parsers.ParseRepositoryTag(repo)
|
||||||
|
@ -775,12 +777,7 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
|
||||||
Changes: r.Form["changes"],
|
Changes: r.Form["changes"],
|
||||||
InConfig: r.Body,
|
InConfig: r.Body,
|
||||||
OutStream: utils.NewWriteFlusher(w),
|
OutStream: utils.NewWriteFlusher(w),
|
||||||
}
|
Json: useJSON,
|
||||||
if version.GreaterThan("1.0") {
|
|
||||||
imageImportConfig.Json = true
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
} else {
|
|
||||||
imageImportConfig.Json = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
|
newConfig, err := builder.BuildFromConfig(s.daemon, &runconfig.Config{}, imageImportConfig.Changes)
|
||||||
|
@ -789,9 +786,12 @@ func (s *Server) postImagesCreate(eng *engine.Engine, version version.Version, w
|
||||||
}
|
}
|
||||||
imageImportConfig.ContainerConfig = newConfig
|
imageImportConfig.ContainerConfig = newConfig
|
||||||
|
|
||||||
if err := s.daemon.Repositories().Import(src, repo, tag, imageImportConfig); err != nil {
|
opErr = s.daemon.Repositories().Import(src, repo, tag, imageImportConfig)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opErr != nil {
|
||||||
|
sf := streamformatter.NewStreamFormatter(useJSON)
|
||||||
|
return fmt.Errorf(string(sf.FormatError(opErr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -98,8 +98,13 @@ func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
|
||||||
|
|
||||||
// pulling a non-existing image from the central registry should return a non-zero exit code
|
// pulling a non-existing image from the central registry should return a non-zero exit code
|
||||||
func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
|
func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
|
||||||
pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234")
|
testRequires(c, Network)
|
||||||
if out, _, err := runCommandWithOutput(pullCmd); err == nil {
|
|
||||||
|
name := "sadfsadfasdf"
|
||||||
|
pullCmd := exec.Command(dockerBinary, "pull", name)
|
||||||
|
out, _, err := runCommandWithOutput(pullCmd)
|
||||||
|
|
||||||
|
if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
|
||||||
c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
|
c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue