From 64207d933cc3fb25d37c25c4412129b3147a6647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 23 Oct 2024 00:39:53 +0200 Subject: [PATCH] WIP: Conditional digests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miloslav Trmač --- test/e2e/config.go | 57 ++++++++++++++++++++++++++++++++++++--- test/e2e/create_test.go | 8 +++--- test/e2e/images_test.go | 2 +- test/e2e/manifest_test.go | 14 +++++----- test/e2e/prune_test.go | 2 +- test/e2e/rmi_test.go | 2 +- test/e2e/save_test.go | 2 +- 7 files changed, 68 insertions(+), 19 deletions(-) diff --git a/test/e2e/config.go b/test/e2e/config.go index af9364502d..94a59e7b77 100644 --- a/test/e2e/config.go +++ b/test/e2e/config.go @@ -2,16 +2,27 @@ package integration +import ( + "fmt" + "os" + "os/exec" + "path/filepath" + "strings" + + . "github.com/onsi/ginkgo/v2" //nolint:stylecheck // FIXME +) + var ( REDIS_IMAGE = "quay.io/libpod/redis:alpine" //nolint:revive,stylecheck fedoraMinimal = "quay.io/libpod/systemd-image:20240124" ALPINE = "quay.io/libpod/alpine:latest" ALPINELISTTAG = "quay.io/libpod/alpine:3.10.2" - ALPINELISTDIGEST = "quay.io/libpod/alpine@sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" - ALPINEAMD64DIGEST = "quay.io/libpod/alpine@sha256:634a8f35b5f16dcf4aaa0822adc0b1964bb786fca12f6831de8ddc45e5986a00" - ALPINEAMD64ID = "961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4" - ALPINEARM64DIGEST = "quay.io/libpod/alpine@sha256:f270dcd11e64b85919c3bab66886e59d677cf657528ac0e4805d3c71e458e525" + 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 = ifCachedHardcoded("961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4", "FIXME BROKEN") + ALPINEARM64DIGEST = "quay.io/libpod/alpine@" + digestOrCachedArch("quay.io/libpod/alpine", "arm64", "sha256:f270dcd11e64b85919c3bab66886e59d677cf657528ac0e4805d3c71e458e525") ALPINEARM64ID = "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" HEALTHCHECK_IMAGE = "quay.io/libpod/alpine_healthcheck:latest" //nolint:revive,stylecheck @@ -23,3 +34,41 @@ var ( // Note: "ImageCacheDir" has nothing to do with "PODMAN_TEST_IMAGE_CACHE_DIR". ImageCacheDir = "" ) + +func digestOrCachedTop(image string, standardDigest string) string { + if !UsingCacheRegistry() { + return standardDigest + } + cwd, _ := os.Getwd() + cmd := exec.Command("skopeo", "inspect", "--raw", "docker://"+image, "--format", "{{.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("Digest of %q = %q", image, string(out)) + return strings.TrimSpace(string(out)) +} + +func digestOrCachedArch(image string, arch string, standardDigest string) string { + if !UsingCacheRegistry() { + return standardDigest + } + cwd, _ := os.Getwd() + cmd := exec.Command("sh", "-c", `skopeo inspect --raw docker://`+image+ + ` | jq '.manifests | map(select(.platform.architecture == "`+arch+`"))[0].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("Digest of %q arc %s = %q", image, arch, string(out)) + return strings.TrimSpace(string(out)) +} + +func ifCachedHardcoded(standardDigest, cachedDigest string) string { + if !UsingCacheRegistry() { + return standardDigest + } + return cachedDigest +} diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index ca59962f96..960ecbc175 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -287,7 +287,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) + Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) // FIXME session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -302,7 +302,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) + Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) // FIXME session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -316,7 +316,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) + Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) // FIXME session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -330,7 +330,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"inspect", "--format", "{{.Image}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) + Expect(string(session.Out.Contents())).To(ContainSubstring(ALPINEARM64ID)) // FIXME session = podmanTest.Podman([]string{"inspect", "--format", "{{.ImageName}}", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index 7d6a12a77c..8e8bcc3cf8 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -58,7 +58,7 @@ var _ = Describe("Podman images", func() { session = podmanTest.Podman([]string{"images", "-qn"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES))) + Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES))) // FIXME: ALPINE and quay.io/libpod/alpine may have different IDs }) It("podman images with digests", func() { diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index 22bf064b4e..6d4a52e004 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -69,13 +69,13 @@ func verifyInstanceCompression(descriptor []imgspecv1.Descriptor, compression st var _ = Describe("Podman manifest", func() { - const ( + var ( imageList = "docker://quay.io/libpod/testimage:00000004" - imageListInstance = "docker://quay.io/libpod/testimage@sha256:1385ce282f3a959d0d6baf45636efe686c1e14c3e7240eb31907436f7bc531fa" - imageListARM64InstanceDigest = "sha256:1385ce282f3a959d0d6baf45636efe686c1e14c3e7240eb31907436f7bc531fa" - imageListAMD64InstanceDigest = "sha256:1462c8e885d567d534d82004656c764263f98deda813eb379689729658a133fb" - imageListPPC64LEInstanceDigest = "sha256:9b7c3300f5f7cfe94e3101a28d1f0a28728f8dbc854fb16dd545b7e5aa351785" - imageListS390XInstanceDigest = "sha256:cb68b7bfd2f4f7d36006efbe3bef04b57a343e0839588476ca336d9ff9240dbf" + imageListARM64InstanceDigest = digestOrCachedArch("quay.io/libpod/testimage:00000004", "arm64", "sha256:1385ce282f3a959d0d6baf45636efe686c1e14c3e7240eb31907436f7bc531fa") + imageListInstance = "docker://quay.io/libpod/testimage" + imageListARM64InstanceDigest + imageListAMD64InstanceDigest = digestOrCachedArch("quay.io/libpod/testimage:00000004", "amd64", "sha256:1462c8e885d567d534d82004656c764263f98deda813eb379689729658a133fb") + imageListPPC64LEInstanceDigest = digestOrCachedArch("quay.io/libpod/testimage:00000004", "ppc64le", "sha256:9b7c3300f5f7cfe94e3101a28d1f0a28728f8dbc854fb16dd545b7e5aa351785") + imageListS390XInstanceDigest = digestOrCachedArch("quay.io/libpod/testimage:00000004", "s390x", "sha256:cb68b7bfd2f4f7d36006efbe3bef04b57a343e0839588476ca336d9ff9240dbf") ) It("create w/o image and attempt push w/o dest", func() { @@ -120,7 +120,7 @@ var _ = Describe("Podman manifest", func() { Expect(session).Should(ExitCleanly()) // inspect manifest of single image - session = podmanTest.Podman([]string{"manifest", "inspect", "quay.io/libpod/busybox@sha256:6655df04a3df853b029a5fac8836035ac4fab117800c9a6c4b69341bb5306c3d"}) + session = podmanTest.Podman([]string{"manifest", "inspect", BUSYBOXARMDIGEST}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) // yet another warning message that is not seen by remote client diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go index dd893fc9b9..1cb5f1a34c 100644 --- a/test/e2e/prune_test.go +++ b/test/e2e/prune_test.go @@ -156,7 +156,7 @@ var _ = Describe("Podman prune", func() { none.WaitWithDefaultTimeout() Expect(none).Should(ExitCleanly()) hasNone, result := none.GrepString("") - Expect(result).To(HaveLen(2)) + Expect(result).To(HaveLen(2)) // FIXME:??? Expect(hasNone).To(BeTrue()) prune := podmanTest.Podman([]string{"image", "prune", "-f"}) diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go index b4ed4bad11..0480cc9452 100644 --- a/test/e2e/rmi_test.go +++ b/test/e2e/rmi_test.go @@ -153,7 +153,7 @@ var _ = Describe("Podman rmi", func() { session = podmanTest.Podman([]string{"images", "-q"}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) - Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES) + 1)) + Expect(session.OutputToStringArray()).To(HaveLen(len(CACHE_IMAGES) + 1)) // FIXME:??? }) It("podman rmi with cached images", func() { diff --git a/test/e2e/save_test.go b/test/e2e/save_test.go index b4dbecc54c..5afa03a854 100644 --- a/test/e2e/save_test.go +++ b/test/e2e/save_test.go @@ -232,7 +232,7 @@ default-docker: if len(ids) > 3 { ids = ids[:3] } - multiImageSave(podmanTest, ids) + multiImageSave(podmanTest, ids) //FIXME: This expects the loaded IDs to match }) })