From ea1543a0773cf4ead661009850154ddcde57b0e5 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Fri, 10 Nov 2023 17:39:01 +0530 Subject: [PATCH] blobcacheinfo,test: blobs must be resued when pushing across registry It seems we try to reuse blobs only for the specified registry, however we can have valid known compressed digests across registry as well following pr attempts to use that by doing following steps. * `CandidateLocations2` now processes all known blobs and appends them to returned candidates at the lowest priority. As a result when `TryReusingBlob` tries to process these candidates and if the blobs filtered by the `Opaque` set by the `transport` fail to match then attempt is made against all known blobs (ones which do not belong to the current registry). * Increase the sample set of potential blob reuse to all known compressed digests , also involving the one which do not belong to current registry. * If a blob is found match it against the registry where we are attempting to push. If blob is already there consider it a `CACHE HIT!` and reply skipping blob, since its already there. ---- ```console $ skopeo copy docker://registry.fedoraproject.org/fedora-minimal docker://quay.io/fl/test:some-tag $ buildah pull registry.fedoraproject.org/fedora-minimal $ buildah tag registry.fedoraproject.org/fedora-minimal quay.io/fl/test $ buildah push quay.io/fl/test ``` ```console Getting image source signatures Copying blob a3497ca15bbf skipped: already exists Copying config f7e02de757 done Writing manifest to image destination Storing signatures ``` Testing: https://github.com/containers/image/pull/1645 Signed-off-by: Aditya R --- tests/blobcache.bats | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/blobcache.bats b/tests/blobcache.bats index 56c872e8283..cb0972bb949 100644 --- a/tests/blobcache.bats +++ b/tests/blobcache.bats @@ -55,6 +55,31 @@ function _check_matches() { expect_output --from="$unmatched" "$5" "$6 should not match" } +# Integration test for https://github.com/containers/image/pull/1645 +@test "blobcache: blobs must be reused when pushing across registry" { + start_registry + run_buildah login --tls-verify=false --authfile ${TEST_SCRATCH_DIR}/test.auth --username testuser --password testpassword localhost:${REGISTRY_PORT} + run podman run --rm --mount type=bind,src=${TEST_SCRATCH_DIR}/test.auth,target=/test.auth,Z --net host quay.io/skopeo/stable copy --preserve-digests --authfile=/test.auth --tls-verify=false docker://registry.fedoraproject.org/fedora-minimal docker://localhost:${REGISTRY_PORT}/test + + # Clear local image and c/image's blob-info-cache + run_buildah rmi --all -f + if is_rootless; + then + run rm $HOME/.local/share/containers/cache/blob-info-cache-v1.sqlite + assert "$status" -eq 0 "status of `run rm $HOME/.local/share/containers/cache/blob-info-cache-v1.sqlite` must be 0" + else + run rm /var/lib/containers/cache/blob-info-cache-v1.sqlite + assert "$status" -eq 0 "status of `run rm /var/lib/containers/cache/blob-info-cache-v1.sqlite` must be 0" + fi + + # In first push blob must be skipped after vendoring https://github.com/containers/image/pull/1645 + run_buildah pull registry.fedoraproject.org/fedora-minimal + run_buildah images -a --format '{{.ID}}' + cid=$output + run_buildah --log-level debug push --tls-verify=false --authfile ${TEST_SCRATCH_DIR}/test.auth $cid docker://localhost:${REGISTRY_PORT}/test + expect_output --substring "Skipping blob" +} + @test "blobcache-commit" { blobcachedir=${TEST_SCRATCH_DIR}/cache mkdir -p ${blobcachedir}