Skip to content
Closed
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
6 changes: 6 additions & 0 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type upOptions struct {
wait bool
waitTimeout int
watch bool
prune bool
navigationMenu bool
navigationMenuChanged bool
}
Expand Down Expand Up @@ -170,6 +171,7 @@ func upCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *c
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "Maximum duration in seconds to wait for the project to be running|healthy")
flags.BoolVarP(&up.watch, "watch", "w", false, "Watch source code and rebuild/refresh containers when files are updated.")
flags.BoolVar(&up.prune, "prune", false, "Prune dangling images on rebuild")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder: is there any benefits not pruning those ? Shall we just make this the default ? Then do we need a flag ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I agree
@remcokranenburg do you mind adapting your PR to prune by default? We just need to keep it for the watch command itself to let users who want it to choose the option of keeping dangling images

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Would you also like to prune by default for the watch command? That might be more consistent, thus less surprising.

By keeping the flag, it should be possible to disable in either up or watch with --prune=0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up already has so much flags we'd prefer not to have more. For those who really want to keep dangling images (?) watch --prune=false could be a reasonable workaround

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'm aligned with @ndeloof on this one, just keep the --prune flag for the watch command
BTW thank you for doing it 🙏

flags.BoolVar(&up.navigationMenu, "menu", false, "Enable interactive shortcuts when running attached. Incompatible with --detach. Can also be enable/disable by setting COMPOSE_MENU environment var.")

return upCmd
Expand Down Expand Up @@ -207,6 +209,9 @@ func validateFlags(up *upOptions, create *createOptions) error {
if create.noBuild && up.watch {
return fmt.Errorf("--no-build and --watch are incompatible")
}
if !up.watch && up.prune {
return fmt.Errorf("--prune can only be used with --watch")
}
return nil
}

Expand Down Expand Up @@ -310,6 +315,7 @@ func runUp(
Wait: upOptions.wait,
WaitTimeout: timeout,
Watch: upOptions.watch,
Prune: upOptions.prune,
Comment on lines 317 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should not pass directly WatchOptions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should just drop the api package and get CLI options used by composeService

Services: services,
NavigationMenu: upOptions.navigationMenu && ui.Mode != "plain",
},
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type StartOptions struct {
// Services passed in the command line to be started
Services []string
Watch bool
Prune bool
NavigationMenu bool
}

Expand Down
1 change: 1 addition & 0 deletions pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
return s.watch(ctx, doneCh, project, options.Start.Services, api.WatchOptions{
Build: &buildOpts,
LogTo: options.Start.Attach,
Prune: options.Start.Prune,
})
})
}
Expand Down
Loading