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

containers/image v5; support manifest lists; add a "manifest" command #1902

Closed
wants to merge 8 commits into from
Closed
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
2 changes: 1 addition & 1 deletion buildah.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/containers/buildah/docker"
"github.com/containers/buildah/util"
"github.com/containers/image/v4/types"
"github.com/containers/image/v5/types"
"github.com/containers/storage"
"github.com/containers/storage/pkg/ioutils"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down
6 changes: 3 additions & 3 deletions cmd/buildah/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/buildah/util"
"github.com/containers/image/v4/storage"
"github.com/containers/image/v4/transports/alltransports"
"github.com/containers/image/v4/types"
"github.com/containers/image/v5/storage"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down
41 changes: 29 additions & 12 deletions cmd/buildah/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/containers/buildah"
"github.com/containers/buildah/pkg/umask"
"github.com/containers/buildah/pkg/unshare"
is "github.com/containers/image/v4/storage"
"github.com/containers/image/v4/types"
"github.com/containers/image/v5/image"
is "github.com/containers/image/v5/storage"
"github.com/containers/image/v5/types"
"github.com/containers/storage"
digest "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -152,37 +153,38 @@ func openImage(ctx context.Context, sc *types.SystemContext, store storage.Store
return builder, nil
}

func getDateAndDigestAndSize(ctx context.Context, store storage.Store, image storage.Image) (time.Time, string, int64, error) {
func getDateAndDigestAndSize(ctx context.Context, sys *types.SystemContext, store storage.Store, storeImage storage.Image) (time.Time, string, int64, error) {
created := time.Time{}
is.Transport.SetStore(store)
storeRef, err := is.Transport.ParseStoreReference(store, image.ID)
storeRef, err := is.Transport.ParseStoreReference(store, storeImage.ID)
if err != nil {
return created, "", -1, err
}
img, err := storeRef.NewImage(ctx, nil)
img, err := storeRef.NewImageSource(ctx, nil)
if err != nil {
return created, "", -1, err
}
defer img.Close()
imgSize, sizeErr := img.Size()
imgSize, sizeErr := store.ImageSize(storeImage.ID)
if sizeErr != nil {
imgSize = -1
}
manifest, _, manifestErr := img.Manifest(ctx)
manifest, _, manifestErr := img.GetManifest(ctx, nil)
manifestDigest := ""
if manifestErr == nil && len(manifest) > 0 {
manifestDigest = digest.Canonical.FromBytes(manifest).String()
}
inspectInfo, inspectErr := img.Inspect(ctx)
if inspectErr == nil && inspectInfo != nil {
created = *inspectInfo.Created
inspectable, inspectableErr := image.FromUnparsedImage(ctx, sys, image.UnparsedInstance(img, nil))
if inspectableErr == nil && inspectable != nil {
inspectInfo, inspectErr := inspectable.Inspect(ctx)
if inspectErr == nil && inspectInfo != nil {
created = *inspectInfo.Created
}
}
if sizeErr != nil {
err = sizeErr
} else if manifestErr != nil {
err = manifestErr
} else if inspectErr != nil {
err = inspectErr
}
return created, manifestDigest, imgSize, err
}
Expand Down Expand Up @@ -224,6 +226,9 @@ func getImageConfig(ctx context.Context, sc *types.SystemContext, store storage.
}
image, err := ref.NewImage(ctx, sc)
if err != nil {
if img, err2 := store.Image(imageID); err2 == nil && img.ID == imageID {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it that there is no "ImageAlreadyExists" err code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage library can return errors when a caller tries to create an image names or an ID that are specified for the new image are already in use, yes, but here we're trying to avoid fatally breaking getParent() and getChildren(), which would otherwise break imageIsParent(), which would in turn produce an error when buildah images tried to look at an image that doesn't have a configuration blob, which is not an error for any image which exists solely to hold a manifest list.

return nil, nil
}
return nil, errors.Wrapf(err, "unable to open image %q", imageID)
}
config, err := image.OCIConfig(ctx)
Expand Down Expand Up @@ -283,6 +288,9 @@ func getParent(ctx context.Context, sc *types.SystemContext, store storage.Store
if err != nil {
return nil, errors.Wrapf(err, "unable to read configuration from image %q", child.ID)
}
if childConfig == nil {
return nil, nil
}
for _, parent := range images {
if parent.ID == child.ID {
continue
Expand All @@ -294,6 +302,9 @@ func getParent(ctx context.Context, sc *types.SystemContext, store storage.Store
if err != nil {
return nil, errors.Wrapf(err, "unable to read configuration from image %q", parent.ID)
}
if parentConfig == nil {
continue
}
if len(parentConfig.History)+1 != len(childConfig.History) {
continue
}
Expand Down Expand Up @@ -331,6 +342,9 @@ func getChildren(ctx context.Context, sc *types.SystemContext, store storage.Sto
if err != nil {
return nil, errors.Wrapf(err, "unable to read configuration from image %q", parent.ID)
}
if parentConfig == nil {
return nil, nil
}
for _, child := range images {
if child.ID == parent.ID {
continue
Expand All @@ -349,6 +363,9 @@ func getChildren(ctx context.Context, sc *types.SystemContext, store storage.Sto
if err != nil {
return nil, errors.Wrapf(err, "unable to read configuration from image %q", child.ID)
}
if childConfig == nil {
continue
}
if len(parentConfig.History)+1 != len(childConfig.History) {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/buildah/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/containers/buildah"
is "github.com/containers/image/v4/storage"
"github.com/containers/image/v4/types"
is "github.com/containers/image/v5/storage"
"github.com/containers/image/v5/types"
"github.com/containers/storage"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestGetSize(t *testing.T) {
t.Fatalf("Error reading images: %v", err)
}

_, _, _, err = getDateAndDigestAndSize(getContext(), store, images[0])
_, _, _, err = getDateAndDigestAndSize(getContext(), &testSystemContext, store, images[0])
if err != nil {
t.Error(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/buildah/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/formats"
"github.com/containers/buildah/pkg/parse"
is "github.com/containers/image/v4/storage"
"github.com/containers/image/v4/types"
is "github.com/containers/image/v5/storage"
"github.com/containers/image/v5/types"
"github.com/containers/storage"
units "github.com/docker/go-units"
"github.com/pkg/errors"
Expand Down Expand Up @@ -271,7 +271,7 @@ func outputImages(ctx context.Context, systemContext *types.SystemContext, store
opts.readOnly = true
}
createdTime := image.Created
inspectedTime, digest, size, _ := getDateAndDigestAndSize(ctx, store, image)
inspectedTime, digest, size, _ := getDateAndDigestAndSize(ctx, systemContext, store, image)
if !inspectedTime.IsZero() {
if createdTime != inspectedTime {
logrus.Debugf("image record and configuration disagree on the image's creation time for %q, using the configuration creation time: %s", image.ID, inspectedTime)
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildah/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/containers/buildah/util"
is "github.com/containers/image/v4/storage"
is "github.com/containers/image/v5/storage"
"github.com/containers/storage"
)

Expand Down
15 changes: 8 additions & 7 deletions cmd/buildah/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (

buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/image/v4/docker"
"github.com/containers/image/v4/pkg/docker/config"
"github.com/containers/image/v5/docker"
"github.com/containers/image/v5/pkg/docker/config"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)
Expand Down Expand Up @@ -116,15 +117,15 @@ func loginCmd(c *cobra.Command, args []string, iopts *loginReply) error {
return err
}
}
switch err {
case nil:
if err == nil {
fmt.Println("Login Succeeded!")
return nil
case docker.ErrUnauthorizedForCredentials:
}
if unauthorized, ok := err.(docker.ErrUnauthorizedForCredentials); ok {
logrus.Debugf("error logging into %q: %v", server, unauthorized)
return errors.Errorf("error logging into %q: invalid username/password", server)
default:
return errors.Wrapf(err, "error authenticating creds for %q", server)
}
return errors.Wrapf(err, "error authenticating creds for %q", server)
}

// GetUserAndPass gets the username and password from STDIN if not given
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildah/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/image/v4/pkg/docker/config"
"github.com/containers/image/v5/pkg/docker/config"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down
Loading