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:
nils måsén 2020-08-18 20:55:35 +02:00 committed by GitHub
parent cde438996a
commit 5efb249a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 10 deletions

View file

@ -1,6 +1,7 @@
package actions
import (
"errors"
"github.com/containrrr/watchtower/internal/util"
"github.com/containrrr/watchtower/pkg/container"
"github.com/containrrr/watchtower/pkg/lifecycle"
@ -25,11 +26,13 @@ func Update(client container.Client, params types.UpdateParams) error {
return err
}
for i, container := range containers {
stale, err := client.IsContainerStale(container)
for i, targetContainer := range containers {
stale, err := client.IsContainerStale(targetContainer)
if stale && !params.NoRestart && !params.MonitorOnly && !targetContainer.HasImageInfo() {
err = errors.New("no available image info")
}
if err != nil {
log.Infof("Unable to update container %s. Proceeding to next.", containers[i].Name())
log.Debug(err)
log.Infof("Unable to update container %q: %v. Proceeding to next.", containers[i].Name(), err)
stale = false
}
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) {
imageIDs := make(map[string]bool)
for _, container := range containers {
if !container.Stale {
for _, staleContainer := range containers {
if !staleContainer.Stale {
continue
}
restartStaleContainer(container, client, params)
imageIDs[container.ImageID()] = true
restartStaleContainer(staleContainer, client, params)
imageIDs[staleContainer.ImageID()] = true
}
if params.Cleanup {
for imageID := range imageIDs {