mirror of
https://github.com/docker/docs.git
synced 2026-10-31 10:34:26 +03:00
Merge pull request #349 from vieux/pull_rmi
Add support for pull on all hosts (no change in docker run)
This commit is contained in:
@@ -18,7 +18,7 @@ GET "/containers/{name:.*}/attach/ws"
|
||||
|
||||
POST "/commit"
|
||||
POST "/build"
|
||||
POST "/images/create"
|
||||
POST "/images/create" (pull implemented)
|
||||
POST "/images/load"
|
||||
POST "/images/{name:.*}/push"
|
||||
POST "/images/{name:.*}/tag"
|
||||
|
||||
31
api/api.go
31
api/api.go
@@ -247,6 +247,35 @@ func deleteContainers(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// POST /images/create
|
||||
func postImagesCreate(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseForm(); err != nil {
|
||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
wf := NewWriteFlusher(w)
|
||||
|
||||
if image := r.Form.Get("fromImage"); image != "" { //pull
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
if tag := r.Form.Get("tag"); tag != "" {
|
||||
image += ":" + tag
|
||||
}
|
||||
callback := func(what, status string) {
|
||||
if status == "" {
|
||||
fmt.Fprintf(wf, "{%q:%q,%q:\"Pulling %s...\",%q:{}}", "id", what, "status", image, "progressDetail")
|
||||
} else {
|
||||
fmt.Fprintf(wf, "{%q:%q,%q:\"Pulling %s... : %s\",%q:{}}", "id", what, "status", image, status, "progressDetail")
|
||||
}
|
||||
}
|
||||
c.cluster.Pull(image, callback)
|
||||
} else { //import
|
||||
httpError(w, "Not supported in clustering mode.", http.StatusNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
// GET /events
|
||||
func getEvents(c *context, w http.ResponseWriter, r *http.Request) {
|
||||
c.eventsHandler.Add(r.RemoteAddr, w)
|
||||
@@ -416,7 +445,7 @@ func createRouter(c *context, enableCors bool) *mux.Router {
|
||||
"/auth": proxyRandom,
|
||||
"/commit": notImplementedHandler,
|
||||
"/build": notImplementedHandler,
|
||||
"/images/create": notImplementedHandler,
|
||||
"/images/create": postImagesCreate,
|
||||
"/images/load": notImplementedHandler,
|
||||
"/images/{name:.*}/push": notImplementedHandler,
|
||||
"/images/{name:.*}/tag": notImplementedHandler,
|
||||
|
||||
@@ -3,13 +3,31 @@ package cluster
|
||||
import "github.com/samalba/dockerclient"
|
||||
|
||||
type Cluster interface {
|
||||
// Create a container
|
||||
CreateContainer(config *dockerclient.ContainerConfig, name string) (*Container, error)
|
||||
|
||||
// Remove a container
|
||||
RemoveContainer(container *Container, force bool) error
|
||||
|
||||
// Return all images
|
||||
Images() []*Image
|
||||
|
||||
// Return one image matching `IdOrName`
|
||||
Image(IdOrName string) *Image
|
||||
|
||||
// Return all containers
|
||||
Containers() []*Container
|
||||
|
||||
// Return container the matching `IdOrName`
|
||||
Container(IdOrName string) *Container
|
||||
|
||||
// Pull images
|
||||
// `callback` can be called multiple time
|
||||
// `what` is what is being pulled
|
||||
// `status` is the current status, like "", "in progress" or "downloaded
|
||||
Pull(name string, callback func(what, status string))
|
||||
|
||||
// Return some info about the cluster, like nb or containers / images
|
||||
// It is pretty open, so the implementation decides what to return.
|
||||
Info() [][2]string
|
||||
}
|
||||
|
||||
@@ -186,6 +186,26 @@ func (c *Cluster) Image(IdOrName string) *cluster.Image {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) Pull(name string, callback func(what, status string)) {
|
||||
size := len(c.nodes)
|
||||
done := make(chan bool, size)
|
||||
for _, n := range c.nodes {
|
||||
go func(nn *node) {
|
||||
if callback != nil {
|
||||
callback(nn.Name(), "")
|
||||
}
|
||||
nn.pull(name)
|
||||
if callback != nil {
|
||||
callback(nn.Name(), "downloaded")
|
||||
}
|
||||
done <- true
|
||||
}(n)
|
||||
}
|
||||
for i := 0; i < size; i++ {
|
||||
<-done
|
||||
}
|
||||
}
|
||||
|
||||
// Containers returns all the containers in the cluster.
|
||||
func (c *Cluster) Containers() []*cluster.Container {
|
||||
c.RLock()
|
||||
|
||||
Reference in New Issue
Block a user