From 4434cea53567353d0086129cbfbc8c26ca019bf0 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 8 Mar 2023 10:49:46 +0100 Subject: [PATCH] add dry-run support for push command Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/api/dryrunclient.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/api/dryrunclient.go b/pkg/api/dryrunclient.go index f2b1ec54f..edf4a965d 100644 --- a/pkg/api/dryrunclient.go +++ b/pkg/api/dryrunclient.go @@ -17,7 +17,9 @@ package api import ( + "bytes" "context" + "encoding/json" "fmt" "io" "net" @@ -40,6 +42,7 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" + "github.com/docker/docker/pkg/jsonmessage" specs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) @@ -156,7 +159,25 @@ func (d *DryRunClient) ImagePull(ctx context.Context, ref string, options moby.I } func (d *DryRunClient) ImagePush(ctx context.Context, ref string, options moby.ImagePushOptions) (io.ReadCloser, error) { - return nil, ErrNotImplemented + if _, _, err := d.resolver.Resolve(ctx, ref); err != nil { + return nil, err + } + jsonMessage, err := json.Marshal(&jsonmessage.JSONMessage{ + Status: "Pushed", + Progress: &jsonmessage.JSONProgress{ + Current: 100, + Total: 100, + Start: 0, + HideCounts: false, + Units: "Mb", + }, + ID: ref, + }) + if err != nil { + return nil, err + } + rc := io.NopCloser(bytes.NewReader(jsonMessage)) + return rc, nil } func (d *DryRunClient) ImageRemove(ctx context.Context, imageName string, options moby.ImageRemoveOptions) ([]moby.ImageDeleteResponseItem, error) {