Commit Graph

137 Commits

Author SHA1 Message Date
Miloslav Trmač b941c6bf41 Add private.ImageDestination.NoteOriginalOCIConfig
For now, this only adds the API, nothing actually benefits from
it yet.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-28 19:34:59 +01:00
Miloslav Trmač 91d22b295c Introduce private.ImageDestination.CommitWithOptions
This only adds an API method, it does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-11-04 17:22:49 +01:00
Miloslav Trmač 04deef6fe6 Call .Validate() before digest.Hex() / digest.Encoded()
... to prevent panics if the value does not contain a :, or other unexpected
values (e.g. a path traversal).

Don't bother on paths where we computed the digest ourselves, or it is already trusted
for other reasons.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-09 15:59:32 +02:00
Giuseppe Scrivano 21beb2820d
directory: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-11 09:54:09 +02:00
Miloslav Trmač ffd21be778 Rename *BlobMatchesRequiredCompression to *CandidateMatchesTryReusingBlobOptions
... because we will add more reasons to reject a match.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-02 23:19:37 +01:00
Aditya R 4f8c03922a
blob: TryReusingBlobWithOptions consider requiredCompression if set
TryReusingBlob now contains a new option `RequiredCompression` which
filters the blob by checking against a compression of the blob which is
considerd to be resued, in case `RequiredCompression` is set and `info`
of the blob being reused does not matches, no blob is returned.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-07-12 23:58:41 +05:30
Miloslav Trmač d9a7aa0631 Return private.UploadedBlob from PutBlobWithOptions
This is a subset of types.BlobInfo the transports
actually should deal with, to be much more explicit
about what the transports are responsible for.

Should not change behavior, in practice.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-03-22 22:31:42 +01:00
Miloslav Trmač d12d1d1b59 Return private.ReusedBlob from TryReusingBlobWithOptions
This is a subset of types.BlobInfo the transports
actually should deal with. Also tighten the semantics a bit,
to be much more explicit about what the transports are responsible for.

This allows us to stop tracking MIME types in storage.addedLayerInfo,
so simplify that.

Then fix the generic code so that blob annotations are not discarded
on blob reuse.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-03-22 22:31:26 +01:00
Aditya R 8a1955ba80
manifest: introduce internal/manifest.ListInternal and freeze manifest.List
Flips dependency of internal and public manifest.List API and introduces
private manifest.List API which will be extended in future for new
features.

