refactor(oci): keep the extracted artifacts in an "oci" directory of the cache
Some checks are pending
ci / validate (lint) (push) Waiting to run
ci / validate (relay-lint) (push) Waiting to run
ci / validate (relay-test) (push) Waiting to run
ci / validate (validate-docs) (push) Waiting to run
ci / validate (validate-go-mod) (push) Waiting to run
ci / validate (validate-headers) (push) Waiting to run
ci / validate (validate-mocks) (push) Waiting to run
ci / binary (push) Waiting to run
ci / binary-finalize (push) Blocked by required conditions
ci / bin-image-test (push) Waiting to run
ci / relay-image-test (push) Waiting to run
ci / test (push) Waiting to run
ci / e2e (plugin, oldstable, graphdriver) (push) Waiting to run
ci / e2e (standalone, oldstable, graphdriver) (push) Waiting to run
ci / e2e (plugin, stable, containerd) (push) Waiting to run
ci / e2e (plugin, stable, graphdriver) (push) Waiting to run
ci / e2e (standalone, stable, containerd) (push) Waiting to run
ci / e2e (standalone, stable, graphdriver) (push) Waiting to run
ci / coverage (push) Blocked by required conditions
ci / ci-ok (push) Blocked by required conditions
ci / release (push) Blocked by required conditions
merge / bin-image-prepare (push) Waiting to run
merge / bin-image (push) Blocked by required conditions
merge / relay-image (push) Waiting to run
merge / module-image (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
zizmor / zizmor (push) Waiting to run

The cache of remote resources now has one directory for each kind of resource:
the checkouts of Git repositories are in "git", and the extracted OCI artifacts
are in "oci" rather than at the root of the cache.

What earlier releases left at the root of the cache is no longer looked for: an
artifact is pulled again the first time it is used.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2026-11-06 18:39:36 +01:00 • committed by Guillaume Lours
parent b5709cd309
commit 83c50295cb
2 changed files with 29 additions and 1 deletions

View file

@ -168,6 +168,7 @@ func (g *ociRemoteLoader) pullComposeArtifact(ctx context.Context, path string)
if err != nil {
return "", fmt.Errorf("initializing remote resource cache: %w", err)
}
cache = filepath.Join(cache, cacheOCIDir)
local := filepath.Join(cache, descriptor.Digest.Hex())
if cacheEntryIsComplete(local) {
@ -213,6 +214,12 @@ func (g *ociRemoteLoader) pullComposeArtifact(ctx context.Context, path string)
return local, nil
}
// cacheOCIDir is the directory of the cache which holds the extracted OCI
// artifacts, one directory for each digest, as cacheGitDir does for the checkouts of
// Git repositories. Earlier releases kept them at the root of the cache, where they
// are no longer looked for: an artifact is pulled again the first time it is used.
const cacheOCIDir = "oci"
// cacheEntryComplete is the file which marks a directory of the cache as a
// complete entry, written once everything the entry holds is in place.
const cacheEntryComplete = ".complete"

View file

@ -99,7 +99,7 @@ func setCacheRoot(t *testing.T) string {
t.Helper()
root := t.TempDir()
t.Setenv("XDG_CACHE_HOME", root)
return filepath.Join(root, "docker-compose")
return filepath.Join(root, "docker-compose", cacheOCIDir)
}
// An entry of the cache of extracted projects is complete or is not there: it
@ -253,3 +253,24 @@ func TestMoveCacheEntryDoesNotRestoreADirectoryWhichIsNotAnEntry(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, len(entries), 0, "neither the directory nor anything aside is left")
}
// The extracted artifacts are kept in a directory of the cache for OCI artifacts: an
// entry, even a complete one, which an earlier release left at the root of the
// cache is not looked for, and the artifact is extracted again in the directory.
func TestOCILoaderKeepsEntriesInTheDirectoryForOCI(t *testing.T) {
registry := newCacheTestRegistry(t)
host := registry.serve(t)
cache := setCacheRoot(t)
legacy := filepath.Join(filepath.Dir(cache), registry.digest.Hex())
assert.NilError(t, os.MkdirAll(legacy, 0o700))
assert.NilError(t, os.WriteFile(filepath.Join(legacy, "compose.yaml"), []byte("services: {}\n"), 0o600))
assert.NilError(t, os.WriteFile(filepath.Join(legacy, cacheEntryComplete), nil, 0o600))
file, err := newCacheTestLoader(host).Load(t.Context(), registry.ref(host))
assert.NilError(t, err)
assert.Equal(t, file, filepath.Join(cache, registry.digest.Hex(), "compose.yaml"))
content, err := os.ReadFile(file)
assert.NilError(t, err)
assert.Equal(t, string(content), string(registry.compose))
}