Commit Graph

28 Commits

Author SHA1 Message Date
Miloslav Trmač a56436cb15 Use testing.T.Setenv instead of os.Setenv in tests
... to simplify and benefit from Go 1.17.

In some cases, wrap tests in testing.T.Run() to decrease
the scope, or to make the relationship between the test and the
cleanup clearer.  In some cases it's still a bit awkward
because there is no testing.T.Unsetenv, but still worth it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-14 20:57:04 +02:00
Miloslav Trmač a310b13598 Simplify blobifocache/internal/test.GenericCache
We no longer need a cleanup callback.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01: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č 3c376ba255 Use pkg/compression/types where possible
Most importantly this removes a dependency of c/image/manifest
(and thus c/image/signature) on pkg/compression and all the implementations.

Use pkg/compression/types everywhere else it is possible as well,
even if it does not remove any dependency on pkg/compression, just
to enforce the discipline.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-26 15:08:20 +02:00
Josh Soref 111bf164be Spelling
* about
* appropriate
* busybox
* candidate
* candidates
* certificate
* config
* configuration
* containers
* decompression
* directory
* does-not/match
* does/not/exist
* doesnot
* doesnotexist
* exemplary
* garbage
* gzipped
* identify
* initially
* kubernetes
* length
* marshaling
* maximum
* mybetaproduct
* overridden
* parameter
* permissive
* policyconfiguration
* protocols
* reference
* referenceable
* requirement
* response
* simultaneously
* slashes
* subobject
* successfully
* this
* uncompressed
* unmarshaled
* unmarshaler
* unmarshaling it
* unmarshaller
* valid

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-23 14:37:37 -04: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
Qi Wang 701023dd1a Set default rootless sigstore
Set default rootless sigstore to ~/.local/share/containers/sigstore if the caller is non-root.
Export the func ConfiguredSignatureStorageBase() for Podman image sign implementation.
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-09-18 15:44:24 -04:00
Tycho Andersen f5547d5015 blobinfocache: clean up after test
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2020-06-24 08:10:39 -06:00
Miloslav Trmač f9374748e6 Update import path for bbolt
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-03-23 21:10:41 +01:00
Ivan Voronchihin 33ec055725 Fix Error return value is not checked
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 19:11:22 +04:00
Ivan Voronchihin 21320ca776 Fix golangci-lint advises
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:31:04 +04:00
Ivan Voronchihin e099400a03 Delete unused
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:07:19 +04:00
Miloslav Trmač 8d21d1f112 Clean up various imports
... primarily so that imports of packages that aren't in the
standard library are all in one section.

Also correct the package in tarball/doc.go example (without verifying
the code works).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:36:44 +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
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
Valentin Rothberg 92f26c58b8 Switch to github.com/etcd-io/bbolt
github.com/boltdb/bolt is no longer maintained.

Fixes: #560
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-04-12 15:14:09 +02:00
Giuseppe Scrivano 1802aab0bf
blobinfocache: correctly detect the UID in a namespace
for tools in containers/ we are using the env variable
_CONTAINERS_ROOTLESS_UID when running in a user namespace to refer to
the rootless UID that created the user namespace.

Closes: https://github.com/containers/libpod/issues/2510#issuecomment-480066763

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-05 09:55:43 +02:00
W. Trevor King d545a196c9 pkg/blobinfocache: Split implementations into subpackages
This allows consumers who don't need the defaulting logic to pick
their desired implementation without pulling in unrelated
dependencies.  For example, it allows you to consume the memory or
NoCache implementations without pulling in github.com/boltdb.

I'd initially included blobinfocache wrappers to preserve backwards
compatibility with the old API while consumers updated to the new
APIs, but Miloslav said we don't have any backwards-compatibility
commitments at the moment [1].

Having single-implementation subpackages also allows for more generic
names (e.g. NewMemoryCache is now just New), because memory.New is
clear enough while memory.NewMemoryCache stutters.

[1]: https://github.com/containers/image/pull/602#issuecomment-471570789

Signed-off-by: W. Trevor King <wking@tremily.us>
2019-03-12 13:24:14 -07:00
Miloslav Trmač f2e9d08d33 Be even more explicit about the rules for holding mem.mutex
Document that field accesses must be done with the mutex held,
and rename uncompressedDigest to uncompressedDigestLocked.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-02-27 00:02:39 +01:00
Miloslav Trmač 9a6dfd3c57 Don't allocate a sync.Mutex separately
The documentation says
> The zero value for a Mutex is an unlocked mutex.
and memoryCache is already a passed-by-reference interface
implementation, so we don't need that extra allocation.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-02-26 23:59:19 +01:00
Valentin Rothberg 60dc9da8c8 blobinfocache: sync via mutex
Serialize method calls via a mutex to avoid concurrent accesses to the
map leading to panics.

Fixes: https://github.com/containers/libpod/issues/2420
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-02-26 13:52:19 +01:00
Valentin Rothberg 4dd54a8d08 blobinfocache: fix Debugf format error
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2018-12-11 15:37:45 +01:00
Miloslav Trmač 03f6e49dc4 Add pkg/blobinfocache.DefaultCache()
This returns a default BoltDB instance (which almost everyone
should use to maximally benefit from the cache).  The default location
is chosen to exist near the containers/storage GraphRoot (i.e.
typically on the same partition, with the same SELinux context),
both for root and rootless modes of podman.

This adds no users yet, so should not immediately change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 0032e6a3ca Add blobinfocache.NoCache
This exists primarily for the benefit of Image.ConfigBlob
and similar readers, which don't really benefit from the DiffID matching,
blob mounting, and the like, or callers like ImageDestination.PutBlob,
which actively wants to avoid using any extra cached data (because the
cache lookup should have already happened and now it would just be
redundant).

Does not add any users yet, so should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač c3f319ba3e Add blobinfocache.NewMemoryCache
This exists for tests, as a fallback when we can't use
the BoltDB locations, and possibly for non-copy.Image
users.

Has no users yet, so does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 2513b17350 Introduce a BoltDB-based implementation of BlobInfoCache
This is the primary production implementation.

Does not add any users yet, so should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 0835847b23 Add generic replacement candidate prioritization code
This will be called by at least two of the implementations.  Has no users
yet, but they will be added momentarily.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00
Miloslav Trmač 5cf409ebf2 Add implementation-independent helpers for types.BlobInfoCache tests
The helpers have no users yet, they will be added momentarily along
with the implementations to be tested.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 18:59:24 +01:00