Commit Graph

13 Commits

Author SHA1 Message Date
Oleksandr Redko ba4c7c98bb chore: remove outdated build constraints
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-03 22:56:00 +02:00
Paul Holzinger 92c98a7323 libimage: add !remote tag
To prevent the podman remote client from using libimage which causes a
lot of bloat due the c/image and c/storage dependencies add the
`!remote` tag.

This will cause a hard compile time failure if the remote client ends up
pulling in libimage.

Fixes 

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-23 15:14:43 +02:00
Valentin Rothberg 1fa8b65281 linters: enable forbidigo
Selectively disable cases that I cannot touch or don't bother spending
time on.  Future cases will be avoided.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-09-01 11:08:17 +02:00
Miloslav Trmač 75abab16f1 Update c/image with https://github.com/containers/image/pull/1944
... to update github.com/opencontainers/image-spec to v1.1.0-rc3.

Also update code for image-spec API changes.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-05-05 20:35:32 +02:00
Sascha Grunert 426d69c00f Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-12 10:54:07 +02:00
Kir Kolyshkin 2ddd7fd725 libimage: nit
Rename hist to history.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2022-03-30 11:39:49 -07:00
Aditya R 4057001d4e libimage: import should not ignore configured variant if any
`image-spec` already supports variant and if `ImportOptions` contains
any configured `Variant` it should be set on the imported image as well.

What does this fix:

Allows `podman import --variant <something> some.tar image-name` to
become functional from `no-op`

Ref: https://github.com/opencontainers/image-spec/blob/main/specs-go/v1/config.go#L93

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-25 14:27:10 +05:30
Valentin Rothberg 8eb373cb0a pkg/download: for downloading files into tmp
cmd/podman needs that functionality as well, so I figured it makes sense
to break it into a separate package to reduce code clones.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-11-10 14:41:42 +01:00
Nalin Dahyabhai 73ed145c72 Add and use libimage.Runtime.imageIDsForManifest()
When copying images into local storage, parse the manifest of the copied
image and then look up the IDs of the matching image.

There's a short period of time, between when we copy the image into
local storage and when we subsequently go to look for it using the name
that we specified for it when we copied it, when the name we wanted to
assign to the image could have been assigned to another image by another
process.

The manifest that we copied as part of the image that we copied will
still be in the right image regardless, and we can use that to find the
image's ID, and from there fill out our own Image structure that we
return to our caller.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-07-23 15:09:28 -04:00
Valentin Rothberg 1360dbce52 libimage: import: fix tags
When importing, first create the image and tag it afterwards.  This also
makes sure that an imported image *without* a tag is correctly listed as
"<none>".  Previously, such images were tagged as
"docker.io/library/sha256:$ID" (inherited from older Podman code).

Context: containers/podman/issues/10854
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-07-06 14:42:50 +02:00
cdoern 8c89f85147 fixed comments
Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
2021-06-08 08:49:15 -04:00
Valentin Rothberg bc6c57edb5 libimage: follow-up changes
The following changes were not split into smaller commits since the
entire package is still work in progress and I want to keep moving:

 * Various small fixes.

 * The internal image cache has been removed as it's a recipe for
   inconsistencies for longer running processes.  This should make
   libimage easier to use for CRI-O and a Podman service.

 * LookupImage now returns storage.ErrUnknownImage rather than nil.
   This simplifies the callers and makes sure we have a consistent
   error.

 * LookupImage is now able to handle manifests lists.  Unless the
   platform is explicitly ignored via the options, the matching
   image within the manifest list is now returned.  This greatly
   simplifies the spec generation in Podman; no callers should have
   to worry about this kind of detail.

 * LookupImage has been refactored into smaller-sized and easier to
   read functions.

 * RemoveImages has been changed to assemble the data of removed or
   untagged images.  This comes in handy for pruning images.  I am
   heavily against having a dedicated API for pruning since the it's
   really just a combination of filtering and removing images which
   RemoveImages already supports.  Hence these changes to satisfy
   the needs of `podman image prune`.
   Furthermore, it now returns an []error slice rather than a single
   error.  Again to make Podman happy which needs to inspect *all*
   errors for setting the appropriate exit code.

 * A rather large refactoring of the removal code along with very
   verbose comments.  Those were largely absent in the Podman code base
   but there many rules and contracts embedded that I partially could
   only reconstruct by manually tests and comparing to Docker.

 * Add a new `containers={true,false}` filter which allows filtering
   images whether they are used by containers (=true) or if no container
   is using them (=false).  This filter is required for pruning images
   in Podman.

 * `libimage/types` has been merged into `libimage`.  Podman has to do
   _a lot of_ massaging for the remote client already and the types
   are pretty much nailed down for the remote API.  Hence, I prefer to
   do some translation between `libimage` types and what Podman needs
   rather than splitting `libimage` in half without an obvious reason.
   This way the package is self-contained allowing for an easier
   navigation and maintenance.

 * `libimage.PullPolicy` has been merged into `pkg/config.PullPolicy`
   to have _one_ central place to deal with pull policies.  The type
   system in `pkg/config` sets "always" as the default unfortunately
   but I think consistency is more important at that point.

 * Added `CopyOptions.DirForceCompress` to enforce layer compression
   when copying to a `dir` destination.

 * We now use `github.com/disiqueira/gotree` for pretty printing image
   trees.  That greatly simplifies the code and we don't have to worry
   about the logic of printing a tree.  Note that trees are now always
   printed top down!

 * Added a new `libimage.ManifestList` type along with an API for local
   lookups and performing certain operations on it to wrap around
   `libimage/manifests` as previously done in `libpod/image` and other
   places in Podman.

 * Correct caching of `(*Image).Inspect`.

 * In addition to username, password and credentials, allow for
   speciying an identity token for copying images.  That's needed for
   Podman's remote API.

 * Make image removal more tolerant toward corrupted images.

 * A new "until=timestamp" filter that can be used by all APIs
   supporting filtering.

 * An empty string now resolves to PullPolicyMissing.

 * `(*Runtime) systemContextCopy()` returns a deep copy of the runtime's
   system context.  Golang's shallow copies are very dangerous for long
   running processes such as Podman's system service.  Hence, we need to
   make sure that base data is not altered over time.  That adds another
   external dependency but I do not see a way around that.  Long term,
   I desire a `(*containers/image/types.SystemContext).Copy()` function.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-03 15:20:40 +02:00
Valentin Rothberg 32a28aee73 new libimage package
The new `libimage` package is an attempt to consolidate the code for
managing container images and performing operations on them such as
pulling, pushing, saving, searching, local lookups, removing etc.

Over time, Buildah, CRI-O and Podman diverged with respect to managing
container images resulting in a high amount of code duplication
rendering the tools harder to maintain (e.g., bug fixes) and harder to
extend (e.g., adding new features) than necessary.

The desire to share all that code in a common library grew and this is
an attempt to address the it.

The changes as they are now pass Buildah CI [1].  Once merged into
Buildah, I expect follow up changes when migrating Podman over to
`libimage`.

Miscellaneous changes:

* Copy `podman/pkg/signal` to `pkg/signal`.

* Copy `buildah/manifests` to `image/manifests`. Note that the unit
  tests require root privileges. Skip()'s are added when running
  rootless.  Currently excluded from linting.

* Copy `buildah/pkg/manifests` to `pkg/manifests`.  Currently excluded
  from linting.

* Copy `buildah/pkg/supplemented` to `pkg/supplemented`.  Currently
  excluded from linting.

[1] github.com/containers/buildah/pull/3148

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-04-21 11:17:47 +02:00