add some more tests and debug logs

This commit is contained in:
Simon Aronsson 2020-11-21 21:34:56 +01:00
parent 2b68874087
commit 0c704ce02b
No known key found for this signature in database
GPG key ID: 8DA57A5FD341605B
9 changed files with 727 additions and 39 deletions

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/containrrr/watchtower/pkg/registry"
"github.com/containrrr/watchtower/pkg/registry/digest"
t "github.com/containrrr/watchtower/pkg/types"
"github.com/docker/docker/api/types"
@ -275,14 +276,36 @@ func (client dockerClient) HasNewImage(ctx context.Context, container Container)
func (client dockerClient) PullImage(ctx context.Context, container Container) error {
containerName := container.Name()
imageName := container.ImageName()
log.Debugf("Pulling %s for %s", imageName, containerName)
fields := log.Fields{
"image": imageName,
"container": containerName,
}
log.WithFields(fields).Debugf("Trying to load authentication credentials.")
opts, err := registry.GetPullOptions(imageName)
if opts.RegistryAuth != "" {
log.Debug("Credentials loaded")
}
if err != nil {
log.Debugf("Error loading authentication credentials %s", err)
return err
}
log.WithFields(fields).Debugf("Checking if pull is needed")
if match, err := digest.CompareDigest(ctx, *container.ImageInfo(), nil); err != nil {
log.Info("Could not do a head request, falling back to regulara pull.")
log.Debugf("Reason: %s", err.Error())
} else if match {
log.Debug("No pull needed. Skipping image.")
return nil
} else {
log.Debug("Digests did not match, doing a pull.")
}
log.WithFields(fields).Debugf("Pulling image")
response, err := client.api.ImagePull(ctx, imageName, opts)
if err != nil {
log.Debugf("Error pulling image %s, %s", imageName, err)