mirror of https://github.com/docker/docs.git
Merge pull request #754 from aluzzardi/jimmyxian-add-support-images-save
Add support images save
This commit is contained in:
commit
38a1708e81
|
@ -62,6 +62,44 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(version)
|
json.NewEncoder(w).Encode(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GET /images/get
|
||||||
|
func getImages(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
if err := r.ParseForm(); err != nil {
|
||||||
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
names := r.Form["names"]
|
||||||
|
|
||||||
|
// Create a map of engine address to the list of images it holds.
|
||||||
|
engineImages := make(map[string][]*cluster.Image)
|
||||||
|
for _, image := range c.cluster.Images() {
|
||||||
|
engineImages[image.Engine.Addr] = append(engineImages[image.Engine.Addr], image)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for an engine that has all the images we need.
|
||||||
|
for engine, images := range engineImages {
|
||||||
|
matchedImages := 0
|
||||||
|
|
||||||
|
// Count how many images we need it has.
|
||||||
|
for _, name := range names {
|
||||||
|
for _, image := range images {
|
||||||
|
if image.Match(name) {
|
||||||
|
matchedImages = matchedImages + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the engine has all images, stop our search here.
|
||||||
|
if matchedImages == len(names) {
|
||||||
|
proxy(c.tlsConfig, engine, w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
httpError(w, fmt.Sprintf("Unable to find an engine containing all images: %s", names), http.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
// GET /images/json
|
// GET /images/json
|
||||||
func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
|
|
|
@ -28,7 +28,7 @@ var routes = map[string]map[string]handler{
|
||||||
"/images/json": getImagesJSON,
|
"/images/json": getImagesJSON,
|
||||||
"/images/viz": notImplementedHandler,
|
"/images/viz": notImplementedHandler,
|
||||||
"/images/search": proxyRandom,
|
"/images/search": proxyRandom,
|
||||||
"/images/get": notImplementedHandler,
|
"/images/get": getImages,
|
||||||
"/images/{name:.*}/get": proxyImage,
|
"/images/{name:.*}/get": proxyImage,
|
||||||
"/images/{name:.*}/history": proxyImage,
|
"/images/{name:.*}/history": proxyImage,
|
||||||
"/images/{name:.*}/json": proxyImage,
|
"/images/{name:.*}/json": proxyImage,
|
||||||
|
|
|
@ -42,3 +42,49 @@ function teardown() {
|
||||||
rm -f $temp_file_name
|
rm -f $temp_file_name
|
||||||
rm -f $temp_file_name_o
|
rm -f $temp_file_name_o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "docker save multi-images" {
|
||||||
|
start_docker_with_busybox 2
|
||||||
|
# tag busybox
|
||||||
|
docker -H ${HOSTS[0]} tag busybox test1
|
||||||
|
docker -H ${HOSTS[1]} tag busybox test2
|
||||||
|
|
||||||
|
# start manage
|
||||||
|
swarm_manage
|
||||||
|
|
||||||
|
# make sure image exists
|
||||||
|
run docker_swarm images
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${output}" == *"busybox"* ]]
|
||||||
|
[[ "${output}" == *"test1"* ]]
|
||||||
|
[[ "${output}" == *"test2"* ]]
|
||||||
|
|
||||||
|
local temp_file_name=$(mktemp)
|
||||||
|
|
||||||
|
# do not support save images which are on multi machine
|
||||||
|
run docker_swarm save -o "$temp_file_name" busybox test1 test2
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "${output}" == *"Unable to find an engine containing all images"* ]]
|
||||||
|
|
||||||
|
# save images which are on same machine
|
||||||
|
docker_swarm save -o "$temp_file_name" busybox test1
|
||||||
|
|
||||||
|
# saved image file exists, not empty and is tar file
|
||||||
|
[ -s $temp_file_name ]
|
||||||
|
run file $temp_file_name
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${output}" == *"tar archive"* ]]
|
||||||
|
|
||||||
|
# Try to load our image back on an empty docker engine.
|
||||||
|
start_docker 1
|
||||||
|
run docker -H "${HOSTS[2]}" images -q
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "${#lines[@]}" -eq 0 ]
|
||||||
|
docker -H "${HOSTS[2]}" load -i "$temp_file_name"
|
||||||
|
run docker -H ${HOSTS[2]} images
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "${output}" == *"busybox"* ]]
|
||||||
|
[[ "${output}" == *"test1"* ]]
|
||||||
|
|
||||||
|
rm -f $temp_file_name
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue