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 committed 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.