Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow up --watch --prune #12415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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")
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,
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