Merge pull request #10413 from glours/dry-run-create-support

add dry-run support to create command
This commit is contained in:
Guillaume Lours 2023-04-03 18:25:55 +02:00 committed by GitHub
commit 6a37428491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import (
"io"
"net"
"net/http"
"runtime"
"strings"
"sync"
@ -84,6 +85,12 @@ func NewDryRunClient(apiClient client.APIClient, cli *command.DockerCli) (*DryRu
}, nil
}
func getCallingFunction() string {
pc, _, _, _ := runtime.Caller(2)
fullName := runtime.FuncForPC(pc).Name()
return fullName[strings.LastIndex(fullName, ".")+1:]
}
// 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) {
@ -162,7 +169,14 @@ func (d *DryRunClient) ImageBuild(ctx context.Context, reader io.Reader, options
}
func (d *DryRunClient) ImageInspectWithRaw(ctx context.Context, imageName string) (moby.ImageInspect, []byte, error) {
caller := getCallingFunction()
switch caller {
case "pullServiceImage", "buildContainerVolumes":
return moby.ImageInspect{ID: "dryRunId"}, nil, nil
default:
return d.apiClient.ImageInspectWithRaw(ctx, imageName)
}
}
func (d *DryRunClient) ImagePull(ctx context.Context, ref string, options moby.ImagePullOptions) (io.ReadCloser, error) {
@ -204,7 +218,10 @@ func (d *DryRunClient) NetworkConnect(ctx context.Context, networkName, containe
}
func (d *DryRunClient) NetworkCreate(ctx context.Context, name string, options moby.NetworkCreate) (moby.NetworkCreateResponse, error) {
return moby.NetworkCreateResponse{}, ErrNotImplemented
return moby.NetworkCreateResponse{
ID: name,
Warning: "",
}, nil
}
func (d *DryRunClient) NetworkDisconnect(ctx context.Context, networkName, container string, force bool) error {

View File

@ -74,6 +74,16 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
return nil
}
//TODO:glours - condition to be removed when dry-run support of build will be implemented.
if s.dryRun {
builder := "buildkit"
if !buildkitEnabled {
builder = "legacy builder"
}
fmt.Printf("%sBuilding image %s with %s\n", api.DRYRUN_PREFIX, service.Image, builder)
return nil
}
if !buildkitEnabled {
if service.Build.Args == nil {
service.Build.Args = args