Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saving in oci format #6814

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/containers/image/v5/image"
"github.com/containers/image/v5/manifest"
ociarchive "github.com/containers/image/v5/oci/archive"
"github.com/containers/image/v5/oci/layout"
is "github.com/containers/image/v5/storage"
"github.com/containers/image/v5/tarball"
"github.com/containers/image/v5/transports"
Expand Down Expand Up @@ -1483,9 +1484,10 @@ func (i *Image) Save(ctx context.Context, source, format, output string, moreTag
return errors.Wrapf(err, "error getting OCI archive ImageReference for (%q, %q)", output, destImageName)
}
case "oci-dir":
destRef, err = directory.NewReference(output)
destImageName := imageNameForSaveDestination(i, source)
destRef, err = layout.NewReference(output, destImageName) // destImageName may be ""
if err != nil {
return errors.Wrapf(err, "error getting directory ImageReference for %q", output)
return errors.Wrapf(err, "error getting the OCI directory ImageReference for (%q, %q)", output, destImageName)
}
manifestType = imgspecv1.MediaTypeImageManifest
case "docker-dir":
Expand Down
64 changes: 44 additions & 20 deletions libpod/runtime_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ import (
"net/http"
"net/url"
"os"
"strings"

"github.com/containers/buildah/imagebuildah"
"github.com/containers/image/v5/directory"
"github.com/containers/image/v5/docker/reference"
ociarchive "github.com/containers/image/v5/oci/archive"
"github.com/containers/image/v5/oci/layout"
"github.com/containers/image/v5/types"

"github.com/containers/libpod/v2/libpod/define"
"github.com/containers/libpod/v2/libpod/image"
"github.com/containers/libpod/v2/pkg/util"
"github.com/containers/storage"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/containers/image/v5/directory"
dockerarchive "github.com/containers/image/v5/docker/archive"
ociarchive "github.com/containers/image/v5/oci/archive"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)

Expand Down Expand Up @@ -256,28 +260,48 @@ func DownloadFromFile(reader *os.File) (string, error) {

// LoadImage loads a container image into local storage
func (r *Runtime) LoadImage(ctx context.Context, name, inputFile string, writer io.Writer, signaturePolicy string) (string, error) {
var newImages []*image.Image
src, err := dockerarchive.ParseReference(inputFile) // FIXME? We should add dockerarchive.NewReference()
if err == nil {
newImages, err = r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer)
}
if err != nil {
// generate full src name with specified image:tag
src, err := ociarchive.NewReference(inputFile, name) // imageName may be ""
if err == nil {
newImages, err = r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer)
}
if err != nil {
src, err := directory.NewReference(inputFile)
if err == nil {
newImages, err = r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer)
var (
newImages []*image.Image
err error
src types.ImageReference
)

for _, referenceFn := range []func() (types.ImageReference, error){
func() (types.ImageReference, error) {
return dockerarchive.ParseReference(inputFile) // FIXME? We should add dockerarchive.NewReference()
},
func() (types.ImageReference, error) {
return ociarchive.NewReference(inputFile, name) // name may be ""
},
func() (types.ImageReference, error) {
// prepend "localhost/" to support local image saved with this semantics
if !strings.Contains(name, "/") {
return ociarchive.NewReference(inputFile, fmt.Sprintf("%s/%s", image.DefaultLocalRegistry, name))
}
return nil, nil
},
func() (types.ImageReference, error) {
return directory.NewReference(inputFile)
},
func() (types.ImageReference, error) {
return layout.NewReference(inputFile, name)
},
func() (types.ImageReference, error) {
// prepend "localhost/" to support local image saved with this semantics
if !strings.Contains(name, "/") {
return layout.NewReference(inputFile, fmt.Sprintf("%s/%s", image.DefaultLocalRegistry, name))
}
if err != nil {
return "", errors.Wrapf(err, "error pulling %q", name)
return nil, nil
},
} {
src, err = referenceFn()
if err == nil && src != nil {
if newImages, err = r.ImageRuntime().LoadFromArchiveReference(ctx, src, signaturePolicy, writer); err == nil {
return getImageNames(newImages), nil
}
}
}
return getImageNames(newImages), nil
return "", errors.Wrapf(err, "error pulling %q", name)
}

func getImageNames(images []*image.Image) string {
Expand Down