mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-16 07:00:13 +01:00
- Upgraded `go.mod` to use Go 1.23 and updated module dependencies to latest versions - Refactored code to align with API changes in Docker and related modules: - Updated `ContainerListOptions` to `container.ListOptions` and related structs - Replaced `types.ImageDeleteResponseItem` with `image.DeleteResponse` for compatibility - Modified `ImagePullOptions` and `ContainerRemoveOptions` to updated package paths
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/containrrr/watchtower/pkg/registry/helpers"
|
|
watchtowerTypes "github.com/containrrr/watchtower/pkg/types"
|
|
ref "github.com/distribution/reference"
|
|
"github.com/docker/docker/api/types/image"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// GetPullOptions creates a struct with all options needed for pulling images from a registry
|
|
func GetPullOptions(imageName string) (image.PullOptions, error) {
|
|
auth, err := EncodedAuth(imageName)
|
|
log.Debugf("Got image name: %s", imageName)
|
|
if err != nil {
|
|
return image.PullOptions{}, err
|
|
}
|
|
|
|
if auth == "" {
|
|
return image.PullOptions{}, nil
|
|
}
|
|
|
|
// CREDENTIAL: Uncomment to log docker config auth
|
|
// log.Tracef("Got auth value: %s", auth)
|
|
|
|
return image.PullOptions{
|
|
RegistryAuth: auth,
|
|
PrivilegeFunc: DefaultAuthHandler,
|
|
}, nil
|
|
}
|
|
|
|
func DefaultAuthHandler(ctx context.Context) (string, error) {
|
|
log.Debug("Authentication request was rejected. Trying again without authentication")
|
|
return "", nil
|
|
}
|
|
|
|
// WarnOnAPIConsumption will return true if the registry is known-expected
|
|
// to respond well to HTTP HEAD in checking the container digest -- or if there
|
|
// are problems parsing the container hostname.
|
|
// Will return false if behavior for container is unknown.
|
|
func WarnOnAPIConsumption(container watchtowerTypes.Container) bool {
|
|
|
|
normalizedRef, err := ref.ParseNormalizedNamed(container.ImageName())
|
|
if err != nil {
|
|
return true
|
|
}
|
|
|
|
containerHost, err := helpers.GetRegistryAddress(normalizedRef.Name())
|
|
if err != nil {
|
|
return true
|
|
}
|
|
|
|
if containerHost == helpers.DefaultRegistryHost || containerHost == "ghcr.io" {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|