mirror of
https://github.com/docker/compose.git
synced 2025-04-08 17:05:13 +02:00
add dry-run support for pull command
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
9cc1613b55
commit
3f7d3c2661
@ -25,6 +25,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/docker/buildx/builder"
|
||||||
|
"github.com/docker/buildx/util/imagetools"
|
||||||
|
"github.com/docker/cli/cli/command"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/uuid"
|
"github.com/distribution/distribution/v3/uuid"
|
||||||
moby "github.com/docker/docker/api/types"
|
moby "github.com/docker/docker/api/types"
|
||||||
containerType "github.com/docker/docker/api/types/container"
|
containerType "github.com/docker/docker/api/types/container"
|
||||||
@ -52,6 +56,7 @@ type DryRunKey struct{}
|
|||||||
type DryRunClient struct {
|
type DryRunClient struct {
|
||||||
apiClient client.APIClient
|
apiClient client.APIClient
|
||||||
execs sync.Map
|
execs sync.Map
|
||||||
|
resolver *imagetools.Resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
type execDetails struct {
|
type execDetails struct {
|
||||||
@ -60,11 +65,20 @@ type execDetails struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewDryRunClient produces a DryRunClient
|
// NewDryRunClient produces a DryRunClient
|
||||||
func NewDryRunClient(apiClient client.APIClient) *DryRunClient {
|
func NewDryRunClient(apiClient client.APIClient, cli *command.DockerCli) (*DryRunClient, error) {
|
||||||
|
b, err := builder.New(cli, builder.WithSkippedValidation())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
configFile, err := b.ImageOpt()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &DryRunClient{
|
return &DryRunClient{
|
||||||
apiClient: apiClient,
|
apiClient: apiClient,
|
||||||
execs: sync.Map{},
|
execs: sync.Map{},
|
||||||
}
|
resolver: imagetools.New(configFile),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// All methods and functions which need to be overridden for dry run.
|
// All methods and functions which need to be overridden for dry run.
|
||||||
@ -129,8 +143,16 @@ func (d *DryRunClient) ImageBuild(ctx context.Context, reader io.Reader, options
|
|||||||
return moby.ImageBuildResponse{}, ErrNotImplemented
|
return moby.ImageBuildResponse{}, ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DryRunClient) ImageInspectWithRaw(ctx context.Context, imageName string) (moby.ImageInspect, []byte, error) {
|
||||||
|
return moby.ImageInspect{ID: "dryRunId"}, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DryRunClient) ImagePull(ctx context.Context, ref string, options moby.ImagePullOptions) (io.ReadCloser, error) {
|
func (d *DryRunClient) ImagePull(ctx context.Context, ref string, options moby.ImagePullOptions) (io.ReadCloser, error) {
|
||||||
return nil, ErrNotImplemented
|
if _, _, err := d.resolver.Resolve(ctx, ref); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rc := io.NopCloser(strings.NewReader(""))
|
||||||
|
return rc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DryRunClient) ImagePush(ctx context.Context, ref string, options moby.ImagePushOptions) (io.ReadCloser, error) {
|
func (d *DryRunClient) ImagePush(ctx context.Context, ref string, options moby.ImagePushOptions) (io.ReadCloser, error) {
|
||||||
@ -304,10 +326,6 @@ func (d *DryRunClient) ImageImport(ctx context.Context, source moby.ImageImportS
|
|||||||
return d.apiClient.ImageImport(ctx, source, ref, options)
|
return d.apiClient.ImageImport(ctx, source, ref, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DryRunClient) ImageInspectWithRaw(ctx context.Context, imageName string) (moby.ImageInspect, []byte, error) {
|
|
||||||
return d.apiClient.ImageInspectWithRaw(ctx, imageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DryRunClient) ImageList(ctx context.Context, options moby.ImageListOptions) ([]moby.ImageSummary, error) {
|
func (d *DryRunClient) ImageList(ctx context.Context, options moby.ImageListOptions) ([]moby.ImageSummary, error) {
|
||||||
return d.apiClient.ImageList(ctx, options)
|
return d.apiClient.ImageList(ctx, options)
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,7 @@ func (s *composeService) DryRunMode(ctx context.Context, dryRun bool) (context.C
|
|||||||
return ctx, err
|
return ctx, err
|
||||||
}
|
}
|
||||||
err = cli.Initialize(flags.NewClientOptions(), command.WithInitializeClient(func(cli *command.DockerCli) (client.APIClient, error) {
|
err = cli.Initialize(flags.NewClientOptions(), command.WithInitializeClient(func(cli *command.DockerCli) (client.APIClient, error) {
|
||||||
dryRunClient := api.NewDryRunClient(s.apiClient())
|
return api.NewDryRunClient(s.apiClient(), cli)
|
||||||
return dryRunClient, nil
|
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctx, err
|
return ctx, err
|
||||||
|
@ -130,6 +130,13 @@ func (s *composeService) pull(ctx context.Context, project *types.Project, opts
|
|||||||
mustBuild = append(mustBuild, service.Name)
|
mustBuild = append(mustBuild, service.Name)
|
||||||
}
|
}
|
||||||
if !opts.IgnoreFailures && service.Build == nil {
|
if !opts.IgnoreFailures && service.Build == nil {
|
||||||
|
if s.dryRun {
|
||||||
|
w.Event(progress.Event{
|
||||||
|
ID: service.Name,
|
||||||
|
Status: progress.Error,
|
||||||
|
Text: fmt.Sprintf(" - Pull error for image: %s", service.Image),
|
||||||
|
})
|
||||||
|
}
|
||||||
// fail fast if image can't be pulled nor built
|
// fail fast if image can't be pulled nor built
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user