Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -53,7 +53,7 @@ type apiClient interface {
|
| 53 | 53 |
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error) |
| 54 | 54 |
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error) |
| 55 | 55 |
ImageList(options types.ImageListOptions) ([]types.Image, error) |
| 56 |
- ImageLoad(input io.Reader) (io.ReadCloser, error) |
|
| 56 |
+ ImageLoad(input io.Reader) (types.ImageLoadResponse, error) |
|
| 57 | 57 |
ImagePull(options types.ImagePullOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error) |
| 58 | 58 |
ImagePush(options types.ImagePushOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error) |
| 59 | 59 |
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error) |
| ... | ... |
@@ -3,15 +3,20 @@ package lib |
| 3 | 3 |
import ( |
| 4 | 4 |
"io" |
| 5 | 5 |
"net/url" |
| 6 |
+ |
|
| 7 |
+ "github.com/docker/docker/api/types" |
|
| 6 | 8 |
) |
| 7 | 9 |
|
| 8 | 10 |
// ImageLoad loads an image in the docker host from the client host. |
| 9 | 11 |
// It's up to the caller to close the io.ReadCloser returned by |
| 10 | 12 |
// this function. |
| 11 |
-func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
|
| 13 |
+func (cli *Client) ImageLoad(input io.Reader) (types.ImageLoadResponse, error) {
|
|
| 12 | 14 |
resp, err := cli.postRaw("/images/load", url.Values{}, input, nil)
|
| 13 | 15 |
if err != nil {
|
| 14 |
- return nil, err |
|
| 16 |
+ return types.ImageLoadResponse{}, err
|
|
| 15 | 17 |
} |
| 16 |
- return resp.body, nil |
|
| 18 |
+ return types.ImageLoadResponse{
|
|
| 19 |
+ Body: resp.body, |
|
| 20 |
+ JSON: resp.header.Get("Content-Type") == "application/json",
|
|
| 21 |
+ }, nil |
|
| 17 | 22 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"os" |
| 6 | 6 |
|
| 7 | 7 |
Cli "github.com/docker/docker/cli" |
| 8 |
+ "github.com/docker/docker/pkg/jsonmessage" |
|
| 8 | 9 |
flag "github.com/docker/docker/pkg/mflag" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -29,12 +30,16 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
| 29 | 29 |
input = file |
| 30 | 30 |
} |
| 31 | 31 |
|
| 32 |
- responseBody, err := cli.client.ImageLoad(input) |
|
| 32 |
+ response, err := cli.client.ImageLoad(input) |
|
| 33 | 33 |
if err != nil {
|
| 34 | 34 |
return err |
| 35 | 35 |
} |
| 36 |
- defer responseBody.Close() |
|
| 36 |
+ defer response.Body.Close() |
|
| 37 | 37 |
|
| 38 |
- _, err = io.Copy(cli.out, responseBody) |
|
| 38 |
+ if response.JSON {
|
|
| 39 |
+ return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut) |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ _, err = io.Copy(cli.out, response.Body) |
|
| 39 | 43 |
return err |
| 40 | 44 |
} |
| ... | ... |
@@ -179,6 +179,12 @@ type ImageListOptions struct {
|
| 179 | 179 |
Filters filters.Args |
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 |
+// ImageLoadResponse returns information to the client about a load process. |
|
| 183 |
+type ImageLoadResponse struct {
|
|
| 184 |
+ Body io.ReadCloser |
|
| 185 |
+ JSON bool |
|
| 186 |
+} |
|
| 187 |
+ |
|
| 182 | 188 |
// ImagePullOptions holds information to pull images. |
| 183 | 189 |
type ImagePullOptions struct {
|
| 184 | 190 |
ImageID string |