forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_push.go
42 lines (35 loc) · 872 Bytes
/
image_push.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
36
37
38
39
40
41
42
package client
import (
"context"
"errors"
"io"
"net/url"
"github.com/alibaba/pouch/pkg/reference"
)
// ImagePush requests daemon to push an image to registry.
func (client *APIClient) ImagePush(ctx context.Context, ref, encodedAuth string) (io.ReadCloser, error) {
namedRef, err := reference.Parse(ref)
if err != nil {
return nil, err
}
if reference.IsCanonicalDigested(namedRef) {
return nil, errors.New("cannot push a digest reference format image")
}
tag := ""
if v, ok := namedRef.(reference.Tagged); ok {
tag = v.Tag()
}
q := url.Values{}
if tag != "" {
q.Set("tag", tag)
}
headers := map[string][]string{}
if encodedAuth != "" {
headers["X-Registry-Auth"] = []string{encodedAuth}
}
resp, err := client.post(ctx, "/images/"+namedRef.Name()+"/push", q, nil, headers)
if err != nil {
return nil, err
}
return resp.Body, nil
}