Skip to content

Commit

Permalink
[image-builder] Support pre-caching from authenticated registry
Browse files Browse the repository at this point in the history
  • Loading branch information
csweichel committed May 4, 2022
1 parent 8b82dc6 commit 3ca8b49
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion components/image-builder-mk3/pkg/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type DockerRefResolver interface {
type PrecachingRefResolver struct {
Resolver DockerRefResolver
Candidates []string
Auth auth.RegistryAuthenticator

mu sync.RWMutex
cache map[string]string
Expand All @@ -218,7 +219,24 @@ func (pr *PrecachingRefResolver) StartCaching(ctx context.Context, interval time
pr.cache = make(map[string]string)
for {
for _, c := range pr.Candidates {
res, err := pr.Resolver.Resolve(ctx, c)
var opts []DockerRefResolverOption
if pr.Auth != nil {
ref, err := reference.ParseNormalizedNamed(c)
if err != nil {
log.WithError(err).WithField("ref", c).Warn("unable to precache reference: cannot parse")
continue
}

auth, err := pr.Auth.Authenticate(reference.Domain(ref))
if err != nil {
log.WithError(err).WithField("ref", c).Warn("unable to precache reference: cannot authenticate")
continue
}

opts = append(opts, WithAuthentication(auth))
}

res, err := pr.Resolver.Resolve(ctx, c, opts...)
if err != nil {
log.WithError(err).WithField("ref", c).Warn("unable to precache reference")
continue
Expand Down

0 comments on commit 3ca8b49

Please sign in to comment.