mirror of https://github.com/docker/compose.git
Merge pull request #8668 from ndeloof/ignore_orphans
add support for COMPOSE_IGNORE_ORPHANS
This commit is contained in:
commit
1ec997270d
|
@ -31,6 +31,7 @@ type createOptions struct {
|
||||||
Build bool
|
Build bool
|
||||||
noBuild bool
|
noBuild bool
|
||||||
removeOrphans bool
|
removeOrphans bool
|
||||||
|
ignoreOrphans bool
|
||||||
forceRecreate bool
|
forceRecreate bool
|
||||||
noRecreate bool
|
noRecreate bool
|
||||||
recreateDeps bool
|
recreateDeps bool
|
||||||
|
@ -57,6 +58,7 @@ func createCommand(p *projectOptions, backend api.Service) *cobra.Command {
|
||||||
RunE: p.WithProject(func(ctx context.Context, project *types.Project) error {
|
RunE: p.WithProject(func(ctx context.Context, project *types.Project) error {
|
||||||
return backend.Create(ctx, project, api.CreateOptions{
|
return backend.Create(ctx, project, api.CreateOptions{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
|
IgnoreOrphans: opts.ignoreOrphans,
|
||||||
Recreate: opts.recreateStrategy(),
|
Recreate: opts.recreateStrategy(),
|
||||||
RecreateDependencies: opts.dependenciesRecreateStrategy(),
|
RecreateDependencies: opts.dependenciesRecreateStrategy(),
|
||||||
Inherit: !opts.noInherit,
|
Inherit: !opts.noInherit,
|
||||||
|
|
|
@ -120,6 +120,11 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
|
||||||
return nil
|
return nil
|
||||||
}),
|
}),
|
||||||
RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
|
RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
|
||||||
|
ignore := project.Environment["COMPOSE_IGNORE_ORPHANS"]
|
||||||
|
create.ignoreOrphans = strings.ToLower(ignore) == "true"
|
||||||
|
if create.ignoreOrphans && create.removeOrphans {
|
||||||
|
return fmt.Errorf("COMPOSE_IGNORE_ORPHANS and --remove-orphans cannot be combined")
|
||||||
|
}
|
||||||
return runUp(ctx, backend, create, up, project, services)
|
return runUp(ctx, backend, create, up, project, services)
|
||||||
}),
|
}),
|
||||||
ValidArgsFunction: serviceCompletion(p),
|
ValidArgsFunction: serviceCompletion(p),
|
||||||
|
@ -177,6 +182,7 @@ func runUp(ctx context.Context, backend api.Service, createOptions createOptions
|
||||||
create := api.CreateOptions{
|
create := api.CreateOptions{
|
||||||
Services: services,
|
Services: services,
|
||||||
RemoveOrphans: createOptions.removeOrphans,
|
RemoveOrphans: createOptions.removeOrphans,
|
||||||
|
IgnoreOrphans: createOptions.ignoreOrphans,
|
||||||
Recreate: createOptions.recreateStrategy(),
|
Recreate: createOptions.recreateStrategy(),
|
||||||
RecreateDependencies: createOptions.dependenciesRecreateStrategy(),
|
RecreateDependencies: createOptions.dependenciesRecreateStrategy(),
|
||||||
Inherit: !createOptions.noInherit,
|
Inherit: !createOptions.noInherit,
|
||||||
|
|
|
@ -100,6 +100,8 @@ type CreateOptions struct {
|
||||||
Services []string
|
Services []string
|
||||||
// Remove legacy containers for services that are not defined in the project
|
// Remove legacy containers for services that are not defined in the project
|
||||||
RemoveOrphans bool
|
RemoveOrphans bool
|
||||||
|
// Ignore legacy containers for services that are not defined in the project
|
||||||
|
IgnoreOrphans bool
|
||||||
// Recreate define the strategy to apply on existing containers
|
// Recreate define the strategy to apply on existing containers
|
||||||
Recreate string
|
Recreate string
|
||||||
// RecreateDependencies define the strategy to apply on dependencies services
|
// RecreateDependencies define the strategy to apply on dependencies services
|
||||||
|
|
|
@ -89,7 +89,7 @@ func (s *composeService) create(ctx context.Context, project *types.Project, opt
|
||||||
allServiceNames = append(allServiceNames, service.Name)
|
allServiceNames = append(allServiceNames, service.Name)
|
||||||
}
|
}
|
||||||
orphans := observedState.filter(isNotService(allServiceNames...))
|
orphans := observedState.filter(isNotService(allServiceNames...))
|
||||||
if len(orphans) > 0 {
|
if len(orphans) > 0 && !options.IgnoreOrphans {
|
||||||
if options.RemoveOrphans {
|
if options.RemoveOrphans {
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
err := s.removeContainers(ctx, w, orphans, nil, false)
|
err := s.removeContainers(ctx, w, orphans, nil, false)
|
||||||
|
|
Loading…
Reference in New Issue