Skip to content

Commit 6a37428

Browse files
authored
Merge pull request docker#10413 from glours/dry-run-create-support
add dry-run support to create command
2 parents 449a46a + b83edbd commit 6a37428

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

pkg/api/dryrunclient.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"io"
2525
"net"
2626
"net/http"
27+
"runtime"
2728
"strings"
2829
"sync"
2930

@@ -84,6 +85,12 @@ func NewDryRunClient(apiClient client.APIClient, cli *command.DockerCli) (*DryRu
8485
}, nil
8586
}
8687

88+
func getCallingFunction() string {
89+
pc, _, _, _ := runtime.Caller(2)
90+
fullName := runtime.FuncForPC(pc).Name()
91+
return fullName[strings.LastIndex(fullName, ".")+1:]
92+
}
93+
8794
// All methods and functions which need to be overridden for dry run.
8895

8996
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
162169
}
163170

164171
func (d *DryRunClient) ImageInspectWithRaw(ctx context.Context, imageName string) (moby.ImageInspect, []byte, error) {
165-
return moby.ImageInspect{ID: "dryRunId"}, nil, nil
172+
caller := getCallingFunction()
173+
switch caller {
174+
case "pullServiceImage", "buildContainerVolumes":
175+
return moby.ImageInspect{ID: "dryRunId"}, nil, nil
176+
default:
177+
return d.apiClient.ImageInspectWithRaw(ctx, imageName)
178+
}
179+
166180
}
167181

168182
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
204218
}
205219

206220
func (d *DryRunClient) NetworkCreate(ctx context.Context, name string, options moby.NetworkCreate) (moby.NetworkCreateResponse, error) {
207-
return moby.NetworkCreateResponse{}, ErrNotImplemented
221+
return moby.NetworkCreateResponse{
222+
ID: name,
223+
Warning: "",
224+
}, nil
208225
}
209226

210227
func (d *DryRunClient) NetworkDisconnect(ctx context.Context, networkName, container string, force bool) error {

pkg/compose/build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
7474
return nil
7575
}
7676

77+
//TODO:glours - condition to be removed when dry-run support of build will be implemented.
78+
if s.dryRun {
79+
builder := "buildkit"
80+
if !buildkitEnabled {
81+
builder = "legacy builder"
82+
}
83+
fmt.Printf("%sBuilding image %s with %s\n", api.DRYRUN_PREFIX, service.Image, builder)
84+
return nil
85+
}
86+
7787
if !buildkitEnabled {
7888
if service.Build.Args == nil {
7989
service.Build.Args = args

0 commit comments

Comments
 (0)