Merge pull request #18878 from calavera/conditional_load_response
Make `docker load` to output json when the response content type is json.
This commit is contained in:
commit
b0be88c111
4 changed files with 23 additions and 7 deletions
|
@ -53,7 +53,7 @@ type apiClient interface {
|
|||
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
|
||||
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error)
|
||||
ImageList(options types.ImageListOptions) ([]types.Image, error)
|
||||
ImageLoad(input io.Reader) (io.ReadCloser, error)
|
||||
ImageLoad(input io.Reader) (types.ImageLoadResponse, error)
|
||||
ImagePull(options types.ImagePullOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
||||
ImagePush(options types.ImagePushOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
||||
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
||||
|
|
|
@ -3,15 +3,20 @@ package lib
|
|||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
)
|
||||
|
||||
// ImageLoad loads an image in the docker host from the client host.
|
||||
// It's up to the caller to close the io.ReadCloser returned by
|
||||
// this function.
|
||||
func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
||||
func (cli *Client) ImageLoad(input io.Reader) (types.ImageLoadResponse, error) {
|
||||
resp, err := cli.postRaw("/images/load", url.Values{}, input, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return types.ImageLoadResponse{}, err
|
||||
}
|
||||
return resp.body, nil
|
||||
return types.ImageLoadResponse{
|
||||
Body: resp.body,
|
||||
JSON: resp.header.Get("Content-Type") == "application/json",
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
|
||||
Cli "github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
)
|
||||
|
||||
|
@ -29,12 +30,16 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
|||
input = file
|
||||
}
|
||||
|
||||
responseBody, err := cli.client.ImageLoad(input)
|
||||
response, err := cli.client.ImageLoad(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer responseBody.Close()
|
||||
defer response.Body.Close()
|
||||
|
||||
_, err = io.Copy(cli.out, responseBody)
|
||||
if response.JSON {
|
||||
return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut)
|
||||
}
|
||||
|
||||
_, err = io.Copy(cli.out, response.Body)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -184,6 +184,12 @@ type ImageListOptions struct {
|
|||
Filters filters.Args
|
||||
}
|
||||
|
||||
// ImageLoadResponse returns information to the client about a load process.
|
||||
type ImageLoadResponse struct {
|
||||
Body io.ReadCloser
|
||||
JSON bool
|
||||
}
|
||||
|
||||
// ImagePullOptions holds information to pull images.
|
||||
type ImagePullOptions struct {
|
||||
ImageID string
|
||||
|
|
Loading…
Reference in a new issue