Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
build = &bo
}

if createOpts.AssumeYes {
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
}

backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
if err != nil {
return err
Expand All @@ -124,7 +128,6 @@ func runCreate(ctx context.Context, dockerCli command.Cli, backendOptions *Backe
Inherit: !createOpts.noInherit,
Timeout: createOpts.GetTimeout(),
QuietPull: createOpts.quietPull,
AssumeYes: createOpts.AssumeYes,
})
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back
return errors.New("cannot publish compose file with local includes")
}

if opts.assumeYes {
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
}
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
if err != nil {
return err
Expand All @@ -87,6 +90,5 @@ func runPublish(ctx context.Context, dockerCli command.Cli, backendOptions *Back
Application: opts.app,
OCIVersion: api.OCIVersion(opts.ociVersion),
WithEnvironment: opts.withEnvironment,
AssumeYes: opts.assumeYes,
})
}
5 changes: 4 additions & 1 deletion cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ func runUp(
Inherit: !createOptions.noInherit,
Timeout: createOptions.GetTimeout(),
QuietPull: createOptions.quietPull,
AssumeYes: createOptions.AssumeYes,
}

if createOptions.AssumeYes {
backendOptions.Options = append(backendOptions.Options, compose.WithPrompt(compose.AlwaysOkPrompt()))
}

backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
Expand Down
3 changes: 0 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ type CreateOptions struct {
Timeout *time.Duration
// QuietPull makes the pulling process quiet
QuietPull bool
// AssumeYes assume "yes" as answer to all prompts and run non-interactively
AssumeYes bool
}

// StartOptions group options of the Start API
Expand Down Expand Up @@ -447,7 +445,6 @@ type PublishOptions struct {
Application bool
WithEnvironment bool

AssumeYes bool
OCIVersion OCIVersion
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ func WithDryRun(s *composeService) error {

type Prompt func(message string, defaultValue bool) (bool, error)

// AlwaysOkPrompt returns a Prompt implementation that always returns true without user interaction.
func AlwaysOkPrompt() Prompt {
return func(message string, defaultValue bool) (bool, error) {
return true, nil
}
}

// WithEventProcessor configure component to get notified on Compose operation and progress events.
// Typically used to configure a progress UI
func WithEventProcessor(bus progress.EventProcessor) Option {
Expand Down
19 changes: 8 additions & 11 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
return err
}

volumes, err := s.ensureProjectVolumes(ctx, project, options.AssumeYes)
volumes, err := s.ensureProjectVolumes(ctx, project)
if err != nil {
return err
}
Expand Down Expand Up @@ -150,13 +150,13 @@ func (s *composeService) ensureNetworks(ctx context.Context, project *types.Proj
return networks, nil
}

func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project, assumeYes bool) (map[string]string, error) {
func (s *composeService) ensureProjectVolumes(ctx context.Context, project *types.Project) (map[string]string, error) {
ids := map[string]string{}
for k, volume := range project.Volumes {
volume.CustomLabels = volume.CustomLabels.Add(api.VolumeLabel, k)
volume.CustomLabels = volume.CustomLabels.Add(api.ProjectLabel, project.Name)
volume.CustomLabels = volume.CustomLabels.Add(api.VersionLabel, api.ComposeVersion)
id, err := s.ensureVolume(ctx, k, volume, project, assumeYes)
id, err := s.ensureVolume(ctx, k, volume, project)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1529,7 +1529,7 @@ func (s *composeService) resolveExternalNetwork(ctx context.Context, n *types.Ne
}
}

func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project, assumeYes bool) (string, error) {
func (s *composeService) ensureVolume(ctx context.Context, name string, volume types.VolumeConfig, project *types.Project) (string, error) {
inspected, err := s.apiClient().VolumeInspect(ctx, volume.Name)
if err != nil {
if !errdefs.IsNotFound(err) {
Expand Down Expand Up @@ -1561,13 +1561,10 @@ func (s *composeService) ensureVolume(ctx context.Context, name string, volume t
}
actual, ok := inspected.Labels[api.ConfigHashLabel]
if ok && actual != expected {
confirm := assumeYes
if !assumeYes {
msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name)
confirm, err = s.prompt(msg, false)
if err != nil {
return "", err
}
msg := fmt.Sprintf("Volume %q exists but doesn't match configuration in compose file. Recreate (data will be lost)?", volume.Name)
confirm, err := s.prompt(msg, false)
if err != nil {
return "", err
}
if confirm {
err = s.removeDivergedVolume(ctx, name, volume, project)
Expand Down
3 changes: 0 additions & 3 deletions pkg/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,6 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp
if ok, err := s.checkOnlyBuildSection(project); !ok || err != nil {
return false, err
}
if options.AssumeYes {
return true, nil
}
bindMounts := s.checkForBindMount(project)
if len(bindMounts) > 0 {
b := strings.Builder{}
Expand Down