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

feature: init pouch tag functionality #1378

Merged
merged 1 commit into from
May 23, 2018
Merged

feature: init pouch tag functionality #1378

merged 1 commit into from
May 23, 2018

Conversation

fuweid
Copy link
Contributor

@fuweid fuweid commented May 22, 2018

Since the containerd provides the ImageService to modify the boltdb
data, we can add tag reference into the containerd. Just in case that
the client removes the source image.

Signed-off-by: Wei Fu [email protected]

Ⅰ. Describe what this PR did

Use containerd's ImageService to implement pouch tag functionality. Allow user to create tag reference to existing image.

Ⅱ. Does this pull request fix one issue?

NONE.

Ⅲ. Describe how you did it

The containerd stores the image name as key in the boltdb. pouch run/image inspect/rmi will use the primary reference as name to handle image information.

If we don't use the boltdb provided by containerd.ImageService, we will loss the tag reference when we remove the source image.

Therefore, when user adds tag reference to the existing image, I will do the following things:

  • get the image from containerd
  • use the tag reference as primary name and update boltdb by containerd.ImageService

The update action will add the reference count for the image content. That is the key to implement this functionality.

Ⅳ. Describe how to verify it

First one is the help:

➜  pouch git:(feature_image_tag) pouch tag -h
tag command is to add tag reference for the existing image.

Usage:
  pouch tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Examples:
$ pouch tag registry.hub.docker.com/library/busybox:1.28 busybox:latest

Flags:
  -h, --help   help for tag

Global Flags:
  -D, --debug              Switch client log level to DEBUG mode
  -H, --host string        Specify connecting address of Pouch CLI (default "unix:///var/run/pouchd.sock")
      --tlscacert string   Specify CA file of TLS
      --tlscert string     Specify cert file of TLS
      --tlskey string      Specify key file of TLS
      --tlsverify          Use TLS and verify remote

Use Tag:

➜  pouch git:(feature_image_tag) pouch images
IMAGE ID       IMAGE NAME                                     SIZE
8ac48589692a   registry.hub.docker.com/library/busybox:1.28   710.83 KB
➜  pouch git:(feature_image_tag) pouch tag busybox:1.28 busybox:test
➜  pouch git:(feature_image_tag) pouch images --digest
IMAGE ID       IMAGE NAME                                     DIGEST                                                                    SIZE
8ac48589692a   registry.hub.docker.com/library/busybox:1.28   sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64   710.83 KB
8ac48589692a   registry.hub.docker.com/library/busybox:test   sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64   710.83 KB

We can use the tag reference to run container like:

➜  pouch git:(feature_image_tag) pouch run busybox:test ls
bin
dev
etc
home
proc
root
run
sys
tmp
usr
var

But we don't allow to use sha256 as name, because it will confuse with searching by imageID.

➜  pouch git:(feature_image_tag) pouch tag busybox:1.28 sha256:oops
Error: {"message":"refusing to create an reference using digest algorithm as name: invalid param"}

However, it doesn't act like docker right now. We don't allow user to override the existing primary reference, like:

➜  pouch git:(feature_image_tag) pouch images
IMAGE ID       IMAGE NAME                                     SIZE
e02e811dd08f   registry.hub.docker.com/library/busybox:1.25   654.44 KB
8ac48589692a   registry.hub.docker.com/library/busybox:1.28   710.83 KB
8ac48589692a   registry.hub.docker.com/library/busybox:test   710.83 KB
➜  pouch git:(feature_image_tag) pouch tag e02e811dd08f busybox:test # even if the busybox:test is created by tag
Error: {"message":"the tag reference (registry.hub.docker.com/library/busybox:test) has been used as reference: invalid param"}

Ⅴ. Special notes for reviews

name := mux.Vars(req)["name"]

targetRef := req.FormValue("repo")
if tag := req.FormValue("tag"); tag != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

if tag is "", do we need set default value latest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have handled it in the deamon so that we can keep the bridge simple.

@@ -60,6 +60,7 @@ func initRoute(s *Server) http.Handler {
s.addRoute(r, http.MethodGet, "/images/json", s.listImages)
s.addRoute(r, http.MethodDelete, "/images/{name:.*}", s.removeImage)
s.addRoute(r, http.MethodGet, "/images/{name:.*}/json", s.getImage)
s.addRoute(r, http.MethodPost, "/images/{name:.*}/tag", s.postImageTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

need add swagger info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch.

Since the containerd provides the ImageService to modify the boltdb
data, we can add tag reference into the containerd. Just in case that
the client removes the source image.

Signed-off-by: Wei Fu <[email protected]>
@HusterWan
Copy link
Contributor

LGTM

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label May 23, 2018
@HusterWan HusterWan merged commit c38f332 into AliyunContainerService:0.5.x May 23, 2018
@fuweid fuweid deleted the feature_add_image_tag_functionality branch August 3, 2018 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants