Skip to content

Commit 9a4ad17

Browse files
committed
mz507: normalize via skopeo
1 parent 6bc1774 commit 9a4ad17

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

.github/workflows/integration-tests.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ jobs:
5050
- uses: docker/setup-docker-action@1a6edb0ba9ac496f6850236981f15d8f9a82254d # v5.0.0
5151
with:
5252
version: 29.2.1
53-
daemon-config: |
54-
{
55-
"features": {
56-
"containerd-snapshotter": false
57-
}
58-
}
5953

6054
- uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
6155

62-
- run: make install-diffoci install-crane k3s-setup
56+
- run: make install-diffoci install-crane install-skopeo k3s-setup
6357
- run: make ${{ matrix.make-target }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ install-diffoci:
6464
install-crane:
6565
@ GOFLAGS="" go install github.com/google/go-containerregistry/cmd/crane@latest
6666

67+
.PHONY: install-skopeo
68+
install-skopeo:
69+
@ GOFLAGS="" go install github.com/containers/skopeo/cmd/skopeo@latest
70+
6771
.PHONY: k3s-setup
6872
k3s-setup:
6973
@ ./scripts/k3s-setup.sh

integration/integration_test.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ func initIntegrationTestConfig() *integrationTestConfig {
12941294
}
12951295

12961296
func meetsRequirements() bool {
1297-
requiredTools := []string{"diffoci"}
1297+
requiredTools := []string{"diffoci", "skopeo"}
12981298
hasRequirements := true
12991299
for _, tool := range requiredTools {
13001300
_, err := exec.LookPath(tool)
@@ -1308,20 +1308,8 @@ func meetsRequirements() bool {
13081308

13091309
// containerDiff compares the container images image1 and image2.
13101310
func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte {
1311-
// workaround for container-diff OCI issue https://github.com/GoogleContainerTools/container-diff/issues/389
1312-
if !strings.HasPrefix(image1, daemonPrefix) {
1313-
dockerPullCmd := exec.Command("docker", "pull", image1)
1314-
out := RunCommand(dockerPullCmd, t)
1315-
t.Logf("docker pull cmd output for image1 = %s", string(out))
1316-
image1 = daemonPrefix + image1
1317-
}
1318-
1319-
if !strings.HasPrefix(image2, daemonPrefix) {
1320-
dockerPullCmd := exec.Command("docker", "pull", image2)
1321-
out := RunCommand(dockerPullCmd, t)
1322-
t.Logf("docker pull cmd output for image2 = %s", string(out))
1323-
image2 = daemonPrefix + image2
1324-
}
1311+
image1 = normalizeImageFormat(t, image1)
1312+
image2 = normalizeImageFormat(t, image2)
13251313

13261314
flags = append([]string{"diff"}, flags...)
13271315
flags = append(flags, image1, image2, "--ignore-image-name", "--ignore-image-timestamps")
@@ -1333,3 +1321,32 @@ func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte
13331321

13341322
return diff
13351323
}
1324+
1325+
// normalizeImageFormat pulls image to the Docker daemon (if not already present)
1326+
// and converts it to Docker V2S2 format using skopeo. This ensures both images
1327+
// are in the same format before comparison, replicating the normalization that
1328+
// legacy Docker storage performs on pull.
1329+
func normalizeImageFormat(t *testing.T, image string) string {
1330+
t.Helper()
1331+
if !strings.HasPrefix(image, daemonPrefix) {
1332+
out := RunCommand(exec.Command("docker", "pull", image), t)
1333+
t.Logf("docker pull %s: %s", image, string(out))
1334+
image = daemonPrefix + image
1335+
}
1336+
ref := strings.TrimPrefix(image, daemonPrefix)
1337+
taggedRef := ref
1338+
lastSlash := strings.LastIndex(ref, "/")
1339+
if !strings.Contains(ref[lastSlash+1:], ":") {
1340+
taggedRef = ref + ":latest"
1341+
}
1342+
normalized := taggedRef + "-v2s2"
1343+
cmd := exec.Command("skopeo", "copy", "--format", "v2s2",
1344+
"docker-daemon:"+taggedRef,
1345+
"docker-daemon:"+normalized)
1346+
out, err := RunCommandWithoutTest(cmd)
1347+
t.Logf("skopeo normalize %s: %s", ref, string(out))
1348+
if err != nil {
1349+
t.Fatalf("failed to normalize image %s to v2s2: %v\n%s", ref, err, string(out))
1350+
}
1351+
return daemonPrefix + normalized
1352+
}

0 commit comments

Comments
 (0)