mirror of
https://github.com/containers/skopeo.git
synced 2025-09-03 23:55:21 +00:00
Use a reference.Named, not types.ImageReference, in imagesToCopyFromRepo
Right now that only complicates code by going through a types.ImageReference->reference.Named->types.ImageReference sequence, but that will change as we modify the callers as well. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
committed by
Valentin Rothberg
parent
7439f94e22
commit
d16cd39939
@@ -164,15 +164,20 @@ func destinationReference(destination string, transport string) (types.ImageRefe
|
|||||||
return destRef, nil
|
return destRef, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageTags retrieves all the tags associated to an image hosted on a
|
// getImageTags lists all tags in a repository.
|
||||||
// container registry.
|
|
||||||
// It returns a string slice of tags and any error encountered.
|
// It returns a string slice of tags and any error encountered.
|
||||||
func getImageTags(ctx context.Context, sysCtx *types.SystemContext, imgRef types.ImageReference) ([]string, error) {
|
func getImageTags(ctx context.Context, sysCtx *types.SystemContext, repoRef reference.Named) ([]string, error) {
|
||||||
name := imgRef.DockerReference().Name()
|
name := repoRef.Name()
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"image": name,
|
"image": name,
|
||||||
}).Info("Getting tags")
|
}).Info("Getting tags")
|
||||||
tags, err := docker.GetRepositoryTags(ctx, sysCtx, imgRef)
|
// Ugly: NewReference rejects IsNameOnly references, and GetRepositoryTags ignores the tag/digest.
|
||||||
|
// So, we use TagNameOnly here only to shut up NewReference
|
||||||
|
dockerRef, err := docker.NewReference(reference.TagNameOnly(repoRef))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err // Should never happen for a reference with tag and no digest
|
||||||
|
}
|
||||||
|
tags, err := docker.GetRepositoryTags(ctx, sysCtx, dockerRef)
|
||||||
|
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
@@ -205,18 +210,17 @@ func isTagSpecified(imageName string) (bool, error) {
|
|||||||
return tagged, nil
|
return tagged, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// imagesTopCopyFromRepo builds a list of image references from the tags
|
// imagesToCopyFromRepo builds a list of image references from the tags
|
||||||
// found in the source repository.
|
// found in a source repository.
|
||||||
// It returns an image reference slice with as many elements as the tags found
|
// It returns an image reference slice with as many elements as the tags found
|
||||||
// and any error encountered.
|
// and any error encountered.
|
||||||
func imagesToCopyFromRepo(sys *types.SystemContext, repoReference types.ImageReference) ([]types.ImageReference, error) {
|
func imagesToCopyFromRepo(sys *types.SystemContext, repoRef reference.Named) ([]types.ImageReference, error) {
|
||||||
var sourceReferences []types.ImageReference
|
tags, err := getImageTags(context.Background(), sys, repoRef)
|
||||||
tags, err := getImageTags(context.Background(), sys, repoReference)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sourceReferences, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repoRef := repoReference.DockerReference()
|
var sourceReferences []types.ImageReference
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
taggedRef, err := reference.WithTag(repoRef, tag)
|
taggedRef, err := reference.WithTag(repoRef, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -309,7 +313,7 @@ func imagesToCopyFromRegistry(registryName string, cfg registrySyncConfig, sourc
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceReferences, err = imagesToCopyFromRepo(serverCtx, imageRef)
|
sourceReferences, err = imagesToCopyFromRepo(serverCtx, imageRef.DockerReference())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
repoLogger.Error("Error processing repo, skipping")
|
repoLogger.Error("Error processing repo, skipping")
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@@ -351,7 +355,7 @@ func imagesToCopyFromRegistry(registryName string, cfg registrySyncConfig, sourc
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
allSourceReferences, err := imagesToCopyFromRepo(serverCtx, imageRef)
|
allSourceReferences, err := imagesToCopyFromRepo(serverCtx, imageRef.DockerReference())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
repoLogger.Error("Error processing repo, skipping")
|
repoLogger.Error("Error processing repo, skipping")
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@@ -407,7 +411,7 @@ func imagesToCopy(source string, transport string, sourceCtx *types.SystemContex
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
desc.TaggedImages, err = imagesToCopyFromRepo(sourceCtx, srcRef)
|
desc.TaggedImages, err = imagesToCopyFromRepo(sourceCtx, srcRef.DockerReference())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return descriptors, err
|
return descriptors, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user