mirror of https://github.com/docker/compose.git
Merge pull request #10413 from glours/dry-run-create-support
add dry-run support to create command
This commit is contained in:
commit
6a37428491
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue