Merge pull request #10404 from glours/dry-run-run-support

add dry-run support to run command
This commit is contained in:
Milas Bowman 2023-03-27 17:42:28 -04:00 committed by GitHub
commit 67c9ecb4f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 10 deletions

View File

@ -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)
}