diff options
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/filters.go | 5 | ||||
-rw-r--r-- | libpod/image/image.go | 73 | ||||
-rw-r--r-- | libpod/image/image_test.go | 9 | ||||
-rw-r--r-- | libpod/image/pull.go | 13 |
4 files changed, 52 insertions, 48 deletions
diff --git a/libpod/image/filters.go b/libpod/image/filters.go index 20a9efc97..c1dd1e5cd 100644 --- a/libpod/image/filters.go +++ b/libpod/image/filters.go @@ -1,6 +1,7 @@ package image import ( + "context" "strings" "time" @@ -39,7 +40,7 @@ func DanglingFilter() ResultFilter { } // LabelFilter allows you to filter by images labels key and/or value -func LabelFilter(labelfilter string) ResultFilter { +func LabelFilter(ctx context.Context, labelfilter string) ResultFilter { // We need to handle both label=key and label=key=value return func(i *Image) bool { var value string @@ -48,7 +49,7 @@ func LabelFilter(labelfilter string) ResultFilter { if len(splitFilter) > 1 { value = splitFilter[1] } - labels, err := i.Labels() + labels, err := i.Labels(ctx) if err != nil { return false } diff --git a/libpod/image/image.go b/libpod/image/image.go index cf0c7ec1b..53d69ebe9 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -1,6 +1,7 @@ package image import ( + "context" "encoding/json" "fmt" "io" @@ -117,7 +118,7 @@ func (ir *Runtime) NewFromLocal(name string) (*Image, error) { // New creates a new image object where the image could be local // or remote -func (ir *Runtime) New(name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, forcePull, forceSecure bool) (*Image, error) { +func (ir *Runtime) New(ctx context.Context, name, signaturePolicyPath, authfile string, writer io.Writer, dockeroptions *DockerRegistryOptions, signingoptions SigningOptions, forcePull, forceSecure bool) (*Image, error) { // We don't know if the image is local or not ... check local first newImage := Image{ InputName: name, @@ -137,7 +138,7 @@ func (ir *Runtime) New(name, signaturePolicyPath, authfile string, writer io.Wri if signaturePolicyPath == "" { signaturePolicyPath = ir.SignaturePolicyPath } - imageName, err := newImage.pullImage(writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, forceSecure) + imageName, err := newImage.pullImage(ctx, writer, authfile, signaturePolicyPath, signingoptions, dockeroptions, forceSecure) if err != nil { return nil, errors.Errorf("unable to pull %s", name) } @@ -254,12 +255,12 @@ func (i *Image) Digest() digest.Digest { // Manifest returns the image's manifest as a byte array // and manifest type as a string. The manifest type is // MediaTypeImageManifest from ociv1. -func (i *Image) Manifest() ([]byte, string, error) { - imgRef, err := i.toImageRef() +func (i *Image) Manifest(ctx context.Context) ([]byte, string, error) { + imgRef, err := i.toImageRef(ctx) if err != nil { return nil, "", err } - return imgRef.Manifest() + return imgRef.Manifest(ctx) } // Names returns a string array of names associated with the image @@ -351,8 +352,8 @@ func (ir *Runtime) GetImages() ([]*Image, error) { // getImageDigest creates an image object and uses the hex value of the digest as the image ID // for parsing the store reference -func getImageDigest(src types.ImageReference, ctx *types.SystemContext) (string, error) { - newImg, err := src.NewImage(ctx) +func getImageDigest(ctx context.Context, src types.ImageReference, sc *types.SystemContext) (string, error) { + newImg, err := src.NewImage(ctx, sc) if err != nil { return "", err } @@ -408,7 +409,7 @@ func (i *Image) UntagImage(tag string) error { } // PushImage pushes the given image to a location described by the given path -func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error { +func (i *Image) PushImage(ctx context.Context, destination, manifestMIMEType, authFile, signaturePolicyPath string, writer io.Writer, forceCompress bool, signingOptions SigningOptions, dockerRegistryOptions *DockerRegistryOptions) error { if destination == "" { return errors.Wrapf(syscall.EINVAL, "destination image name must be specified") } @@ -444,7 +445,7 @@ func (i *Image) PushImage(destination, manifestMIMEType, authFile, signaturePoli copyOptions := getCopyOptions(writer, signaturePolicyPath, nil, dockerRegistryOptions, signingOptions, authFile, manifestMIMEType, forceCompress) // Copy the image to the remote destination - err = cp.Image(policyContext, dest, src, copyOptions) + err = cp.Image(ctx, policyContext, dest, src, copyOptions) if err != nil { return errors.Wrapf(err, "Error copying image to the remote destination") } @@ -477,12 +478,12 @@ func (i *Image) toStorageReference() (types.ImageReference, error) { // ToImageRef returns an image reference type from an image // TODO: Hopefully we can remove this exported function for mheon -func (i *Image) ToImageRef() (types.Image, error) { - return i.toImageRef() +func (i *Image) ToImageRef(ctx context.Context) (types.Image, error) { + return i.toImageRef(ctx) } // toImageRef returns an Image Reference type from an image -func (i *Image) toImageRef() (types.Image, error) { +func (i *Image) toImageRef(ctx context.Context) (types.Image, error) { if i == nil { return nil, errors.Errorf("cannot convert nil image to image reference") } @@ -491,7 +492,7 @@ func (i *Image) toImageRef() (types.Image, error) { if err != nil { return nil, errors.Wrapf(err, "error parsing reference to image %q", i.ID()) } - imgRef, err := ref.NewImage(nil) + imgRef, err := ref.NewImage(ctx, nil) if err != nil { return nil, errors.Wrapf(err, "error reading image %q", i.ID()) } @@ -506,13 +507,13 @@ type sizer interface { } //Size returns the size of the image -func (i *Image) Size() (*uint64, error) { +func (i *Image) Size(ctx context.Context) (*uint64, error) { storeRef, err := is.Transport.ParseStoreReference(i.imageruntime.store, i.ID()) if err != nil { return nil, err } systemContext := &types.SystemContext{} - img, err := storeRef.NewImageSource(systemContext) + img, err := storeRef.NewImageSource(ctx, systemContext) if err != nil { return nil, err } @@ -540,12 +541,12 @@ func (i *Image) Layer() (*storage.Layer, error) { } // History gets the history of an image and information about its layers -func (i *Image) History() ([]ociv1.History, []types.BlobInfo, error) { - img, err := i.toImageRef() +func (i *Image) History(ctx context.Context) ([]ociv1.History, []types.BlobInfo, error) { + img, err := i.toImageRef(ctx) if err != nil { return nil, nil, err } - oci, err := img.OCIConfig() + oci, err := img.OCIConfig(ctx) if err != nil { return nil, nil, err } @@ -558,8 +559,8 @@ func (i *Image) Dangling() bool { } // Labels returns the image's labels -func (i *Image) Labels() (map[string]string, error) { - imgInspect, err := i.imageInspectInfo() +func (i *Image) Labels(ctx context.Context) (map[string]string, error) { + imgInspect, err := i.imageInspectInfo(ctx) if err != nil { return nil, nil } @@ -567,8 +568,8 @@ func (i *Image) Labels() (map[string]string, error) { } // Annotations returns the annotations of an image -func (i *Image) Annotations() (map[string]string, error) { - manifest, manifestType, err := i.Manifest() +func (i *Image) Annotations(ctx context.Context) (map[string]string, error) { + manifest, manifestType, err := i.Manifest(ctx) if err != nil { return nil, err } @@ -587,25 +588,25 @@ func (i *Image) Annotations() (map[string]string, error) { // ociv1Image converts and image to an imgref and then an // ociv1 image type -func (i *Image) ociv1Image() (*ociv1.Image, error) { - imgRef, err := i.toImageRef() +func (i *Image) ociv1Image(ctx context.Context) (*ociv1.Image, error) { + imgRef, err := i.toImageRef(ctx) if err != nil { return nil, err } - return imgRef.OCIConfig() + return imgRef.OCIConfig(ctx) } -func (i *Image) imageInspectInfo() (*types.ImageInspectInfo, error) { +func (i *Image) imageInspectInfo(ctx context.Context) (*types.ImageInspectInfo, error) { if i.inspectInfo == nil { sr, err := i.toStorageReference() if err != nil { return nil, err } - ic, err := sr.NewImage(&types.SystemContext{}) + ic, err := sr.NewImage(ctx, &types.SystemContext{}) if err != nil { return nil, err } - imgInspect, err := ic.Inspect() + imgInspect, err := ic.Inspect(ctx) if err != nil { return nil, err } @@ -615,21 +616,21 @@ func (i *Image) imageInspectInfo() (*types.ImageInspectInfo, error) { } // Inspect returns an image's inspect data -func (i *Image) Inspect() (*inspect.ImageData, error) { - ociv1Img, err := i.ociv1Image() +func (i *Image) Inspect(ctx context.Context) (*inspect.ImageData, error) { + ociv1Img, err := i.ociv1Image(ctx) if err != nil { return nil, err } - info, err := i.imageInspectInfo() + info, err := i.imageInspectInfo(ctx) if err != nil { return nil, err } - annotations, err := i.Annotations() + annotations, err := i.Annotations(ctx) if err != nil { return nil, err } - size, err := i.Size() + size, err := i.Size(ctx) if err != nil { return nil, err } @@ -670,7 +671,7 @@ func (i *Image) Inspect() (*inspect.ImageData, error) { } // Import imports and image into the store and returns an image -func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) { +func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io.Writer, signingOptions SigningOptions, imageConfig ociv1.Image) (*Image, error) { file := TarballTransport + ":" + path src, err := alltransports.ParseImageName(file) if err != nil { @@ -694,7 +695,7 @@ func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptio // if reference not given, get the image digest if reference == "" { - reference, err = getImageDigest(src, sc) + reference, err = getImageDigest(ctx, src, sc) if err != nil { return nil, err } @@ -709,7 +710,7 @@ func (ir *Runtime) Import(path, reference string, writer io.Writer, signingOptio if err != nil { errors.Wrapf(err, "error getting image reference for %q", reference) } - if err = cp.Image(policyContext, dest, src, copyOptions); err != nil { + if err = cp.Image(ctx, policyContext, dest, src, copyOptions); err != nil { return nil, err } return ir.NewFromLocal(reference) diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index f160a14a4..71beed495 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -1,6 +1,7 @@ package image import ( + "context" "fmt" "io" "io/ioutil" @@ -81,9 +82,9 @@ func TestImage_NewFromLocal(t *testing.T) { // Need images to be present for this test ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) - bb, err := ir.New("docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, false, false) + bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, false, false) assert.NoError(t, err) - bbglibc, err := ir.New("docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, false, false) + bbglibc, err := ir.New(context.Background(), "docker.io/library/busybox:glibc", "", "", writer, nil, SigningOptions{}, false, false) assert.NoError(t, err) tm, err := makeLocalMatrix(bb, bbglibc) @@ -126,7 +127,7 @@ func TestImage_New(t *testing.T) { // Iterate over the names and delete the image // after the pull for _, img := range names { - newImage, err := ir.New(img, "", "", writer, nil, SigningOptions{}, false, false) + newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, false, false) assert.NoError(t, err) assert.NotEqual(t, newImage.ID(), "") err = newImage.Remove(false) @@ -150,7 +151,7 @@ func TestImage_MatchRepoTag(t *testing.T) { } ir, err := NewImageRuntimeFromOptions(so) assert.NoError(t, err) - newImage, err := ir.New("busybox", "", "", os.Stdout, nil, SigningOptions{}, false, false) + newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, false, false) assert.NoError(t, err) err = newImage.TagImage("foo:latest") assert.NoError(t, err) diff --git a/libpod/image/pull.go b/libpod/image/pull.go index b2d32b255..74a773987 100644 --- a/libpod/image/pull.go +++ b/libpod/image/pull.go @@ -1,6 +1,7 @@ package image import ( + "context" "fmt" "io" "os" @@ -70,7 +71,7 @@ func (ir *Runtime) getPullStruct(srcRef types.ImageReference, destName string) ( } // returns a list of pullStruct with the srcRef and DstRef based on the transport being used -func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullStruct, error) { +func (ir *Runtime) getPullListFromRef(ctx context.Context, srcRef types.ImageReference, imgName string, sc *types.SystemContext) ([]*pullStruct, error) { var pullStructs []*pullStruct splitArr := strings.Split(imgName, ":") archFile := splitArr[len(splitArr)-1] @@ -89,7 +90,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin // to pull the first image stored in the tar file if len(manifest) == 0 { // use the hex of the digest if no manifest is found - reference, err := getImageDigest(srcRef, sc) + reference, err := getImageDigest(ctx, srcRef, sc) if err != nil { return nil, err } @@ -104,7 +105,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin dest = manifest[0].RepoTags[0] } else { // If the input image has no repotags, we need to feed it a dest anyways - dest, err = getImageDigest(srcRef, sc) + dest, err = getImageDigest(ctx, srcRef, sc) if err != nil { return nil, err } @@ -155,7 +156,7 @@ func (ir *Runtime) getPullListFromRef(srcRef types.ImageReference, imgName strin // pullImage pulls an image from configured registries // By default, only the latest tag (or a specific tag if requested) will be // pulled. -func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, forceSecure bool) (string, error) { +func (i *Image) pullImage(ctx context.Context, writer io.Writer, authfile, signaturePolicyPath string, signingOptions SigningOptions, dockerOptions *DockerRegistryOptions, forceSecure bool) (string, error) { // pullImage copies the image from the source to the destination var pullStructs []*pullStruct sc := GetSystemContext(signaturePolicyPath, authfile, false) @@ -167,7 +168,7 @@ func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string return "", errors.Wrap(err, "error getting default registries to try") } } else { - pullStructs, err = i.imageruntime.getPullListFromRef(srcRef, i.InputName, sc) + pullStructs, err = i.imageruntime.getPullListFromRef(ctx, srcRef, i.InputName, sc) if err != nil { return "", errors.Wrapf(err, "error getting pullStruct info to pull image %q", i.InputName) } @@ -201,7 +202,7 @@ func (i *Image) pullImage(writer io.Writer, authfile, signaturePolicyPath string if writer != nil && (strings.HasPrefix(DockerTransport, imageInfo.srcRef.Transport().Name()) || imageInfo.srcRef.Transport().Name() == AtomicTransport) { io.WriteString(writer, fmt.Sprintf("Trying to pull %s...", imageInfo.image)) } - if err = cp.Image(policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil { + if err = cp.Image(ctx, policyContext, imageInfo.dstRef, imageInfo.srcRef, copyOptions); err != nil { if writer != nil { io.WriteString(writer, "Failed\n") } |