forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_tag.go
35 lines (28 loc) · 857 Bytes
/
image_tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package client
import (
"context"
"fmt"
"net/url"
"github.com/alibaba/pouch/pkg/reference"
)
// ImageTag creates tag for the image.
func (client *APIClient) ImageTag(ctx context.Context, image string, tag string) error {
if _, err := reference.Parse(image); err != nil {
return fmt.Errorf("the image reference (%s) is not valid reference", image)
}
ref, err := reference.Parse(tag)
if err != nil {
return fmt.Errorf("the tag reference (%s) is not valid reference", tag)
}
if _, ok := ref.(reference.Digested); ok {
return fmt.Errorf("refusing to create a tag with a digest reference")
}
q := url.Values{}
q.Set("repo", ref.Name())
if tagRef, ok := ref.(reference.Tagged); ok {
q.Set("tag", tagRef.Tag())
}
resp, err := client.post(ctx, fmt.Sprintf("/images/%s/tag", image), q, nil, nil)
ensureCloseReader(resp)
return err
}