mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
Skip updating containers where no local image info can be retrieved (#612)
* Revert "Image of running container no longer needed locally (#571)"
This reverts commit 6da66fb312
.
* Update client.go
* fix: skip updating when no image info can be retrieved
This will allow watchtower to continue even though the image info for a
container cannot be retrieved. If this happens one warning will be emitted
and the container will be skipped, unless NoRestart or OnlyMonitor is supplied
This commit is contained in:
parent
cde438996a
commit
5efb249a86
3 changed files with 22 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
package actions
|
package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"github.com/containrrr/watchtower/internal/util"
|
"github.com/containrrr/watchtower/internal/util"
|
||||||
"github.com/containrrr/watchtower/pkg/container"
|
"github.com/containrrr/watchtower/pkg/container"
|
||||||
"github.com/containrrr/watchtower/pkg/lifecycle"
|
"github.com/containrrr/watchtower/pkg/lifecycle"
|
||||||
|
@ -25,11 +26,13 @@ func Update(client container.Client, params types.UpdateParams) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, container := range containers {
|
for i, targetContainer := range containers {
|
||||||
stale, err := client.IsContainerStale(container)
|
stale, err := client.IsContainerStale(targetContainer)
|
||||||
|
if stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.HasImageInfo() {
|
||||||
|
err = errors.New("no available image info")
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Unable to update container %s. Proceeding to next.", containers[i].Name())
|
log.Infof("Unable to update container %q: %v. Proceeding to next.", containers[i].Name(), err)
|
||||||
log.Debug(err)
|
|
||||||
stale = false
|
stale = false
|
||||||
}
|
}
|
||||||
containers[i].Stale = stale
|
containers[i].Stale = stale
|
||||||
|
@ -89,12 +92,12 @@ func stopStaleContainer(container container.Container, client container.Client,
|
||||||
func restartContainersInSortedOrder(containers []container.Container, client container.Client, params types.UpdateParams) {
|
func restartContainersInSortedOrder(containers []container.Container, client container.Client, params types.UpdateParams) {
|
||||||
imageIDs := make(map[string]bool)
|
imageIDs := make(map[string]bool)
|
||||||
|
|
||||||
for _, container := range containers {
|
for _, staleContainer := range containers {
|
||||||
if !container.Stale {
|
if !staleContainer.Stale {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
restartStaleContainer(container, client, params)
|
restartStaleContainer(staleContainer, client, params)
|
||||||
imageIDs[container.ImageID()] = true
|
imageIDs[staleContainer.ImageID()] = true
|
||||||
}
|
}
|
||||||
if params.Cleanup {
|
if params.Cleanup {
|
||||||
for imageID := range imageIDs {
|
for imageID := range imageIDs {
|
||||||
|
|
|
@ -119,8 +119,12 @@ func (client dockerClient) GetContainer(containerID string) (Container, error) {
|
||||||
return Container{}, err
|
return Container{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
container := Container{containerInfo: &containerInfo}
|
imageInfo, _, err := client.api.ImageInspectWithRaw(bg, containerInfo.Image)
|
||||||
return container, nil
|
if err != nil {
|
||||||
|
log.Warnf("Failed to retrieve container image info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Container{containerInfo: &containerInfo, imageInfo: &imageInfo}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client dockerClient) StopContainer(c Container, timeout time.Duration) error {
|
func (client dockerClient) StopContainer(c Container, timeout time.Duration) error {
|
||||||
|
|
|
@ -221,3 +221,8 @@ func (c Container) hostConfig() *dockercontainer.HostConfig {
|
||||||
|
|
||||||
return hostConfig
|
return hostConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasImageInfo returns whether image information could be retrieved for the container
|
||||||
|
func (c Container) HasImageInfo() bool {
|
||||||
|
return c.imageInfo != nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue