add http head based digest comparison to avoid dockerhub rate limits

This commit is contained in:
Simon Aronsson 2020-12-06 13:21:04 +01:00 committed by GitHub
parent c8bd484b9e
commit cb62b16369
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1476 additions and 57 deletions

View file

@ -10,7 +10,7 @@ import (
"github.com/containrrr/watchtower/pkg/filters"
"github.com/containrrr/watchtower/pkg/sorter"
"github.com/opencontainers/runc/Godeps/_workspace/src/github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"

View file

@ -17,6 +17,7 @@ func CreateMockContainer(id string, name string, image string, created time.Time
Created: created.String(),
},
Config: &container2.Config{
Image: image,
Labels: make(map[string]string),
},
}
@ -24,10 +25,40 @@ func CreateMockContainer(id string, name string, image string, created time.Time
&content,
&types.ImageInspect{
ID: image,
RepoDigests: []string{
image,
},
},
)
}
// CreateMockContainerWithImageInfo should only be used for testing
func CreateMockContainerWithImageInfo(id string, name string, image string, created time.Time, imageInfo types.ImageInspect) container.Container {
content := types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
ID: id,
Image: image,
Name: name,
Created: created.String(),
},
Config: &container2.Config{
Image: image,
Labels: make(map[string]string),
},
}
return *container.NewContainer(
&content,
&imageInfo,
)
}
// CreateMockContainerWithDigest should only be used for testing
func CreateMockContainerWithDigest(id string, name string, image string, created time.Time, digest string) container.Container {
c := CreateMockContainer(id, name, image, created)
c.ImageInfo().RepoDigests = []string{digest}
return c
}
// CreateMockContainerWithConfig creates a container substitute valid for testing
func CreateMockContainerWithConfig(id string, name string, image string, created time.Time, config *container2.Config) container.Container {
content := types.ContainerJSON{

View file

@ -300,10 +300,11 @@ Should only be used for testing.`)
// SetDefaults provides default values for environment variables
func SetDefaults() {
day := time.Hour * 24 / time.Second
viper.AutomaticEnv()
viper.SetDefault("DOCKER_HOST", "unix:///var/run/docker.sock")
viper.SetDefault("DOCKER_API_VERSION", DockerAPIMinVersion)
viper.SetDefault("WATCHTOWER_POLL_INTERVAL", 300)
viper.SetDefault("WATCHTOWER_POLL_INTERVAL", day)
viper.SetDefault("WATCHTOWER_TIMEOUT", time.Second*10)
viper.SetDefault("WATCHTOWER_NOTIFICATIONS", []string{})
viper.SetDefault("WATCHTOWER_NOTIFICATIONS_LEVEL", "info")