Skip to content

Commit b3d79ef

Browse files
committed
Ability to overwrite an existing manifest
Sometimes amend is not enough, especially when `--purge` was not used during `manifest push` command. And since we don't have a `manifest delete` either to clean up. So just adding an `--overwrite` seems like a good thought. Change-Id: I473952ae434f421b6345c28db5cfdfcc49614710 Signed-off-by: Davanum Srinivas <davanum@gmail.com>
1 parent 6ef11c5 commit b3d79ef

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

cli/command/manifest/create_list.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
)
1414

1515
type createOpts struct {
16-
amend bool
17-
insecure bool
16+
amend bool
17+
overwrite bool
18+
insecure bool
1819
}
1920

2021
func newCreateListCommand(dockerCli command.Cli) *cobra.Command {
@@ -32,6 +33,7 @@ func newCreateListCommand(dockerCli command.Cli) *cobra.Command {
3233
flags := cmd.Flags()
3334
flags.BoolVar(&opts.insecure, "insecure", false, "Allow communication with an insecure registry")
3435
flags.BoolVarP(&opts.amend, "amend", "a", false, "Amend an existing manifest list")
36+
flags.BoolVarP(&opts.amend, "overwrite", "o", false, "Remove an existing manifest list if any and start fresh")
3537
return cmd
3638
}
3739

@@ -55,7 +57,11 @@ func createManifestList(dockerCli command.Cli, args []string, opts createOpts) e
5557
case err != nil:
5658
return err
5759
case !opts.amend:
58-
return errors.Errorf("refusing to amend an existing manifest list with no --amend flag")
60+
if opts.overwrite {
61+
manifestStore.Remove(targetRef)
62+
} else {
63+
return errors.Errorf("refusing to amend an existing manifest list with no --amend flag")
64+
}
5965
}
6066

6167
ctx := context.Background()

cli/command/manifest/create_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
9292
assert.Error(t, err, "refusing to amend an existing manifest list with no --amend flag")
9393
}
9494

95+
// Successfully overwrite a saved manifest
96+
func TestManifestCreateOverwrite(t *testing.T) {
97+
store, cleanup := newTempManifestStore(t)
98+
defer cleanup()
99+
100+
cli := test.NewFakeCli(nil)
101+
cli.SetManifestStore(store)
102+
namedRef := ref(t, "alpine:3.0")
103+
imageManifest := fullImageManifest(t, namedRef)
104+
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
105+
assert.NilError(t, err)
106+
107+
cmd := newCreateListCommand(cli)
108+
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
109+
cmd.Flags().Set("overwrite", "true")
110+
cmd.SetOutput(ioutil.Discard)
111+
err = cmd.Execute()
112+
assert.NilError(t, err)
113+
}
114+
95115
// attempt to make a manifest list without valid images
96116
func TestManifestCreateNoManifest(t *testing.T) {
97117
store, cleanup := newTempManifestStore(t)

0 commit comments

Comments
 (0)