mirror of https://github.com/docker/docs.git
add force-refresh when commit/tag/pull
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
parent
1aa61f9f36
commit
5c068de28c
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue