From 72a61c060270194260251bf48c2c984d471db788 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Fri, 24 Mar 2023 18:21:19 +0100 Subject: [PATCH] add dry-run support to run command Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/api/dryrunclient.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/pkg/api/dryrunclient.go b/pkg/api/dryrunclient.go index edf4a965d..32722a484 100644 --- a/pkg/api/dryrunclient.go +++ b/pkg/api/dryrunclient.go @@ -87,12 +87,27 @@ func NewDryRunClient(apiClient client.APIClient, cli *command.DockerCli) (*DryRu // All methods and functions which need to be overridden for dry run. func (d *DryRunClient) ContainerAttach(ctx context.Context, container string, options moby.ContainerAttachOptions) (moby.HijackedResponse, error) { - return moby.HijackedResponse{}, ErrNotImplemented + return moby.HijackedResponse{}, errors.New("interactive run is not supported in dry-run mode") } func (d *DryRunClient) ContainerCreate(ctx context.Context, config *containerType.Config, hostConfig *containerType.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (containerType.CreateResponse, error) { - return containerType.CreateResponse{}, ErrNotImplemented + return containerType.CreateResponse{ID: "dryRunId"}, nil +} + +func (d *DryRunClient) ContainerInspect(ctx context.Context, container string) (moby.ContainerJSON, error) { + containerJSON, err := d.apiClient.ContainerInspect(ctx, container) + if err != nil { + return moby.ContainerJSON{ + ContainerJSONBase: &moby.ContainerJSONBase{ + ID: "dryRunId", + }, + Mounts: nil, + Config: &containerType.Config{}, + NetworkSettings: &moby.NetworkSettings{}, + }, nil + } + return containerJSON, err } func (d *DryRunClient) ContainerKill(ctx context.Context, container, signal string) error { @@ -108,7 +123,7 @@ func (d *DryRunClient) ContainerRemove(ctx context.Context, container string, op } func (d *DryRunClient) ContainerRename(ctx context.Context, container, newContainerName string) error { - return ErrNotImplemented + return nil } func (d *DryRunClient) ContainerRestart(ctx context.Context, container string, options containerType.StopOptions) error { @@ -116,7 +131,7 @@ func (d *DryRunClient) ContainerRestart(ctx context.Context, container string, o } func (d *DryRunClient) ContainerStart(ctx context.Context, container string, options moby.ContainerStartOptions) error { - return ErrNotImplemented + return nil } func (d *DryRunClient) ContainerStop(ctx context.Context, container string, options containerType.StopOptions) error { @@ -185,7 +200,7 @@ func (d *DryRunClient) ImageRemove(ctx context.Context, imageName string, option } func (d *DryRunClient) NetworkConnect(ctx context.Context, networkName, container string, config *network.EndpointSettings) error { - return ErrNotImplemented + return nil } func (d *DryRunClient) NetworkCreate(ctx context.Context, name string, options moby.NetworkCreate) (moby.NetworkCreateResponse, error) { @@ -193,7 +208,7 @@ func (d *DryRunClient) NetworkCreate(ctx context.Context, name string, options m } func (d *DryRunClient) NetworkDisconnect(ctx context.Context, networkName, container string, force bool) error { - return ErrNotImplemented + return nil } func (d *DryRunClient) NetworkRemove(ctx context.Context, networkName string) error { @@ -275,10 +290,6 @@ func (d *DryRunClient) ContainerExport(ctx context.Context, container string) (i return d.apiClient.ContainerExport(ctx, container) } -func (d *DryRunClient) ContainerInspect(ctx context.Context, container string) (moby.ContainerJSON, error) { - return d.apiClient.ContainerInspect(ctx, container) -} - func (d *DryRunClient) ContainerInspectWithRaw(ctx context.Context, container string, getSize bool) (moby.ContainerJSON, []byte, error) { return d.apiClient.ContainerInspectWithRaw(ctx, container, getSize) }