Merge pull request #3686 from vieux/load_job

Load job
This commit is contained in:
Victor Vieux 2014-01-21 11:29:15 -08:00
Родитель ba4ae40445 f2f44b91a8
Коммит 9164ba6516
3 изменённых файлов: 35 добавлений и 21 удалений

Просмотреть файл

@ -9,13 +9,13 @@ ok "/images/viz": getImagesViz, 0
ok "/images/search": getImagesSearch, N
ok "/images/{name:.*}/get": getImagesGet, 0
ok "/images/{name:.*}/history": getImagesHistory, N
... "/images/{name:.*}/json": getImagesByName, 1
#3621 "/images/{name:.*}/json": getImagesByName, 1
TODO "/containers/ps": getContainersJSON, N
TODO "/containers/json": getContainersJSON, 1
ok "/containers/{name:.*}/export": getContainersExport, 0
#3616 "/containers/{name:.*}/changes": getContainersChanges, N
... "/containers/{name:.*}/json": getContainersByName, 1
TODO "/containers/{name:.*}/top": getContainersTop, N
ok "/containers/{name:.*}/changes": getContainersChanges, N
#3621 "/containers/{name:.*}/json": getContainersByName, 1
ok "/containers/{name:.*}/top": getContainersTop, N
ok "/containers/{name:.*}/attach/ws": wsContainersAttach, 0 yes
**POST**
@ -24,7 +24,7 @@ ok "/commit": postCommit, 0
TODO "/build": postBuild, 0 yes
TODO "/images/create": postImagesCreate, N yes yes (pull)
ok "/images/{name:.*}/insert": postImagesInsert, N yes yes
TODO "/images/load": postImagesLoad, 1 yes (stdin)
ok "/images/load": postImagesLoad, 1 yes (stdin)
TODO "/images/{name:.*}/push": postImagesPush, N yes
ok "/images/{name:.*}/tag": postImagesTag, 0
ok "/containers/create": postContainersCreate, 0
@ -39,7 +39,7 @@ ok "/containers/{name:.*}/copy": postContainersCopy, 0
**DELETE**
ok "/containers/{name:.*}": deleteContainers, 0
TODO "/images/{name:.*}": deleteImages, N
#3645 "/images/{name:.*}": deleteImages, N
**OPTIONS**
ok "": optionsHandler, 0

4
api.go
Просмотреть файл

@ -608,7 +608,9 @@ func getImagesGet(srv *Server, version float64, w http.ResponseWriter, r *http.R
}
func postImagesLoad(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return srv.ImageLoad(r.Body)
job := srv.Eng.Job("load")
job.Stdin.Add(r.Body)
return job.Run()
}
func postContainersCreate(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {

Просмотреть файл

@ -95,6 +95,7 @@ func jobInitApi(job *engine.Job) engine.Status {
"search": srv.ImagesSearch,
"changes": srv.ContainerChanges,
"top": srv.ContainerTop,
"load": srv.ImageLoad,
} {
if err := job.Eng.Register(name, handler); err != nil {
job.Error(err)
@ -355,10 +356,11 @@ func (srv *Server) exportImage(image *Image, tempdir string) error {
// Loads a set of images into the repository. This is the complementary of ImageExport.
// The input stream is an uncompressed tar ball containing images and metadata.
func (srv *Server) ImageLoad(in io.Reader) error {
func (srv *Server) ImageLoad(job *engine.Job) engine.Status {
tmpImageDir, err := ioutil.TempDir("", "docker-import-")
if err != nil {
return err
job.Error(err)
return engine.StatusErr
}
defer os.RemoveAll(tmpImageDir)
@ -369,33 +371,40 @@ func (srv *Server) ImageLoad(in io.Reader) error {
tarFile, err := os.Create(repoTarFile)
if err != nil {
return err
job.Error(err)
return engine.StatusErr
}
if _, err := io.Copy(tarFile, in); err != nil {
return err
if _, err := io.Copy(tarFile, job.Stdin); err != nil {
job.Error(err)
return engine.StatusErr
}
tarFile.Close()
repoFile, err := os.Open(repoTarFile)
if err != nil {
return err
job.Error(err)
return engine.StatusErr
}
if err := os.Mkdir(repoDir, os.ModeDir); err != nil {
return err
job.Error(err)
return engine.StatusErr
}
if err := archive.Untar(repoFile, repoDir, nil); err != nil {
return err
job.Error(err)
return engine.StatusErr
}
dirs, err := ioutil.ReadDir(repoDir)
if err != nil {
return err
job.Error(err)
return engine.StatusErr
}
for _, d := range dirs {
if d.IsDir() {
if err := srv.recursiveLoad(d.Name(), tmpImageDir); err != nil {
return err
job.Error(err)
return engine.StatusErr
}
}
}
@ -404,21 +413,24 @@ func (srv *Server) ImageLoad(in io.Reader) error {
if err == nil {
repositories := map[string]Repository{}
if err := json.Unmarshal(repositoriesJson, &repositories); err != nil {
return err
job.Error(err)
return engine.StatusErr
}
for imageName, tagMap := range repositories {
for tag, address := range tagMap {
if err := srv.runtime.repositories.Set(imageName, tag, address, true); err != nil {
return err
job.Error(err)
return engine.StatusErr
}
}
}
} else if !os.IsNotExist(err) {
return err
job.Error(err)
return engine.StatusErr
}
return nil
return engine.StatusOK
}
func (srv *Server) recursiveLoad(address, tmpImageDir string) error {