Commit Graph

67 Commits

Author SHA1 Message Date
Miloslav Trmač 8dabf442db Remove obsolete build tag syntax
per (go fix ./...).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-03-12 20:20:16 +01:00
Miloslav Trmač 175ffae56f Improve an error message
We are seeing
> reference "[overlay@...]quay.io/...@sha256:..." does not resolve to an image ID: identifier is not an image

which is misleading; hide the ErrNoSuchImage text.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-19 17:14:15 +01:00
Kir Kolyshkin dffce6fc3d Use %w for error wrapping
Some code was not using it while it should (this allows a caller to
better inspect the error, if a need arises).

Note in a single case where we have two errors, we only make the
"primary" one unwrappable (by using %w), and explicitly convert the
"secondary" one to a string (which is a way to tell a code reviewer
and a linter that we don't want it to be unwrappable).

Found by errorlint linter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-08-19 13:30:40 -07:00
Miloslav Trmač f2743a47eb Call .Validate() before digest.Digest.String() if necessary
... to prevent unexpected behavior on invalid values.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-09 15:59:42 +02:00
Miloslav Trmač c936932f2a Use "maps" and "slices" from the standard library
... except where we need maps.Keys().

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-22 20:24:31 +02:00
Miloslav Trmač 4992180f28 Improve documentation of ResolveReference
- Document the error returned if image is not found
- Also document it for the internal resolveImage, to record
  the commitment
- Update the deprecation comments to warn about the error
  return value change

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-11-02 19:38:51 +01:00
Miloslav Trmač 6cb88ae2e6 Add storage.ResolveReference; deprecate GetImage and GetStoreImage
See the added comments for details.

This allows things like
> ref := ParseReference(userInput)
> ref2, img := ResolveReference(ref)
> src := ref2.NewImageSource

while ensuring that img and src are _guaranteed_ to refer
to the same image.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-10-25 14:54:27 +02:00
Miloslav Trmač bca868f393 Fix various unused parameters
Usually by removing them, sometimes by actually using an already-available value.

golangci-lint linter: unparam

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-14 19:46:41 +01:00
Miloslav Trmač f2c0a16b78 Use short-form assignments in various places
golangci-lint linter: gocritic

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:23:14 +01:00
Miloslav Trmač f43fe85e9e Remove duplicate words in comments
golangci-lint linter: dupword

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:22:09 +01:00
Miloslav Trmač 23a22f1f93 Use golang.org/x/exp to avoid open-coded loops.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-03 18:33:34 +01:00
Sascha Grunert 849dd70143 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-13 16:50:50 +02:00
Miloslav Trmač 72550dd582 Always refer to pkg/errors as perrors
This will allow imports of errors and pkg/errors to
coexist in a single package, avoid adding accidental
new uses via errors.New(), make any potential new
additions more visible in reviews.

Files that can import errors only (typically
because they only use errors.New) have been updated to
that import instead of renaming.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 22:04:10 +02:00
Miloslav Trmač 1e7020d1d7 Run (gofmt -s -w)
Go 1.17 introduces a much more reasonable build constraint format,
and gofmt now fails without using it.

Sadly we still need the old format _as well_, to support <1.17 builds.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-21 05:29:39 +02:00
Daniel J Walsh 1f79791095
Do not prepend Error on each wrapped error message.
Podman and other tools already add Error: to the front of returned error
message, and this ends up as a stutter.

podman pull fedora.io/fred
Trying to pull fedora.io/fred:latest...
Error: Error initializing image from source docker://fedora.io/fred:latest: invalid character '<' looking for beginning of value

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-07-01 05:01:27 -04:00
Miloslav Trmač 8298d2d8a3 Simplify digest references to manifest lists in c/storage
- If the digest references a single-platform manifest,
  all matching images will have the same manifest, same config,
  and same behavior of the dummy index created by
  imageMatchesSystemContext ; so don't build that dummy index
  and rename the function to multiArchImageMatchesSystemContext .
- If the digest references a multi-platform list, just check
  whether ChooseInstance would chose the current image;
  don't check _both_ ChooseInstance based on the multi-platform
  list and config values through the dummy index.
  The original pull did both (ChooseInstance to choose
  a per-platform image, and
  copy.checkImageDestinationForCurrentRuntime(), so they
  are expected to match (and we don't do a config check
  vs. the current SystemContext to refuse handling
  single-platform images in c/storage, in general).
- Even more verbosely document the situation,
  explaining how we can end up with multiple images that
  match the same digest, and what we want to achieve.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-06-24 01:18:25 +02:00
Miloslav Trmač c31232f617 Add storage.Transport.NewStoreReference
To allow callers to create storage reference without having to
parse strings.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-11 12:52:17 +01:00
Ivan Voronchihin 4d6079501f Fix this value is never used
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:47:55 +04:00
bpopovschi 81308749f7 Added possibility to overwrite default tmp dir for big files
Signed-off-by: bpopovschi <zyqsempai@mail.ru>
2019-11-20 17:18:05 +02:00
Miloslav Trmač 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Nalin Dahyabhai ca5fe04cb3 Add manifest list support
Add the manifest.List interface, and implementations for OCIv1 Index and
Docker Schema2List documents.

Add an instanceDigest parameter to PutManifest(), PutSignatures(), and
LayerInfosForCopy, for symmetry with GetManifest() and GetSignatures().
Return an error if the instanceDigest is supplied to destinations which
don't support them, and add stubs that do so even to the transports
which would support it, so that we don't break compilation here.

Add a MultipleImages flag to copy.Options, and if the source for a copy
operation contains multiple images, copy all of the images if we can.
If we can't copy them all, but we were told to, return an error.

Use the generic manifest list API to select a single image to copy from
a list, so that we aren't just limited to the Docker manifest list
format for those cases.

When guessing at the type of a manifest, if the manifest contains a list
of manifests, use its declared MIME type if it included one, else assume
it's an OCI index, because an OCI index doesn't include its MIME type.

When copying, switch from using an encode-then-compare of the original
and updated versions of the list to checking if the instance list was
changed (one of the things we might have changed) or if its type has
changed due to conversion (the other change we might have made).  If
neither has changed, then we don't need to change the encoded value of
the manifest.

When copying, when checking for a digest mismatch in a target image
reference, ignore a mismatch between the digest in the reference and the
digest of the main manifest if we're copying one element from a list,
and the digest in the reference matches the digest of the manifest list.

When copying, if conversion of manifests for single images is being
forced, convert manifest lists to the corresponding list types.

When copying, supply the unparsed top level to Commit() by attaching the
value to the context.Context.

Support manifest lists in the directory transport by using the instance
digest as a prefix of the filename used to store a manifest or a piece
of signature data.

Support manifest lists in the oci-layout transport by accepting indexes
as we do images, and stop guessing about Platform values to add to the
top-level index.

Support storing manifest lists to registries in the docker: transport by
using the manifest digest when we're writing one image as part of
pushing a list of them, and by using the instance digest when reading or
writing signature data, when one is specified, or the cached digest of
the non-instanced digest when one is not specified.

Add partial support for manifest lists to the storage transport: when
committing one image from a list into storage, also add a copy of the
manifest list by extracting it from the context.Context.  The logic is
already in place to enable locating an image using any of multiple
manifest digests.

When writing an image that has an instanceDigest value (meaning it's a
secondary image), don't try to generate a canonical reference to add to
the image's list of names if the reference for the primary image doesn't
contain a name.  That should only happen if we're writing using just an
image ID, which is unlikely, but we still need to handle it.

Avoid computing the digest of the manifest, or retrieving the
either-a-tag-or-a-digest value from the target reference, if we're given
an instanceDigest, which would override them anyway.

Move the check for non-nil instanceDigest values up into the main
PutSignatures() method instead of duplicating it in the per-strategy
helpers.

Add mention of the instanceDigest parameter and its use to various
PutManifest, PutSignatures, and LayerInfosForCopy implementations and
their declarations in interfaces.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-10-18 15:15:13 -04:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
Nalin Dahyabhai c5de929f5e storage: set a returned image's .Digest to the specified digest
If the reference that we use to locate an image includes a digest, set
the returned Image's Digest field to match it.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-11 15:14:51 -05:00
Miloslav Trmač 62ed2a82ec Drop storageReference.breakDockerReference and storageImageDestination.publicRef
Now that storageImageDestination.IgnoreEmbeddedDockerReference exists, this hack
is no longer needed.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 9fd3ee4414 RFC UNTESTED: Only load an image once in resolveImage
If we find an image and determine the ID, it seems pointless to load it again by ID
immediately afterwards.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač b69da33122 Add a name:tag parent policy namespace for name:tag@digest images
Again, as suggested elsewhere, maybe we should just refuse such images.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 896003d6c8 Simplify StringWithinTransport and PolicyConfigurationIdentity
Instead of three cases, each handling a subset of fields, construct
the return value in steps, making it clear how the fields fit together.

(The code could, in theory, return just a [storeSpec] with no name nor ID;
but newReference has just been edited to refuse to create such values.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 9d0ef1b2ac Enforce that a reference has at least one of "named" and "id"
The code assumes that anyway, and this allows us to move an unreachable
check from ParseStoreReference into a testable one in newReference.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač c5e28a6b12 Rename storageReference.completeReference to storageReference.named
Now that the implementation transition is complete, the value being
"complete" is no longer a differentiating factor; instead, use a shorter,
easier to use name.

(We could also use just "ref", but there are several kinds of references
around, this suggests more about the type.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 46174f33d4 Remove storageReference.reference
Finally, storageReference is just a (store, reference.Named, ID) triple.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 3ebfd20d46 Eliminate all users of storageReference.reference
Use completeReference.String() or (completeReference != nil) instead.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 841cbfeabd Remove storageReference.name
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 059c0fc4d7 Simplify storageReference.DockerReference
Now that all data for DockerReference comes from completeReference,
just return it directly, and eliminate the weird theoretical
failure paths where we can silently return incorrect data.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 5bc7884770 Remove all users of storageReference.name
They are mostly used only for boolean presence checking; only DockerReference
actually uses the value; in that case the transition to completeReference
may add a digest value, but a few lines below we do a, now redundant,
WithDigest computation which would have added the same digest anyway.

NOTE: This changes PolicyConfigurationIdentity and PolicyConfigurationNamespaces,
which now return values even if breakDockerReference.  That seems to be the right
thing to do anyway.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 70afa3bbb1 Remove storageReference.digest
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač d801ec64a8 Remove all users of storageReference.digest
Extract the value from completeReference instead

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 91508beeec Remove storageReference.tag
Now that it is no longer used, remove its initialization as well.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 5ad5ea2b69 Remove the only user of storageReference.tag
Extract the value from completeReference instead.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač acf13f4d89 Fix storageReference.tag for name:tag@digest
name:tag@digest is actually a valid input to reference.ParseNormalizedNamed;
the code used to set name:tag in s.name, but leave s.tag empty.

That happened to mostly work correctly, but for the wrong reasons.  So, fix
setting s.tag for name:tag@digest inputs, and then update DockerReference
to handle such cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 5b62b7d2ae Introduce storageReference.completeReference
This starts a series of commits reworking storageReference to rely more on
reference.Named than on a set of independent string members.

First, introduce completeReference: this is a reference.Named, like
storageReference.name, but it includes both the tag and the digest, possibly
at the same time.  For now, the field is only set, never used; users will be
ported one aspect at a time in the following commits; ultimately it will be
renamed to something shorter after we eliminate storageReference.name as well.

Also, to preserve the ImageDestination.DockerReference() ... interesting
behavior ..., add an explicit breakDockerReference boolean.  This will allow
us to rely on completeDockerReference being always available, while keeping the
existing behavior unchanged until we can improve upon it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 44067112c2 UNTESTED: Extract duplicate code from resolveImage
Extract an imageMatchesRepo helper from resolveImage.  This avoids
duplicating it, and a separate helper with "return" is easier to follow
than labeled breaks.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač c0bc99122f UNTESTED: Match repositories using .Name() instead of FamiliarName()
This should produce equivalent results, but Name() uses the fully-qualified
format (i.e. is safer against normalization changes), while FamiliarName is
primarily intended for UI output, and also more costly to compute.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač cbb7c078af Don't use reference.TrimNamed().String()
reference.TrimNamed(r).String() is equivalent to r.Name(), just more expensive.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 225e91a1ff Re-add the :tag or @digest form at start of PolicyConfigurationNamespaces
... if PolicyConfigurationIdentity includes @id.  At least the :tag form is clearly useful.

This does not handle the name:tag@digest case (which _can_ happen), where the tag is
currently recorded inside s.name but not s.tag; the possible code handling it would
be very non-obviously pointing out this difference.  For now, only leave a FIXME in the test.
Maybe it should be handled by refusing such input instead; e.g. that's what
docker.Transport does.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač cce388188e Add more test cases, along with a few FIXMEs
This does not change the implementation at all yet.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-06-04 16:50:17 +02:00
Miloslav Trmač 8968eb0bc3 Remove a few unused context.context parameters from private functions
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-04-10 19:12:04 +02:00
Mike Lundy 369c44212b Put context.Context arguments on almost everything
- Network IO paths should react to cancels now.
- File IO paths generally still won't.
- `SystemContext` objects have been renamed to `sys` to leave `ctx`
  available for the stdlib context objects.

Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
2018-04-07 04:34:51 -07:00
Nalin Dahyabhai 179c5ae10a storage: log image-not-resolving at debug level, not error
Log the message about a given reference not being resolvable to an image
ID at the debug level rather than as an error, and wrap the error that
we return in case the caller wants to relay the reference's value back
as part of the error.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-12-14 16:55:20 -05:00
Nalin Dahyabhai b937756b87 storage: learn to look up images using canonical refs
When attempting to locate an image, if we have a name+digest (i.e.,
canonical reference), use the store's new ImagesByDigest() method to
search for images that match a given digest, and which have at least one
name that matches the specified name, treating the reference as an
implicit name so long as it has an explicit name that matches (give or
take a tag).

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-12-11 16:01:06 -05:00
Miloslav Trmač 4861938566 UNFINISHED: Use manifest.Manifest for editing the manifest in storageImageSource
Do not construct storageImageSource around storageImage around
storageUnnamedImageSource; instead, use the ~simple storageUnnamedImageSource
implementations, except using manifest.Manifest to edit layers in GetManifest.

Revert storageImage to only implementing .Size()

Still modifies the input reference, which breaks assumptions of signature validation.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-12-11 16:01:06 -05:00