Skip to content

Commit

Permalink
WIP that doesn't really work
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinAbro321 committed Jun 5, 2024
1 parent acfceca commit 8475a9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
28 changes: 0 additions & 28 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,34 +246,6 @@ func Pull(ctx context.Context, cfg PullConfig) (map[transform.Image]v1.Image, er
doneSaving <- nil
<-doneSaving

// This fixes an issue on amd64, when pulling images 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 the docker to create the permanent fix
blobDirectory := filepath.Join(cfg.DestinationDirectory, "images", "blobs", "sha256")
err = filepath.Walk(blobDirectory, func(path string, _ os.FileInfo, err error) error {
if err != nil {
return err
}

file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()

hash, err := helpers.GetSHA256Hash(file)
if err != nil {
return err
}

return os.Rename(path, hash)
})
if err != nil {
return nil, err
}

return fetched, nil
}

Expand Down
17 changes: 14 additions & 3 deletions src/pkg/layout/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
package layout

import (
"os"
"path/filepath"

"slices"

"github.com/defenseunicorns/pkg/helpers"
v1 "github.com/google/go-containerregistry/pkg/v1"
)

Expand All @@ -25,9 +27,18 @@ func (i *Images) AddBlob(blob string) {
if len(blob) != 64 {
return
}
abs := filepath.Join(i.Base, "blobs", "sha256", blob)
if !slices.Contains(i.Blobs, abs) {
i.Blobs = append(i.Blobs, abs)
layerPath := filepath.Join(i.Base, "blobs", "sha256")
abs := filepath.Join(layerPath, blob)
absSha, err := helpers.GetSHA256OfFile(abs)
if err != nil {
return
}
newPath := filepath.Join(layerPath, absSha)
if absSha != blob {
os.Rename(abs, newPath)
}
if !slices.Contains(i.Blobs, newPath) {
i.Blobs = append(i.Blobs, newPath)
}
}

Expand Down

0 comments on commit 8475a9e

Please sign in to comment.