Add registry errors for pull
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
This commit is contained in:
parent
69b0a82b77
commit
043fd2e300
4
new.go
4
new.go
|
@ -168,7 +168,7 @@ func resolveImage(ctx context.Context, systemContext *types.SystemContext, store
|
||||||
if options.PullPolicy == PullAlways {
|
if options.PullPolicy == PullAlways {
|
||||||
pulledImg, pulledReference, err := pullAndFindImage(ctx, store, image, options, systemContext)
|
pulledImg, pulledReference, err := pullAndFindImage(ctx, store, image, options, systemContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("error pulling and reading image %q: %v", image, err)
|
logrus.Debugf("unable to pull and read image %q: %v", image, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ref = pulledReference
|
ref = pulledReference
|
||||||
|
@ -214,7 +214,7 @@ func resolveImage(ctx context.Context, systemContext *types.SystemContext, store
|
||||||
}
|
}
|
||||||
pulledImg, pulledReference, err := pullAndFindImage(ctx, store, image, options, systemContext)
|
pulledImg, pulledReference, err := pullAndFindImage(ctx, store, image, options, systemContext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("error pulling and reading image %q: %v", image, err)
|
logrus.Debugf("unable to pull and read image %q: %v", image, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ref = pulledReference
|
ref = pulledReference
|
||||||
|
|
18
pull.go
18
pull.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/containers/image/docker/reference"
|
"github.com/containers/image/docker/reference"
|
||||||
tarfile "github.com/containers/image/docker/tarfile"
|
tarfile "github.com/containers/image/docker/tarfile"
|
||||||
ociarchive "github.com/containers/image/oci/archive"
|
ociarchive "github.com/containers/image/oci/archive"
|
||||||
|
"github.com/containers/image/pkg/sysregistries"
|
||||||
"github.com/containers/image/signature"
|
"github.com/containers/image/signature"
|
||||||
is "github.com/containers/image/storage"
|
is "github.com/containers/image/storage"
|
||||||
"github.com/containers/image/transports"
|
"github.com/containers/image/transports"
|
||||||
|
@ -166,12 +167,25 @@ func pullImage(ctx context.Context, store storage.Store, imageName string, optio
|
||||||
}()
|
}()
|
||||||
|
|
||||||
logrus.Debugf("copying %q to %q", spec, destName)
|
logrus.Debugf("copying %q to %q", spec, destName)
|
||||||
|
|
||||||
err = cp.Image(ctx, policyContext, destRef, srcRef, getCopyOptions(options.ReportWriter, options.SystemContext, nil, ""))
|
err = cp.Image(ctx, policyContext, destRef, srcRef, getCopyOptions(options.ReportWriter, options.SystemContext, nil, ""))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return destRef, nil
|
return destRef, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
|
||||||
|
// If no image was found, we should handle. Lets be nicer to the user and see if we can figure out why.
|
||||||
|
registryPath := sysregistries.RegistriesConfPath(&types.SystemContext{})
|
||||||
|
searchRegistries, err := getRegistries()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
hasRegistryInName, err := hasRegistry(imageName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !hasRegistryInName && len(searchRegistries) == 0 {
|
||||||
|
return nil, errors.Errorf("image name provided is a short name and no search registries are defined in %s.", registryPath)
|
||||||
|
}
|
||||||
|
return nil, errors.Errorf("unable to find image in the registries defined in %q", registryPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getImageDigest creates an image object and uses the hex value of the digest as the image ID
|
// getImageDigest creates an image object and uses the hex value of the digest as the image ID
|
||||||
|
|
31
util.go
31
util.go
|
@ -7,6 +7,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/containers/image/docker/reference"
|
||||||
|
"github.com/containers/image/pkg/sysregistries"
|
||||||
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/storage/pkg/archive"
|
"github.com/containers/storage/pkg/archive"
|
||||||
"github.com/containers/storage/pkg/chrootarchive"
|
"github.com/containers/storage/pkg/chrootarchive"
|
||||||
"github.com/containers/storage/pkg/idtools"
|
"github.com/containers/storage/pkg/idtools"
|
||||||
|
@ -200,3 +203,31 @@ func getHostRootIDs(spec *rspec.Spec) (uint32, uint32, error) {
|
||||||
}
|
}
|
||||||
return getHostIDs(spec.Linux.UIDMappings, spec.Linux.GIDMappings, 0, 0)
|
return getHostIDs(spec.Linux.UIDMappings, spec.Linux.GIDMappings, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getRegistries obtains the list of registries defined in the global registries file.
|
||||||
|
func getRegistries() ([]string, error) {
|
||||||
|
registryConfigPath := ""
|
||||||
|
envOverride := os.Getenv("REGISTRIES_CONFIG_PATH")
|
||||||
|
if len(envOverride) > 0 {
|
||||||
|
registryConfigPath = envOverride
|
||||||
|
}
|
||||||
|
searchRegistries, err := sysregistries.GetRegistries(&types.SystemContext{SystemRegistriesConfPath: registryConfigPath})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "unable to parse the registries.conf file")
|
||||||
|
}
|
||||||
|
return searchRegistries, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// hasRegistry returns a bool/err response if the image has a registry in its
|
||||||
|
// name
|
||||||
|
func hasRegistry(imageName string) (bool, error) {
|
||||||
|
imgRef, err := reference.Parse(imageName)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
registry := reference.Domain(imgRef.(reference.Named))
|
||||||
|
if registry != "" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue