diff --git a/pkg/api/dryrunclient.go b/pkg/api/dryrunclient.go index 32722a484..0f2663a7b 100644 --- a/pkg/api/dryrunclient.go +++ b/pkg/api/dryrunclient.go @@ -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) { - return moby.ImageInspect{ID: "dryRunId"}, nil, nil + 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 { diff --git a/pkg/compose/build.go b/pkg/compose/build.go index efc6e26a4..5c3fd4a37 100644 --- a/pkg/compose/build.go +++ b/pkg/compose/build.go @@ -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 { service.Build.Args = service.Build.Args.OverrideBy(args) id, err := s.doBuildClassic(ctx, service)