Skip to content

Commit

Permalink
update to latest libimage
Browse files Browse the repository at this point in the history
Update Buildah to the latest libimage.  Migrating Podman over to
libimage entailed a number of fixes and changes to libimage which
we need to account for in Buildah.

Most notably:

 * `(*Runtime).LookupImage()` now returns `storage.ErrImageUnknown`
   instead of `nil` in case no matching image is found.

 * `(*Runtime).LookupImage()` now does quite a bit more work finding
   a local image and will also look at the repotags (or digests) of
   all local images if needed.

 * The signature of `(*Runtime).RemoveImages()` was changed and now
   returns a slice of reports and errors.  The reports aggregate the
   data of a removed image which allows the function to be used by
   `podman image prune` which is also interested in the size of the
   removed data.  The slice of errors is also needed in Podman which
   needs to have a closer look at _all_ rmi errors in order to determine
   the appropriate exit code (Docker compat).

 * `libimage/types` has been removed.  Pull policies have been merged
   into already existing logic in `pkg/config`.

Please refer to containers/podman/pull/10147 for a more detailed
changelog.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Apr 30, 2021
1 parent df864f1 commit 0d2acbc
Show file tree
Hide file tree
Showing 42 changed files with 1,713 additions and 457 deletions.
2 changes: 1 addition & 1 deletion cmd/buildah/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func formatImages(images []*libimage.Image, opts imageOptions) error {
outputParam.Size = formattedSize(size)
outputParam.ReadOnly = image.IsReadOnly()

repoTags, err := image.NamedTaggedRepoTags()
repoTags, err := image.NamedRepoTags()
if err != nil {
return err
}
Expand Down
20 changes: 14 additions & 6 deletions cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
"github.com/containers/storage"
"github.com/hashicorp/go-multierror"
digest "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -462,14 +463,21 @@ func manifestRmCmd(c *cobra.Command, args []string) error {
options := &libimage.RemoveImagesOptions{
Filters: []string{"readonly=false"},
}
untagged, removed, err := runtime.RemoveImages(context.Background(), args, options)
for _, u := range untagged {
fmt.Printf("untagged: %s\n", u)
rmiReports, rmiErrors := runtime.RemoveImages(context.Background(), args, options)
for _, r := range rmiReports {
for _, u := range r.Untagged {
fmt.Printf("untagged: %s\n", u)
}
}
for _, r := range removed {
fmt.Printf("%s\n", r)
for _, r := range rmiReports {
if r.Removed {
fmt.Printf("%s\n", r.ID)
}
}
return err

var multiE *multierror.Error
multiE = multierror.Append(multiE, rmiErrors...)
return multiE.ErrorOrNil()
}

func manifestAnnotateCmd(c *cobra.Command, args []string, opts manifestAnnotateOpts) error {
Expand Down
20 changes: 14 additions & 6 deletions cmd/buildah/rmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
buildahcli "github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/common/libimage"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -87,12 +88,19 @@ func rmiCmd(c *cobra.Command, args []string, iopts rmiOptions) error {
}
options.Force = iopts.force

untagged, removed, err := runtime.RemoveImages(context.Background(), args, options)
for _, u := range untagged {
fmt.Printf("untagged: %s\n", u)
rmiReports, rmiErrors := runtime.RemoveImages(context.Background(), args, options)
for _, r := range rmiReports {
for _, u := range r.Untagged {
fmt.Printf("untagged: %s\n", u)
}
}
for _, r := range removed {
fmt.Printf("%s\n", r)
for _, r := range rmiReports {
if r.Removed {
fmt.Printf("%s\n", r.ID)
}
}
return err

var multiE *multierror.Error
multiE = multierror.Append(multiE, rmiErrors...)
return multiE.ErrorOrNil()
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ require (
)

replace github.com/sirupsen/logrus => github.com/sirupsen/logrus v1.4.2

replace github.com/containers/common => github.com/vrothberg/common v0.0.3-0.20210430070256-9bc69171635f
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ github.com/containernetworking/cni v0.8.0/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ
github.com/containernetworking/cni v0.8.1 h1:7zpDnQ3T3s4ucOuJ/ZCLrYBxzkg0AELFfII3Epo9TmI=
github.com/containernetworking/cni v0.8.1/go.mod h1:LGwApLUm2FpoOfxTDEeq8T9ipbpZ61X79hmU3w8FmsY=
github.com/containernetworking/plugins v0.8.6/go.mod h1:qnw5mN19D8fIwkqW7oHHYDHVlzhJpcY6TQxn/fUyDDM=
github.com/containers/common v0.37.0 h1:RRyR8FITTJXfrF7J9KXKSplywY4zsXoA2kuQXMaUaNo=
github.com/containers/common v0.37.0/go.mod h1:dgbJcccCPTmncqxhma56+XW+6d5VzqGF6jtkMHyu3v0=
github.com/containers/image/v5 v5.11.1 h1:mNybUvU6zXUwcMsQaa3n+Idsru5pV+GE7k4oRuPzYi0=
github.com/containers/image/v5 v5.11.1/go.mod h1:HC9lhJ/Nz5v3w/5Co7H431kLlgzlVlOC+auD/er3OqE=
github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b h1:Q8ePgVfHDplZ7U33NwHZkrVELsZP5fYj9pM5WBZB2GE=
Expand Down Expand Up @@ -223,6 +221,8 @@ github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8l
github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/disiqueira/gotree/v3 v3.0.2 h1:ik5iuLQQoufZBNPY518dXhiO5056hyNBIK9lWhkNRq8=
github.com/disiqueira/gotree/v3 v3.0.2/go.mod h1:ZuyjE4+mUQZlbpkI24AmruZKhg3VHEgPLDY8Qk+uUu8=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
Expand Down Expand Up @@ -687,6 +687,8 @@ github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYp
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vrothberg/common v0.0.3-0.20210430070256-9bc69171635f h1:k+3j9Xko0KFRUxAEjaoCg66/pwR4w5AjMcUzfqCetkw=
github.com/vrothberg/common v0.0.3-0.20210430070256-9bc69171635f/go.mod h1:4jx2zI23wh9Jj1ozFeFHG7RoXzcU8acoADIKOLJX7BA=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11 h1:N7Z7E9UvjW+sGsEl7k/SJrvY2reP1A07MrGuCjIOjRE=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
Expand Down
9 changes: 5 additions & 4 deletions imagebuildah/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,14 @@ func (b *Executor) resolveNameToImageRef(output string) (types.ImageReference, e
return nil, err
}
// If we can resolve the image locally, make sure we use the resolved name.
localImage, resolvedName, err := runtime.LookupImage(output, nil)
_, resolvedName, err := runtime.LookupImage(output, nil)
if err != nil {
return nil, err
}
if localImage != nil {
if errors.Cause(err) != storage.ErrImageUnknown {
return nil, err
}
output = resolvedName
}

// If we cannot find an image, make sure we normalize the name
// according the conventions and rules in libimage (e.g.,
// "localhost/" prefixing).
Expand Down
4 changes: 2 additions & 2 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/containers/buildah/define"
"github.com/containers/buildah/pkg/blobcache"
"github.com/containers/common/libimage"
libimageTypes "github.com/containers/common/libimage/types"
"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/image"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/transports"
Expand Down Expand Up @@ -119,7 +119,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
return nil, err
}

pullPolicy, err := libimageTypes.ParsePullPolicy(options.PullPolicy.String())
pullPolicy, err := config.ParsePullPolicy(options.PullPolicy.String())
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/containers/buildah/define"
"github.com/containers/buildah/pkg/blobcache"
"github.com/containers/common/libimage"
libimageTypes "github.com/containers/common/libimage/types"
"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/types"
encconfig "github.com/containers/ocicrypt/config"
"github.com/containers/storage"
Expand Down Expand Up @@ -73,7 +73,7 @@ func Pull(ctx context.Context, imageName string, options PullOptions) (imageID s
libimageOptions.DestinationLookupReferenceFunc = blobcache.CacheLookupReferenceFunc(options.BlobDirectory, types.PreserveOriginal)
}

pullPolicy, err := libimageTypes.ParsePullPolicy(options.PullPolicy.String())
pullPolicy, err := config.ParsePullPolicy(options.PullPolicy.String())
if err != nil {
return "", err
}
Expand Down
6 changes: 0 additions & 6 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ func FindImage(store storage.Store, firstRegistry string, systemContext *types.S
if err != nil {
return nil, nil, err
}
if localImage == nil {
return nil, nil, errors.Wrap(storage.ErrImageUnknown, image)
}
ref, err := localImage.StorageReference()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -227,9 +224,6 @@ func AddImageNames(store storage.Store, firstRegistry string, systemContext *typ
if err != nil {
return err
}
if localImage == nil {
return errors.Errorf("could not find libimage for %s", image.ID)
}

for _, tag := range addNames {
if err := localImage.Tag(tag); err != nil {
Expand Down
52 changes: 40 additions & 12 deletions vendor/github.com/containers/common/libimage/copier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0d2acbc

Please sign in to comment.