Skip to content
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 1 commit into from Sep 17, 2020

Conversation

jennydaman
Copy link
Contributor

- What I did

Made a typo and wanted to delete my manifest from local storage, yet there was no easy way to do so without using docker manifest push --purge.

I implemented a new sub-command docker manifest rm

$ docker manifest rm
"docker manifest rm" requires exactly 1 argument.
See 'docker manifest rm --help'.

Usage:  docker manifest rm MANIFEST_LIST

Delete a manifest list from local storage

- How I did it

tbh I never programmed in Go before, so I copied and pasted push.go to rm.go and kept deleting lines until it would compile.

- How to verify it

make -f docker.Makefile binary
build/docker-linux-amd64 manifest create repo/example:latest amd64/ubuntu:latest ppc64le/ubuntu:latest
build/docker-linux-amd64 manifest inspect repo/example:latest
build/docker-linux-amd64 manifest rm repo/example:latest
build/docker-linux-amd64 manifest create repo/example:latest i386/ubuntu arm64v8/ubuntu
build/docker-linux-amd64 manifest inspect repo/example:latest

- Description for the changelog

Add sub-command docker manifest rm

- A picture of a cute animal (not mandatory but encouraged)

image

Short: "Delete a manifest list from local storage",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.target = args[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it accept multiple manifests? (i.e., docker manifest rm one two three) other rm commands support multiple manifests so it would probably make sense to accept that for this command as well

contrib/completion/bash/docker Outdated Show resolved Hide resolved
@hassenius
Copy link

Any view on when this might merge?

This is exactly the functionality we're looking for to ensure that old artifacts are cleaned if there is an issue with previous jobs push --purge while not needing to manually delete files (whose location could change in the future)

return err
}

manifests, err := dockerCli.ManifestStore().GetList(targetRef)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I wonder why we search the manifest list, couldn't we just remove it and return Remove error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, naive copy-paste.

fixed 30466e2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually in working on supporting multiple args it turns out that dockerCli.ManifestStore().GetList(targetRef) is useful because dockerCli.ManifestStore().Remove(targetRef) will fail silently when targetRef does not exist.

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the adding the rm subcommand is fine, but this PR needs some tests to be merged 👍

@jennydaman
Copy link
Contributor Author

Hi everyone,

I am really not a Go dev, this PR was mostly a proof-of-concept. I can try writing some tests...

@rishinair11
Copy link

Hi everyone,

I am really not a Go dev, this PR was mostly a proof-of-concept. I can try writing some tests...

Really appreciate that.

@jennydaman
Copy link
Contributor Author

FYI for my own use cases I found docker buildx as an easier and faster way to build cross-platform manifest lists.

@rishinair11
Copy link

FYI for my own use cases I found docker buildx as an easier and faster way to build cross-platform manifest lists.

Does buildx have a cleanup like the one you implemented above?

@jennydaman
Copy link
Contributor Author

Yes. buildx is for building and manifest is for managing manifests. The ability to create a manifest list is only one of many buildx features. The manifest list is created automatically for multiplatform builds. Clean up with docker buildx prune and docker buildx rm

jennydaman added a commit to jennydaman/cli that referenced this pull request Sep 13, 2020
@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2020

Codecov Report

Merging #2449 into master will increase coverage by 0.02%.
The diff coverage is 77.77%.

@@            Coverage Diff             @@
##           master    #2449      +/-   ##
==========================================
+ Coverage   58.59%   58.61%   +0.02%     
==========================================
  Files         296      297       +1     
  Lines       21360    21387      +27     
==========================================
+ Hits        12516    12537      +21     
- Misses       7931     7935       +4     
- Partials      913      915       +2     

jennydaman added a commit to jennydaman/cli that referenced this pull request Sep 13, 2020
docker#2449 (comment)
Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
jennydaman added a commit to jennydaman/cli that referenced this pull request Sep 13, 2020
docker#2449 (comment)
Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
@jennydaman
Copy link
Contributor Author

jennydaman commented Sep 13, 2020

Happy to say that the tooling was surprisingly easy to pick up!

  • docker manifest rm supports multiple arguments
  • added tests

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @jennydaman 👍

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code changes LGTM, but could you squash the commits? Let me know if you need instructions on doing so 🤗

@thaJeztah thaJeztah added this to the 20.03.0 milestone Sep 14, 2020
Copy link
Collaborator

@albers albers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found problems in bash completion, please fix.

contrib/completion/bash/docker Outdated Show resolved Hide resolved
contrib/completion/bash/docker Outdated Show resolved Hide resolved
contrib/completion/bash/docker Outdated Show resolved Hide resolved
jennydaman added a commit to jennydaman/cli that referenced this pull request Sep 15, 2020
docker#2449 (review)
Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
jennydaman added a commit to jennydaman/cli that referenced this pull request Sep 15, 2020
Squashed commit of the following:

commit b9ef85e
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Mon Sep 14 21:39:57 2020 -0400

    Fix bash completion

    docker#2449 (review)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 8c46bd6
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 01:48:12 2020 -0400

    Add tests for docker manifest rm

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 7e3d9a9
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:55:37 2020 -0400

    docker manifest rm multiple args

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 30466e2
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:01:20 2020 -0400

    No need to search before Remove

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ccdc4ed
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:42:41 2020 -0400

    Completion should also handle --help

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ed260af
Merge: 46c61d8 2955ece
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:31:54 2020 -0400

    Merge branch 'master' into manifest-rm

