mirror of
https://github.com/docker/compose.git
synced 2025-07-16 18:24:26 +02:00
Merge pull request #9261 from ndeloof/recreate_on_image_updated
recreate container after image has been rebuilt/pulled
This commit is contained in:
commit
dc6097d1f0
@ -188,6 +188,15 @@ func (s *composeService) getLocalImagesDigests(ctx context.Context, project *typ
|
|||||||
for name, info := range imgs {
|
for name, info := range imgs {
|
||||||
images[name] = info.ID
|
images[name] = info.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, s := range project.Services {
|
||||||
|
imgName := getImageName(s, project.Name)
|
||||||
|
digest, ok := images[imgName]
|
||||||
|
if ok {
|
||||||
|
s.CustomLabels[api.ImageDigestLabel] = digest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return images, nil
|
return images, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,17 +189,11 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if recreate == api.RecreateNever {
|
mustRecreate, err := mustRecreate(service, container, recreate)
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Re-create diverged containers
|
|
||||||
configHash, err := ServiceHash(service)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
name := getContainerProgressName(container)
|
if mustRecreate {
|
||||||
diverged := container.Labels[api.ConfigHashLabel] != configHash
|
|
||||||
if diverged || recreate == api.RecreateForce || service.Extensions[extLifecycle] == forceRecreate {
|
|
||||||
i, container := i, container
|
i, container := i, container
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
recreated, err := c.service.recreateContainer(ctx, project, service, container, inherit, timeout)
|
recreated, err := c.service.recreateContainer(ctx, project, service, container, inherit, timeout)
|
||||||
@ -211,6 +205,7 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
|
|||||||
|
|
||||||
// Enforce non-diverged containers are running
|
// Enforce non-diverged containers are running
|
||||||
w := progress.ContextWriter(ctx)
|
w := progress.ContextWriter(ctx)
|
||||||
|
name := getContainerProgressName(container)
|
||||||
switch container.State {
|
switch container.State {
|
||||||
case ContainerRunning:
|
case ContainerRunning:
|
||||||
w.Event(progress.RunningEvent(name))
|
w.Event(progress.RunningEvent(name))
|
||||||
@ -249,6 +244,22 @@ func (c *convergence) ensureService(ctx context.Context, project *types.Project,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mustRecreate(expected types.ServiceConfig, actual moby.Container, policy string) (bool, error) {
|
||||||
|
if policy == api.RecreateNever {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
if policy == api.RecreateForce || expected.Extensions[extLifecycle] == forceRecreate {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
configHash, err := ServiceHash(expected)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
configChanged := actual.Labels[api.ConfigHashLabel] != configHash
|
||||||
|
imageUpdated := actual.Labels[api.ImageDigestLabel] != expected.CustomLabels[api.ImageDigestLabel]
|
||||||
|
return configChanged || imageUpdated, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getContainerName(projectName string, service types.ServiceConfig, number int) string {
|
func getContainerName(projectName string, service types.ServiceConfig, number int) string {
|
||||||
name := strings.Join([]string{projectName, service.Name, strconv.Itoa(number)}, Separator)
|
name := strings.Join([]string{projectName, service.Name, strconv.Itoa(number)}, Separator)
|
||||||
if service.ContainerName != "" {
|
if service.ContainerName != "" {
|
||||||
|
@ -93,7 +93,6 @@ func (s *composeService) getImages(ctx context.Context, images []string) (map[st
|
|||||||
tag := ""
|
tag := ""
|
||||||
repository := ""
|
repository := ""
|
||||||
if len(inspect.RepoTags) > 0 {
|
if len(inspect.RepoTags) > 0 {
|
||||||
|
|
||||||
repotag := strings.Split(inspect.RepoTags[0], ":")
|
repotag := strings.Split(inspect.RepoTags[0], ":")
|
||||||
repository = repotag[0]
|
repository = repotag[0]
|
||||||
if len(repotag) > 1 {
|
if len(repotag) > 1 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user