Add `ignore-push-failures` flag to `compose push`

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-03-05 13:20:13 +01:00
parent 482d1ea534
commit 62f24c7086
8 changed files with 37 additions and 12 deletions

View File

@ -48,7 +48,7 @@ func (cs *aciComposeService) Build(ctx context.Context, project *types.Project,
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }
func (cs *aciComposeService) Push(ctx context.Context, project *types.Project) error { func (cs *aciComposeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }

View File

@ -32,7 +32,7 @@ func (c *composeService) Build(ctx context.Context, project *types.Project, opti
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }
func (c *composeService) Push(ctx context.Context, project *types.Project) error { func (c *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }

View File

@ -30,7 +30,7 @@ type Service interface {
// Build executes the equivalent to a `compose build` // Build executes the equivalent to a `compose build`
Build(ctx context.Context, project *types.Project, options BuildOptions) error Build(ctx context.Context, project *types.Project, options BuildOptions) error
// Push executes the equivalent ot a `compose push` // Push executes the equivalent ot a `compose push`
Push(ctx context.Context, project *types.Project) error Push(ctx context.Context, project *types.Project, options PushOptions) error
// Pull executes the equivalent of a `compose pull` // Pull executes the equivalent of a `compose pull`
Pull(ctx context.Context, project *types.Project) error Pull(ctx context.Context, project *types.Project) error
// Create executes the equivalent to a `compose create` // Create executes the equivalent to a `compose create`
@ -133,6 +133,11 @@ type ConvertOptions struct {
Output string Output string
} }
// PushOptions group options of the Push API
type PushOptions struct {
IgnoreFailures bool
}
// KillOptions group options of the Kill API // KillOptions group options of the Kill API
type KillOptions struct { type KillOptions struct {
// Signal to send to containers // Signal to send to containers

View File

@ -22,12 +22,15 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/api/progress"
) )
type pushOptions struct { type pushOptions struct {
*projectOptions *projectOptions
composeOptions composeOptions
Ignorefailures bool
} }
func pushCommand(p *projectOptions) *cobra.Command { func pushCommand(p *projectOptions) *cobra.Command {
@ -41,6 +44,8 @@ func pushCommand(p *projectOptions) *cobra.Command {
return runPush(cmd.Context(), opts, args) return runPush(cmd.Context(), opts, args)
}, },
} }
pushCmd.Flags().BoolVar(&opts.Ignorefailures, "ignore-push-failures", false, "Push what it can and ignores images with push failures")
return pushCmd return pushCmd
} }
@ -56,7 +61,9 @@ func runPush(ctx context.Context, opts pushOptions, services []string) error {
} }
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) { _, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
return "", c.ComposeService().Push(ctx, project) return "", c.ComposeService().Push(ctx, project, compose.PushOptions{
IgnoreFailures: opts.Ignorefailures,
})
}) })
return err return err
} }

View File

@ -36,8 +36,8 @@ func (e ecsLocalSimulation) Build(ctx context.Context, project *types.Project, o
return e.compose.Build(ctx, project, options) return e.compose.Build(ctx, project, options)
} }
func (e ecsLocalSimulation) Push(ctx context.Context, project *types.Project) error { func (e ecsLocalSimulation) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
return e.compose.Push(ctx, project) return e.compose.Push(ctx, project, options)
} }
func (e ecsLocalSimulation) Pull(ctx context.Context, project *types.Project) error { func (e ecsLocalSimulation) Pull(ctx context.Context, project *types.Project) error {

View File

@ -35,7 +35,7 @@ func (b *ecsAPIService) Build(ctx context.Context, project *types.Project, optio
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }
func (b *ecsAPIService) Push(ctx context.Context, project *types.Project) error { func (b *ecsAPIService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }

View File

@ -169,7 +169,7 @@ func (s *composeService) Build(ctx context.Context, project *types.Project, opti
} }
// Push executes the equivalent ot a `compose push` // Push executes the equivalent ot a `compose push`
func (s *composeService) Push(ctx context.Context, project *types.Project) error { func (s *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
return errdefs.ErrNotImplemented return errdefs.ErrNotImplemented
} }

View File

@ -33,11 +33,12 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config" "github.com/docker/compose-cli/api/config"
"github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/api/progress"
) )
func (s *composeService) Push(ctx context.Context, project *types.Project) error { func (s *composeService) Push(ctx context.Context, project *types.Project, options compose.PushOptions) error {
configFile, err := cliconfig.Load(config.Dir(ctx)) configFile, err := cliconfig.Load(config.Dir(ctx))
if err != nil { if err != nil {
return err return err
@ -64,13 +65,25 @@ func (s *composeService) Push(ctx context.Context, project *types.Project) error
} }
service := service service := service
eg.Go(func() error { eg.Go(func() error {
return s.pullServiceImage(ctx, service, info, configFile, w) err := s.pushServiceImage(ctx, service, info, configFile, w)
if err != nil {
if !options.IgnoreFailures {
return err
}
w.Event(progress.Event{
ID: fmt.Sprintf("Pushing %s:", service.Name),
Text: fmt.Sprintf("%v", err),
Status: progress.Error,
StatusText: fmt.Sprintf("%s", err),
})
}
return nil
}) })
} }
return eg.Wait() return eg.Wait()
} }
func (s *composeService) pullServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer) error { func (s *composeService) pushServiceImage(ctx context.Context, service types.ServiceConfig, info moby.Info, configFile driver.Auth, w progress.Writer) error {
ref, err := reference.ParseNormalizedNamed(service.Image) ref, err := reference.ParseNormalizedNamed(service.Image)
if err != nil { if err != nil {
return err return err
@ -113,7 +126,7 @@ func (s *composeService) pullServiceImage(ctx context.Context, service types.Ser
if jm.Error != nil { if jm.Error != nil {
return errors.New(jm.Error.Message) return errors.New(jm.Error.Message)
} }
toPushProgressEvent("Pushing "+service.Name, jm, w) toPushProgressEvent(service.Name, jm, w)
} }
return nil return nil
} }