mirror of https://github.com/docker/compose.git
Merge pull request #1376 from docker/renews_anon
introduce --renew-anon-volumes
This commit is contained in:
commit
7175a266c1
|
@ -71,6 +71,8 @@ type CreateOptions struct {
|
|||
RemoveOrphans bool
|
||||
// Recreate define the strategy to apply on existing containers
|
||||
Recreate string
|
||||
// Inherit reuse anonymous volumes from previous container
|
||||
Inherit bool
|
||||
}
|
||||
|
||||
// StartOptions group options of the Start API
|
||||
|
|
|
@ -65,6 +65,7 @@ type upOptions struct {
|
|||
timeChanged bool
|
||||
timeout int
|
||||
noDeps bool
|
||||
noInherit bool
|
||||
}
|
||||
|
||||
func (o upOptions) recreateStrategy() string {
|
||||
|
@ -129,6 +130,7 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
|||
flags.StringVar(&opts.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
|
||||
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.")
|
||||
flags.BoolVar(&opts.noDeps, "no-deps", false, "Don't start linked services.")
|
||||
flags.BoolVarP(&opts.noInherit, "renew-anon-volumes", "V", false, "Recreate anonymous volumes instead of retrieving data from the previous containers.")
|
||||
}
|
||||
|
||||
return upCmd
|
||||
|
@ -192,6 +194,7 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
||||
RemoveOrphans: opts.removeOrphans,
|
||||
Recreate: opts.recreateStrategy(),
|
||||
Inherit: !opts.noInherit,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -85,7 +85,7 @@ func (s *composeService) ensureScale(ctx context.Context, project *types.Project
|
|||
return eg, actual, nil
|
||||
}
|
||||
|
||||
func (s *composeService) ensureService(ctx context.Context, project *types.Project, service types.ServiceConfig, recreate string) error {
|
||||
func (s *composeService) ensureService(ctx context.Context, project *types.Project, service types.ServiceConfig, recreate string, inherit bool) error {
|
||||
eg, actual, err := s.ensureScale(ctx, project, service)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -106,7 +106,7 @@ func (s *composeService) ensureService(ctx context.Context, project *types.Proje
|
|||
diverged := container.Labels[configHashLabel] != expected
|
||||
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
||||
eg.Go(func() error {
|
||||
return s.recreateContainer(ctx, project, service, container)
|
||||
return s.recreateContainer(ctx, project, service, container, inherit)
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, container moby.Container) error {
|
||||
func (s *composeService) recreateContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, container moby.Container, inherit bool) error {
|
||||
w := progress.ContextWriter(ctx)
|
||||
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Recreate"))
|
||||
err := s.apiClient.ContainerStop(ctx, container.ID, nil)
|
||||
|
@ -226,7 +226,12 @@ func (s *composeService) recreateContainer(ctx context.Context, project *types.P
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.createMobyContainer(ctx, project, service, name, number, &container, false)
|
||||
|
||||
var inherited *moby.Container
|
||||
if inherit {
|
||||
inherited = &container
|
||||
}
|
||||
err = s.createMobyContainer(ctx, project, service, name, number, inherited, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -263,13 +268,13 @@ func (s *composeService) restartContainer(ctx context.Context, container moby.Co
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *composeService) createMobyContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, container *moby.Container,
|
||||
func (s *composeService) createMobyContainer(ctx context.Context, project *types.Project, service types.ServiceConfig, name string, number int, inherit *moby.Container,
|
||||
autoRemove bool) error {
|
||||
cState, err := GetContextContainerState(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
containerConfig, hostConfig, networkingConfig, err := s.getCreateOptions(ctx, project, service, number, container, autoRemove)
|
||||
containerConfig, hostConfig, networkingConfig, err := s.getCreateOptions(ctx, project, service, number, inherit, autoRemove)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ func (s *composeService) Create(ctx context.Context, project *types.Project, opt
|
|||
prepareNetworkMode(project)
|
||||
|
||||
return InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
|
||||
return s.ensureService(c, project, service, opts.Recreate)
|
||||
return s.ensureService(c, project, service, opts.Recreate, opts.Inherit)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue