mirror of
https://github.com/docker/compose.git
synced 2025-07-18 03:04:25 +02:00
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
|
RemoveOrphans bool
|
||||||
// Recreate define the strategy to apply on existing containers
|
// Recreate define the strategy to apply on existing containers
|
||||||
Recreate string
|
Recreate string
|
||||||
|
// Inherit reuse anonymous volumes from previous container
|
||||||
|
Inherit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartOptions group options of the Start API
|
// StartOptions group options of the Start API
|
||||||
|
@ -65,6 +65,7 @@ type upOptions struct {
|
|||||||
timeChanged bool
|
timeChanged bool
|
||||||
timeout int
|
timeout int
|
||||||
noDeps bool
|
noDeps bool
|
||||||
|
noInherit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o upOptions) recreateStrategy() string {
|
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.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.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.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
|
return upCmd
|
||||||
@ -192,6 +194,7 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||||||
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
Recreate: opts.recreateStrategy(),
|
Recreate: opts.recreateStrategy(),
|
||||||
|
Inherit: !opts.noInherit,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -85,7 +85,7 @@ func (s *composeService) ensureScale(ctx context.Context, project *types.Project
|
|||||||
return eg, actual, nil
|
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)
|
eg, actual, err := s.ensureScale(ctx, project, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -106,7 +106,7 @@ func (s *composeService) ensureService(ctx context.Context, project *types.Proje
|
|||||||
diverged := container.Labels[configHashLabel] != expected
|
diverged := container.Labels[configHashLabel] != expected
|
||||||
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
if diverged || recreate == compose.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
return s.recreateContainer(ctx, project, service, container)
|
return s.recreateContainer(ctx, project, service, container, inherit)
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ func (s *composeService) createContainer(ctx context.Context, project *types.Pro
|
|||||||
return nil
|
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 := progress.ContextWriter(ctx)
|
||||||
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Recreate"))
|
w.Event(progress.NewEvent(getContainerProgressName(container), progress.Working, "Recreate"))
|
||||||
err := s.apiClient.ContainerStop(ctx, container.ID, nil)
|
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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -263,13 +268,13 @@ func (s *composeService) restartContainer(ctx context.Context, container moby.Co
|
|||||||
return nil
|
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 {
|
autoRemove bool) error {
|
||||||
cState, err := GetContextContainerState(ctx)
|
cState, err := GetContextContainerState(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ func (s *composeService) Create(ctx context.Context, project *types.Project, opt
|
|||||||
prepareNetworkMode(project)
|
prepareNetworkMode(project)
|
||||||
|
|
||||||
return InDependencyOrder(ctx, project, func(c context.Context, service types.ServiceConfig) error {
|
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…
x
Reference in New Issue
Block a user