diff --git a/api/handlers.go b/api/handlers.go index 0671064982..fa0ca63332 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -393,6 +393,29 @@ 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 and force refresh +func proxyImageAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + + // get image by name + image := c.cluster.Image(name) + + if image == nil { + httpError(w, fmt.Sprintf("No such image: %s", name), http.StatusNotFound) + } + + cb := func(resp *http.Response) { + if resp.StatusCode == http.StatusCreated { + image.Engine.RefreshImages() + } + } + + if err := proxyAsync(c.tlsConfig, image.Engine.Addr, w, r, cb); err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + } + +} + // Proxy a request to a random node func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) { engine, err := c.cluster.RANDOMENGINE() @@ -454,8 +477,14 @@ func postCommit(c *context, w http.ResponseWriter, r *http.Request) { return } + cb := func(resp *http.Response) { + if resp.StatusCode == http.StatusCreated { + container.Engine.RefreshImages() + } + } + // proxy commit request to the right node - if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil { + if err := proxyAsync(c.tlsConfig, container.Engine.Addr, w, r, cb); err != nil { httpError(w, err.Error(), http.StatusInternalServerError) } } diff --git a/api/router.go b/api/router.go index a402aed895..7da78a2695 100644 --- a/api/router.go +++ b/api/router.go @@ -50,7 +50,7 @@ var routes = map[string]map[string]handler{ "/images/create": postImagesCreate, "/images/load": notImplementedHandler, "/images/{name:.*}/push": proxyImage, - "/images/{name:.*}/tag": proxyImage, + "/images/{name:.*}/tag": proxyImageAndForceRefresh, "/containers/create": postContainersCreate, "/containers/{name:.*}/kill": proxyContainer, "/containers/{name:.*}/pause": proxyContainer, diff --git a/cluster/engine.go b/cluster/engine.go index 81d26bc0e4..5fa6c25e11 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -408,6 +408,10 @@ func (e *Engine) Pull(image string) error { if err := e.client.PullImage(image, nil); err != nil { return err } + + // force refresh images + e.RefreshImages() + return nil }