fix push image

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo 2015-10-29 20:41:28 +08:00
parent d2c5446ea0
commit 5d1fd77aea
2 changed files with 28 additions and 4 deletions

View File

@ -817,8 +817,8 @@ func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// Proxy a request to the right node
func proxyImageTagOptional(c *context, w http.ResponseWriter, r *http.Request) {
// Proxy get image request to the right node
func proxyImageGet(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
for _, image := range c.cluster.Images() {
@ -831,6 +831,30 @@ func proxyImageTagOptional(c *context, w http.ResponseWriter, r *http.Request) {
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// Proxy push image request to the right node
func proxyImagePush(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
if err := r.ParseForm(); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
tag := r.Form.Get("tag")
if tag != "" {
name = name + ":" + tag
}
for _, image := range c.cluster.Images() {
if tag != "" && image.Match(name, true) ||
tag == "" && image.Match(name, false) {
proxy(c.tlsConfig, image.Engine.Addr, w, r)
return
}
}
httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound)
}
// POST /images/{name:.*}/tag
func postTagImage(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]

View File

@ -33,7 +33,7 @@ var routes = map[string]map[string]handler{
"/images/viz": notImplementedHandler,
"/images/search": proxyRandom,
"/images/get": getImages,
"/images/{name:.*}/get": proxyImageTagOptional,
"/images/{name:.*}/get": proxyImageGet,
"/images/{name:.*}/history": proxyImage,
"/images/{name:.*}/json": proxyImage,
"/containers/ps": getContainersJSON,
@ -58,7 +58,7 @@ var routes = map[string]map[string]handler{
"/build": postBuild,
"/images/create": postImagesCreate,
"/images/load": postImagesLoad,
"/images/{name:.*}/push": proxyImageTagOptional,
"/images/{name:.*}/push": proxyImagePush,
"/images/{name:.*}/tag": postTagImage,
"/containers/create": postContainersCreate,
"/containers/{name:.*}/kill": proxyContainerAndForceRefresh,