[NO NEW TESTS NEEDED]
[NO TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
2023-02-08 11:21:46 +05:30
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č b80aac653c Actually test the caller-requested function
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-27 09:06:24 +02:00
Pedro Tôrres b8aad11d36
set directory transport destination as thread-safe
Signed-off-by: Pedro Tôrres <t0rr3sp3dr0@gmail.com>
2022-10-13 16:30:37 -03: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č ad2c293d75 Introduce ImageSource.GetSignaturesWithFormat
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:44:22 +02:00
Miloslav Trmač a5ad6604a4 Introduce ImageDestination.PutSignaturesWithFormat
NOTE: This makes implementation choices:
- dir, docker LOOKASIDE, ostree and storage are going to store the
  generic-format blobs, and can represent any future formats
  of signatures.
- docker X-R-S-S and OpenShift only accept simple signatures,
  and fail when copying the other kind.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:44:22 +02:00
Miloslav Trmač fbf83e451f Add an internal/signature package
We need something to wrap (format ID, actual data).

And a shared helper for a file/blob representation for things like
dir or c/storage.

This looks quite immature.

Tests of the non-simple signing will only be added with support for that format.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:44:19 +02:00
Miloslav Trmač 654a6a660e Add impl.DoesNotAffectLayerInfosForCopy, use it to reduce boilerplate
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:24 +02:00
Miloslav Trmač cbd13d3dcc Add internal/imagesource/impl.Properties, use it to reduce boilerplate
This matches internal/imagedestination/impl.Properties; it's not
quite worth it for the single value, but the consistency is
attractive.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:24 +02:00
Miloslav Trmač 592371c8be Implement private.ImageSource in non-forwarding transports
This sets up the precedent that all transports should primarily implement
the private interface; that will allow us to make future changes to the
private interface easier, because we can just change the public interface
wrappers in a single place instead of modifying transports - especially
as more stubs are added soonish.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:23 +02:00
Miloslav Trmač 85db72593e Add Imagedestination.impl.Properties.AcceptsForeignLayerURLs
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:34:26 +02:00
Miloslav Trmač c3e1251c58 Add imagedestination.impl.Properties.DesiredLayerCompression
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:33:50 +02:00
Miloslav Trmač 52f1c33976 Add imagedestination.impl.Properties.SupportedManifestMIMETypes
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:33:19 +02:00
Miloslav Trmač eed518d05d Add internal/imagedestination/impl.Properties, use it to reduce boilerplate
It's very annoying that Go allows silent zero-initilization,
and we have neither mandatory constructors nor parameter labels,
i.e. a forgotten field does not cause a compile-time error.  For _private_
transport implementations, relying on human review is just about acceptable.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:32:31 +02:00
Miloslav Trmač bebd5b6c59 Add stubs.NoSignatures and stubs.AlwaysSupportsSignatures, use them in transports
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:32:02 +02:00
Miloslav Trmač 5e75f679a6 Implement private.ImageDestination in non-forwarding transports
This sets up the precedent that all transports should primarily implement
the private interface; that will allow us to make future changes to the
private interface easier, because we can just change the public interface
wrappers in a single place instead of modifying transports - especially
as more stubs are added soonish.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:29:14 +02:00
Miloslav Trmač 1799b98724 Only create dirImageDestination when all checks are done
This makes it clearer that dirImageDestination is only
used in a valid state.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-02 01:25:23 +02:00
Miloslav Trmač 1eb6aa9ba9 Replace uses of perrors.New with errors.New
This removes the stack trace, potentially visible
to callers.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 22:55:36 +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č 3852bb9a83 Fix typos
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 21:47:41 +02:00
Miloslav Trmač 6accca5e04 Remove uses of errors.Errorf
This means we won't save the stack, which is cheaper
(and possibly might break callers' format strings that
want to print the stack, but we never promised the stack
to be available).

Use either fmt.Errorf, or errors.New (usually as a local
edit, not carring about errors.new vs. pkg/errors.New;
that's going to be cleaned up later).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-30 21:45:07 +02:00
Miloslav Trmač 08a6499933 Add image.FromReference, replace most users of image.FromSource
This avoids some repetition, and (in all but one case) fixes
a missing .Close() on a failure path.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-11 01:25:44 +02:00
Miloslav Trmač 320a1ff585 Move all internal users of image/v5/image to image/v5/internal/image
... to skip the compatibility layer.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-11 01:25:44 +02:00
Miloslav Trmač 7152f888b9 Update users of deprecated io/ioutil
Mostly just name changes that should not change behavior,
apart from ioutil.ReadDir -> os.ReadDir avoiding per-item
lstat(2) in some cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 20:46:48 +02:00
Miloslav Trmač 9a9904944d Use testing.T.TempDir()
... to simplify tests.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Miloslav Trmač 34d7a624d8 Use assert.ErrorContains
...added in github.com/stretchr/testify 1.7.1.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-16 15:29:36 +01:00
Miloslav Trmač bc2f150462 Don't unnecessarily compute the blob digest in PutBlob
Introduce internal/putblobdigest.Digester to encapsulate
the two alternatives, so that the PutBlob implementations only
need to plug it in.

Then use it throughout: let PutBlob use caller-provided digest
values, if any (and they use the right algorithm).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-23 14:58:56 +02:00
Miloslav Trmač a2c13e95f7 Reorganize PutBlob implementations a bit
Mostly remove some extra variables, instead modify stream
by wrapping it in io.TeeReader()s.

In dockerImageDestination, move more of the pipeline
construction outside of the uploadReader closure, and
use consecutiveio.TeeReader()s instead of io.MultiWriter.

Should not change (observable) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-23 14:58:56 +02:00
Miloslav Trmač 91075c973b Rename computedDigest to blobDigest
It will not always be computed in PutBlob in the future.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-23 14:58:55 +02:00
Miloslav Trmač 9b911933cf Document that PutBlob callers must only provide validated digests
This was always sort of implied, and we now rely on that explicitly
to avoid computing the digests; it turns out the digest computation
can consume a very noticeable amount of CPU time.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-08-23 14:58:55 +02:00
Silvio Moioli e3f0cac14a
Prevent simultaneous compression and decompression
Signed-off-by: Silvio Moioli <moio@suse.com>
2021-07-27 14:20:45 +02:00
Silvio Moioli 401b391cc1
refactoring per PR comments
Signed-off-by: Silvio Moioli <moio@suse.com>
2021-07-27 14:04:18 +02:00
Silvio Moioli 3556c3159a
Add support for decompressing while copying to dir://
Signed-off-by: Silvio Moioli <moio@suse.com>
2021-07-27 13:51:14 +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č d05298862a Improve directory.TestGetPutSignatures
- Use a different manifest and manifest list
- Write per-arch manifest before the top-level one
- Same for signatures
- Don't write the top-level manifest twice

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-06-22 21:45:51 +02:00
Miloslav Trmač e3aa82e5c9 Document the unparsedToplevel parameter to Commit
... and acknowledge that various tests are strictly speaking
invalid, to reinforce that real callers must not pass nil.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-06-22 21:45:50 +02:00
Daniel J Walsh 1fc5bea27b
Fix up errors linter is complaining about
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-19 17:03:52 -05:00
Nalin Dahyabhai 5364600209 blobinfocache: track compression types for locations
Extend the blob info cache to also cache the name of the type of
compression used on a blob that we've seen, or specific values that
indicate that we know the blob was not compressed, or that we don't
know whether or not it was compressed.

New methods for adding known blob-compression pairs and reading
candidate locations including compression information are part of a new
internal BlobInfoCache2 interface which the library's BlobInfoCache
implementors also implement.

When we copy a blob, try to record the state of compression for the
source blob, and if we applied any changes, the blob we produced.

Make sure that when TryReusingBlob successfully uses a blob from the
blob info cache, that it provides compression information in the
BlobInfo that it returns, so that manifests can be updated to describe
layers using the correct MIME types.

When attempting to write a manifest, if a manifest can't be written
because layers were compressed using an algorithm which can't be
expressed using that manifest type, continue on to trying other manifest
formats.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-01-16 13:58:15 -05:00
Daniel J Walsh 33bcba75bb
Fix problems found by codespell
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-15 10:17:41 -04:00
Boris Kuschel fd5888f999 Add comment about chmod
Signed-off-by: Boris Kuschel <boris.kuschel@qlik.com>
2020-01-28 08:49:07 -05:00
Boris Kuschel d034e89be5 Windows fixes for dir: destination
Signed-off-by: Boris Kuschel <boris.kuschel@qlik.com>
2020-01-28 08:21:33 -05:00