Skip to content

Commit

Permalink
WIP: Conditional digests
Browse files Browse the repository at this point in the history
Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Oct 23, 2024
1 parent 709a0fc commit 64207d9
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 19 deletions.
57 changes: 53 additions & 4 deletions test/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ var _ = Describe("Podman prune", func() {
none.WaitWithDefaultTimeout()
Expect(none).Should(ExitCleanly())
hasNone, result := none.GrepString("<none>")
Expect(result).To(HaveLen(2))
Expect(result).To(HaveLen(2)) // FIXME:???
Expect(hasNone).To(BeTrue())

prune := podmanTest.Podman([]string{"image", "prune", "-f"})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/rmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})

Expand Down

0 comments on commit 64207d9

Please sign in to comment.