Skip to content

Commit

Permalink
Save on remote now zero's out the history elements of the image config
Browse files Browse the repository at this point in the history
- This fixes rebase on artifactory as currently, the registry rejects a save on rebased images

Signed-off-by: Ashwin Venkatesh <[email protected]>
Signed-off-by: Danny Joyce <[email protected]>
  • Loading branch information
Danny Joyce authored and Ashwin Venkatesh committed Oct 9, 2019
1 parent 36282d0 commit d2cad01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fakes/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func testFake(t *testing.T, when spec.G, it spec.S) {
h.AssertNil(t, err)

layer2Path, err = createLayerTar(map[string]string{
"/layer2/file1": "file-1-contents",
"/layer2/file2": "file-2-contents",
"/layer2/file1": "file-1-contents",
"/layer2/file2": "file-2-contents",
"/layer2/some.toml": "[[something]]",
})
h.AssertNil(t, err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func createLayerTar(contents map[string]string) (string, error) {
return "", nil
}
defer file.Close()

tw := tar.NewWriter(file)

var paths []string
Expand All @@ -152,18 +152,18 @@ func createLayerTar(contents map[string]string) (string, error) {

for _, path := range paths {
txt := contents[path]

if err := tw.WriteHeader(&tar.Header{Name: path, Size: int64(len(txt)), Mode: 0644}); err != nil {
return "", err
}
if _, err := tw.Write([]byte(txt)); err != nil {
return "", err
}
}

if err := tw.Close(); err != nil {
return "", err
}

return file.Name(), nil
}
}
16 changes: 16 additions & 0 deletions remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ func (i *Image) Save(additionalNames ...string) error {
return errors.Wrap(err, "set creation time")
}

cfg, err := i.image.ConfigFile()
if err != nil {
return errors.Wrap(err, "get image config")
}

layers, err := i.image.Layers()
if err != nil {
return errors.Wrap(err, "get image layers")
}

cfg.History = make([]v1.History, len(layers))
i.image, err = mutate.ConfigFile(i.image, cfg)
if err != nil {
return errors.Wrap(err, "zeroing history")
}

var diagnostics []imgutil.SaveDiagnostic
for _, n := range allNames {
if err := i.doSave(n); err != nil {
Expand Down

0 comments on commit d2cad01

Please sign in to comment.