commit 46c61d8
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:53:33 2020 -0400

    Remove extra space

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 6d31d26
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:15:21 2020 -0400

    Bash completion for `docker manifest rm`

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 3c8c843
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:05:50 2020 -0400

    Frankenstein a `docker manifest rm` command

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
@jennydaman
Copy link
Contributor Author

@albers bash completion fixed

@thaJeztah I tried squash, I think it's correct-ish?

@thaJeztah
Copy link
Member

#2449 (comment)

actually in working on supporting multiple args it turns out that dockerCli.ManifestStore().GetList(targetRef) is useful because dockerCli.ManifestStore().Remove(targetRef) will fail silently when targetRef does not exist.

Looks like something we should fix in a follow-up. I think it would be good to have dockerCli.ManifestStore().Remove(targetRef) return an "NotExist" error, and leave it to the caller of that function to decide wether or not that error is ok to ignore.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Left some suggestions for follow-up improvements

@silvin-lubecki @albers PTAL

targetRef, refErr := normalizeReference(target)
if refErr != nil {
errs = append(errs, refErr.Error())
continue
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this command is still experimental

--force isn't ubiquitous either way

docker network rm --help

Usage:  docker network rm NETWORK [NETWORK...]

Remove one or more networks

Aliases:
rm, remove

Copy link
Member

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.

Copy link
Contributor

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 👍

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Squashed commit of the following:

commit b9ef85e
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Mon Sep 14 21:39:57 2020 -0400

    Fix bash completion

    docker#2449 (review)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 8c46bd6
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 01:48:12 2020 -0400

    Add tests for docker manifest rm

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 7e3d9a9
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:55:37 2020 -0400

    docker manifest rm multiple args

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 30466e2
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:01:20 2020 -0400

    No need to search before Remove

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ccdc4ed
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:42:41 2020 -0400

    Completion should also handle --help

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ed260af
Merge: 46c61d8 2955ece
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:31:54 2020 -0400

    Merge branch 'master' into manifest-rm

commit 46c61d8
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:53:33 2020 -0400

    Remove extra space

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 6d31d26
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:15:21 2020 -0400

    Bash completion for `docker manifest rm`

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 3c8c843
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:05:50 2020 -0400

    Frankenstein a `docker manifest rm` command

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@thaJeztah thaJeztah merged commit b747821 into docker:master Sep 17, 2020
docker-jenkins pushed a commit to docker/docker-ce that referenced this pull request Sep 17, 2020
Squashed commit of the following:

commit b9ef85e74833ba405f68cfc20989c69d64bac4e9
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Mon Sep 14 21:39:57 2020 -0400

    Fix bash completion

    docker/cli#2449 (review)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 8c46bd6e6ed151bb43865c8b1d79c00fd62e4345
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 01:48:12 2020 -0400

    Add tests for docker manifest rm

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 7e3d9a9bc60e44d96953093fa0b1bc3397ca7813
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:55:37 2020 -0400

    docker manifest rm multiple args

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 30466e28d28f6722053c5a232e99ddbae8222715
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:01:20 2020 -0400

    No need to search before Remove

    docker/cli#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ccdc4ed0a620cf8c9ec6ecc6804d1a45f7c61be5
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:42:41 2020 -0400

    Completion should also handle --help

    docker/cli#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ed260afa71a4f8feb6550f79692e47ad7430d786
Merge: 46c61d85e9 2955ece024
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:31:54 2020 -0400

    Merge branch 'master' into manifest-rm

commit 46c61d85e973cc9fdd28d42db9ecebe373e9b942
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:53:33 2020 -0400

    Remove extra space

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 6d31d26c10e8d395ab08561cdb9b29829bb4bd91
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:15:21 2020 -0400

    Bash completion for `docker manifest rm`

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 3c8c843deb2f751a5f51ee6fcaa75da2a4525d99
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:05:50 2020 -0400

    Frankenstein a `docker manifest rm` command

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
Upstream-commit: 185d71262a56dfb2d5c11d49441f6acb729055eb
Component: cli
SMFloris pushed a commit to SMFloris/cli that referenced this pull request Sep 22, 2020
Squashed commit of the following:

commit b9ef85e
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Mon Sep 14 21:39:57 2020 -0400

    Fix bash completion

    docker#2449 (review)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 8c46bd6
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 01:48:12 2020 -0400

    Add tests for docker manifest rm

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 7e3d9a9
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:55:37 2020 -0400

    docker manifest rm multiple args

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 30466e2
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sun Sep 13 00:01:20 2020 -0400

    No need to search before Remove

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ccdc4ed
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:42:41 2020 -0400

    Completion should also handle --help

    docker#2449 (comment)
    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit ed260af
Merge: 46c61d8 2955ece
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Sat Sep 12 23:31:54 2020 -0400

    Merge branch 'master' into manifest-rm

commit 46c61d8
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:53:33 2020 -0400

    Remove extra space

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 6d31d26
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:15:21 2020 -0400

    Bash completion for `docker manifest rm`

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

commit 3c8c843
Author: Jennings Zhang <jenni_zh@protonmail.com>
Date:   Fri Apr 17 21:05:50 2020 -0400

    Frankenstein a `docker manifest rm` command

    Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>

Signed-off-by: Jennings Zhang <jenni_zh@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants