Skip to content

Commit

Permalink
Update descriptor "data" field (when valid) during "crane edit config" (
Browse files Browse the repository at this point in the history
#1584)

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
  • Loading branch information
tianon authored Mar 3, 2023
1 parent 1b8dc2b commit 6770304
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strings"

"github.com/google/go-containerregistry/internal/editor"
"github.com/google/go-containerregistry/internal/verify"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
Expand Down Expand Up @@ -188,6 +189,13 @@ func editConfig(in io.Reader, out io.Writer, src, dst string, options ...crane.O
edited = b
}

// this has to happen before we modify the descriptor (so we can use verify.Descriptor to validate whether m.Config.Data matches m.Config.Digest/Size)
if m.Config.Data != nil && verify.Descriptor(m.Config) == nil {
// https://github.com/google/go-containerregistry/issues/1552#issuecomment-1452653875
// "if data is non-empty and correct, we should update it"
m.Config.Data = edited
}

l := static.NewLayer(edited, m.Config.MediaType)
layerDigest, err := l.Digest()
if err != nil {
Expand Down

0 comments on commit 6770304

Please sign in to comment.