mirror of https://github.com/docker/docs.git
Merge pull request #650 from jimmyxian/force-refresh
Force refresh images when commit/tag/pull
This commit is contained in:
commit
258727f93f
|
|
@ -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)
|
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
|
// Proxy a request to a random node
|
||||||
func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) {
|
func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
engine, err := c.cluster.RANDOMENGINE()
|
engine, err := c.cluster.RANDOMENGINE()
|
||||||
|
|
@ -454,8 +477,14 @@ func postCommit(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cb := func(resp *http.Response) {
|
||||||
|
if resp.StatusCode == http.StatusCreated {
|
||||||
|
container.Engine.RefreshImages()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// proxy commit request to the right node
|
// 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)
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ var routes = map[string]map[string]handler{
|
||||||
"/images/create": postImagesCreate,
|
"/images/create": postImagesCreate,
|
||||||
"/images/load": notImplementedHandler,
|
"/images/load": notImplementedHandler,
|
||||||
"/images/{name:.*}/push": proxyImage,
|
"/images/{name:.*}/push": proxyImage,
|
||||||
"/images/{name:.*}/tag": proxyImage,
|
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
|
||||||
"/containers/create": postContainersCreate,
|
"/containers/create": postContainersCreate,
|
||||||
"/containers/{name:.*}/kill": proxyContainer,
|
"/containers/{name:.*}/kill": proxyContainer,
|
||||||
"/containers/{name:.*}/pause": proxyContainer,
|
"/containers/{name:.*}/pause": proxyContainer,
|
||||||
|
|
|
||||||
|
|
@ -408,6 +408,10 @@ func (e *Engine) Pull(image string) error {
|
||||||
if err := e.client.PullImage(image, nil); err != nil {
|
if err := e.client.PullImage(image, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// force refresh images
|
||||||
|
e.RefreshImages()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue