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 22, 2024
1 parent 709a0fc commit 9712098
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 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"
)

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
}
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

0 comments on commit 9712098

Please sign in to comment.