From f6c241e827a963da87754b34205fb953c1654fd9 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 | 35 +++++++++++++++++++++++++++++++++++ tests/test_runner.sh | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/blobcache.bats b/tests/blobcache.bats index 56c872e8283..686379d522a 100644 --- a/tests/blobcache.bats +++ b/tests/blobcache.bats @@ -55,6 +55,41 @@ 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} + outputdir=${TEST_SCRATCH_DIR}/outputdir + mkdir -p ${outputdir} + run podman run --rm --mount type=bind,src=${TEST_SCRATCH_DIR}/test.auth,target=/test.auth,Z --mount type=bind,src=${outputdir},target=/output,Z --net host quay.io/skopeo/stable copy --preserve-digests --authfile=/test.auth --tls-verify=false docker://registry.fedoraproject.org/fedora-minimal dir:/output + + run_buildah rmi --all -f + run_buildah pull dir:${outputdir} + 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 + # must not contain "Skipping blob" since push must happen + assert "$output" !~ "Skipping blob" + + # 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 dir:${outputdir} + 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} diff --git a/tests/test_runner.sh b/tests/test_runner.sh index a93654b3721..74345566893 100755 --- a/tests/test_runner.sh +++ b/tests/test_runner.sh @@ -19,4 +19,4 @@ function execute() { TESTS=${@:-.} # Run the tests. -execute time bats --tap $TESTS +execute time bats --tap $TESTS --filter "\"across registry\""