Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Commit 7d108ad

Browse files
committed
add-support-images-save
Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
1 parent f49fc12 commit 7d108ad

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

api/handlers.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,59 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) {
6262
json.NewEncoder(w).Encode(version)
6363
}
6464

65+
// GET /images/get
66+
func getImages(c *context, w http.ResponseWriter, r *http.Request) {
67+
if err := r.ParseForm(); err != nil {
68+
httpError(w, err.Error(), http.StatusInternalServerError)
69+
return
70+
}
71+
names := r.Form["names"]
72+
73+
// find an engine which has all images
74+
// Engine.Addr : [found names]
75+
dict := make(map[string][]string)
76+
bFoundEngine := false
77+
var foundEngineAddr string
78+
for _, image := range c.cluster.Images() {
79+
for _, name := range names {
80+
if image.Match(name) {
81+
// check if engine addr already exists
82+
value, exists := dict[image.Engine.Addr]
83+
if exists {
84+
// check if name already exists
85+
found := false
86+
for _, tempName := range value {
87+
if tempName == name {
88+
found = true
89+
}
90+
}
91+
if found == false {
92+
dict[image.Engine.Addr] = append(value, name)
93+
if len(names) == len(dict[image.Engine.Addr]) {
94+
bFoundEngine = true
95+
foundEngineAddr = image.Engine.Addr
96+
}
97+
}
98+
} else {
99+
dict[image.Engine.Addr] = []string{name}
100+
}
101+
}
102+
if bFoundEngine {
103+
break
104+
}
105+
}
106+
if bFoundEngine {
107+
break
108+
}
109+
}
110+
111+
if bFoundEngine {
112+
proxy(c.tlsConfig, foundEngineAddr, w, r)
113+
} else {
114+
httpError(w, fmt.Sprintf("Not found an engine which has all images: %s", names), http.StatusNotFound)
115+
}
116+
}
117+
65118
// GET /images/json
66119
func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
67120
if err := r.ParseForm(); err != nil {

api/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var routes = map[string]map[string]handler{
2828
"/images/json": getImagesJSON,
2929
"/images/viz": notImplementedHandler,
3030
"/images/search": proxyRandom,
31-
"/images/get": notImplementedHandler,
31+
"/images/get": getImages,
3232
"/images/{name:.*}/get": proxyImage,
3333
"/images/{name:.*}/history": proxyImage,
3434
"/images/{name:.*}/json": proxyImage,

test/integration/api/save.bats

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,31 @@ function teardown() {
4242
rm -f $temp_file_name
4343
rm -f $temp_file_name_o
4444
}
45+
46+
@test "docker save muti-images" {
47+
start_docker_with_busybox 1
48+
start_docker 1
49+
swarm_manage
50+
51+
# tag busybox
52+
run docker_swarm tag busybox testimage
53+
[ "$status" -eq 0 ]
54+
55+
# make sure image exists
56+
run docker_swarm images
57+
[ "$status" -eq 0 ]
58+
[[ "${output}" == *"busybox"* ]]
59+
[[ "${output}" == *"testimage"* ]]
60+
61+
temp_file_name=$(mktemp)
62+
63+
docker_swarm save busybox testimage > $temp_file_name
64+
65+
# saved image file exists, not empty and is tar file
66+
[ -s $temp_file_name ]
67+
run file $temp_file_name
68+
[ "$status" -eq 0 ]
69+
[[ "${output}" == *"tar archive"* ]]
70+
71+
rm -f $temp_file_name
72+
}

0 commit comments

Comments
 (0)