From 2707a61df3af7c6118edcf91b909e300d38ed306 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Thu, 6 Jun 2024 18:09:19 -0400 Subject: [PATCH] fix: docker containerd blob error (#2593) ## Description Fixes #2584 ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [ ] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow) followed --- src/internal/packager/images/pull.go | 25 +++++++++++++++++++++++++ src/pkg/layout/image.go | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index c440f8d33d..9063075879 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -246,6 +246,31 @@ func Pull(ctx context.Context, cfg PullConfig) (map[transform.Image]v1.Image, er doneSaving <- nil <-doneSaving + // Needed because when pulling from the local docker daemon, while using the docker containerd runtime + // Crane incorrectly names the blob of the docker image config to a sha that does not match the contents + // https://github.com/defenseunicorns/zarf/issues/2584 + // This is a band aid fix while we wait for crane and or docker to create the permanent fix + blobDir := filepath.Join(cfg.DestinationDirectory, "blobs", "sha256") + err = filepath.Walk(blobDir, func(path string, fi os.FileInfo, err error) error { + if err != nil { + return err + } + + if fi.IsDir() { + return nil + } + + hash, err := helpers.GetSHA256OfFile(path) + if err != nil { + return err + } + newFile := filepath.Join(blobDir, hash) + return os.Rename(path, newFile) + }) + if err != nil { + return nil, err + } + return fetched, nil } diff --git a/src/pkg/layout/image.go b/src/pkg/layout/image.go index 15348bf1d3..7d236410bf 100644 --- a/src/pkg/layout/image.go +++ b/src/pkg/layout/image.go @@ -44,11 +44,13 @@ func (i *Images) AddV1Image(img v1.Image) error { } i.AddBlob(digest.Hex) } - imgCfgSha, err := img.ConfigName() + manifest, err := img.Manifest() if err != nil { return err } - i.AddBlob(imgCfgSha.Hex) + // Cannot use img.ConfigName to get this value because of an upstream bug in crane / docker using the containerd runtime + // https://github.com/defenseunicorns/zarf/issues/2584 + i.AddBlob(manifest.Config.Digest.Hex) manifestSha, err := img.Digest() if err != nil { return err