From 7f57459ebc83231b824adb6fb2e8e7f43497bd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Thu, 31 Oct 2024 19:28:51 +0100 Subject: [PATCH] WIP: Conditional image IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- test/e2e/config.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/e2e/config.go b/test/e2e/config.go index f832bd9069..a80082b7a1 100644 --- a/test/e2e/config.go +++ b/test/e2e/config.go @@ -19,9 +19,9 @@ var ( ALPINELISTTAG = "quay.io/libpod/alpine:3.10.2" ALPINELISTDIGEST = "quay.io/libpod/alpine@" + digestOrCachedTop("quay.io/libpod/alpine", "sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f") ALPINEAMD64DIGEST = "quay.io/libpod/alpine@" + digestOrCachedArch("quay.io/libpod/alpine", "amd64", "sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00") - ALPINEAMD64ID = "961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4" + ALPINEAMD64ID = idOrCached(ALPINEAMD64DIGEST, "961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4") ALPINEARM64DIGEST = "quay.io/libpod/alpine@" + digestOrCachedArch("quay.io/libpod/alpine", "arm64", "sha256:f270dcd11e64b85919c3bab66886e59d677cf657528ac0e4805d3c71e458e525") - ALPINEARM64ID = "915beeae46751fc564998c79e73a1026542e945ca4f73dc841d09ccc6c2c0672" + ALPINEARM64ID = idOrCached(ALPINEARM64DIGEST, "915beeae46751fc564998c79e73a1026542e945ca4f73dc841d09ccc6c2c0672") BUSYBOXARMDIGEST = "quay.io/libpod/busybox@" + digestOrCachedArch("quay.io/libpod/busybox", "arm", "sha256:6655df04a3df853b029a5fac8836035ac4fab117800c9a6c4b69341bb5306c3d") INFRA_IMAGE = "quay.io/libpod/k8s-pause:3.5" //nolint:revive,stylecheck BB = "quay.io/libpod/busybox:latest" @@ -65,3 +65,20 @@ func digestOrCachedArch(image string, arch string, standardDigest string) string GinkgoWriter.Printf("Digest of %q arch %s = %q", image, arch, string(out)) return strings.TrimSpace(string(out)) } + +func idOrCached(image string, standardID string) string { + if !UsingCacheRegistry() { + return standardID + } + cwd, _ := os.Getwd() + cmd := exec.Command("sh", "-c", `skopeo inspect --raw docker://`+image+` | jq -r '.config.digest'`) + cmd.Env = append(os.Environ(), "CONTAINERS_REGISTRIES_CONF="+filepath.Join(cwd, "..", "registries-cached.conf")) + out, err := cmd.Output() + if err != nil { + panic(fmt.Sprintf("Running %q: %s", cmd.String(), err.Error())) + } + GinkgoWriter.Printf("Config digest of %q = %q", image, string(out)) + digest := strings.TrimSpace(string(out)) + _, id, _ := strings.Cut(digest, ":") // A lazy hack, replace + return id +}