New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker manifest rm
command to remove manifest list draft from local storage
#2449
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package manifest | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/docker/cli/cli" | ||
"github.com/docker/cli/cli/command" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newRmManifestListCommand(dockerCli command.Cli) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "rm MANIFEST_LIST [MANIFEST_LIST...]", | ||
Short: "Delete one or more manifest lists from local storage", | ||
Args: cli.RequiresMinArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runRm(dockerCli, args) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runRm(dockerCli command.Cli, targets []string) error { | ||
var errs []string | ||
for _, target := range targets { | ||
targetRef, refErr := normalizeReference(target) | ||
if refErr != nil { | ||
errs = append(errs, refErr.Error()) | ||
continue | ||
} | ||
_, searchErr := dockerCli.ManifestStore().GetList(targetRef) | ||
if searchErr != nil { | ||
errs = append(errs, searchErr.Error()) | ||
continue | ||
} | ||
rmErr := dockerCli.ManifestStore().Remove(targetRef) | ||
if rmErr != nil { | ||
errs = append(errs, rmErr.Error()) | ||
} | ||
} | ||
if len(errs) > 0 { | ||
return errors.New(strings.Join(errs, "\n")) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package manifest | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/docker/cli/internal/test" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
// create two manifest lists and remove them both | ||
func TestRmSeveralManifests(t *testing.T) { | ||
store, cleanup := newTempManifestStore(t) | ||
defer cleanup() | ||
|
||
cli := test.NewFakeCli(nil) | ||
cli.SetManifestStore(store) | ||
|
||
list1 := ref(t, "first:1") | ||
namedRef := ref(t, "alpine:3.0") | ||
err := store.Save(list1, namedRef, fullImageManifest(t, namedRef)) | ||
assert.NilError(t, err) | ||
namedRef = ref(t, "alpine:3.1") | ||
err = store.Save(list1, namedRef, fullImageManifest(t, namedRef)) | ||
assert.NilError(t, err) | ||
|
||
list2 := ref(t, "second:2") | ||
namedRef = ref(t, "alpine:3.2") | ||
err = store.Save(list2, namedRef, fullImageManifest(t, namedRef)) | ||
assert.NilError(t, err) | ||
|
||
cmd := newRmManifestListCommand(cli) | ||
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"}) | ||
cmd.SetOut(ioutil.Discard) | ||
err = cmd.Execute() | ||
assert.NilError(t, err) | ||
|
||
_, search1 := cli.ManifestStore().GetList(list1) | ||
_, search2 := cli.ManifestStore().GetList(list2) | ||
assert.Error(t, search1, "No such manifest: example.com/first:1") | ||
assert.Error(t, search2, "No such manifest: example.com/second:2") | ||
} | ||
|
||
// attempt to remove a manifest list which was never created | ||
func TestRmManifestNotCreated(t *testing.T) { | ||
store, cleanup := newTempManifestStore(t) | ||
defer cleanup() | ||
|
||
cli := test.NewFakeCli(nil) | ||
cli.SetManifestStore(store) | ||
|
||
list2 := ref(t, "second:2") | ||
namedRef := ref(t, "alpine:3.2") | ||
err := store.Save(list2, namedRef, fullImageManifest(t, namedRef)) | ||
assert.NilError(t, err) | ||
|
||
cmd := newRmManifestListCommand(cli) | ||
cmd.SetArgs([]string{"example.com/first:1", "example.com/second:2"}) | ||
cmd.SetOut(ioutil.Discard) | ||
err = cmd.Execute() | ||
assert.Error(t, err, "No such manifest: example.com/first:1") | ||
|
||
_, err = cli.ManifestStore().GetList(list2) | ||
assert.Error(t, err, "No such manifest: example.com/second:2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably add a
-f
/--force
option to switch between "failing immediately" if any of the references is invalid and/or doesn't exist, or only printing the error, but still completing the command successfully (see #2678 and #2677)Not a blocker; this command is still experimental, so I'm ok on improving that in a follow-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--force
isn't ubiquitous either wayThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for network, there had been some discussion, but the problem was that
--force
would also imply "if it's in use", which could mean that containers would have to be (automatically) detached from the network.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your proposal @thaJeztah, and also ok to improve that in a follow-up 👍