forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support push image in daemon side
implement push command in daemon side, since containerd v1.0.3 version push get some problem when push image with index.json which have multiple platforms. But it works good with only one platform, this feature is our need. fixes: AliyunContainerService#2099 Signed-off-by: Ace-Tang <aceapril@126.com>
- Loading branch information
1 parent
6ca29af
commit ff8b8fb
Showing
14 changed files
with
364 additions
and
13 deletions.
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
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
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,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 | ||
} |
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,51 @@ | ||
package client | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestImagePushServerError(t *testing.T) { | ||
client := &APIClient{ | ||
HTTPCli: newMockClient(errorMockResponse(http.StatusInternalServerError, "Server error")), | ||
} | ||
_, err := client.ImagePush(context.Background(), "image", "auth") | ||
if err == nil || !strings.Contains(err.Error(), "Server error") { | ||
t.Fatalf("expected a Server Error, got %v", err) | ||
} | ||
} | ||
|
||
func TestImagePush(t *testing.T) { | ||
name := "test_image" | ||
expectedURL := "/images/" + name + "/push" | ||
|
||
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) { | ||
if !strings.HasPrefix(req.URL.Path, expectedURL) { | ||
return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL) | ||
} | ||
|
||
if req.Method != "POST" { | ||
return nil, fmt.Errorf("expected POST method, got %s", req.Method) | ||
} | ||
|
||
return &http.Response{ | ||
StatusCode: http.StatusOK, | ||
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))), | ||
}, nil | ||
}) | ||
|
||
client := &APIClient{ | ||
HTTPCli: httpClient, | ||
} | ||
|
||
_, err := client.ImagePush(context.Background(), name, "auth") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.