blob: fd04e3f1bb5743c62eeeeb52e5d98ca3a61efaa3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# -*- sh -*-
#
# Tests for image-related endpoints
#
# FIXME: API doesn't support pull yet, so use podman
podman pull -q $IMAGE
t GET libpod/images/json 200 \
.[0].Id~[0-9a-f]\\{64\\}
iid=$(jq -r '.[0].Id' <<<"$output")
# Create an empty manifest and make sure it is not listed
# in the compat endpoint.
t GET images/json 200 length=1
podman manifest create foo
t GET images/json 200 length=1
t GET libpod/images/json 200 length=2
t GET libpod/images/$iid/exists 204
t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/exists 204
t GET libpod/images/${iid}abcdef/exists 404 \
.cause="failed to find image ${iid}abcdef"
# FIXME: compare to actual podman info
t GET libpod/images/json 200 \
.[0].Id=${iid}
t GET libpod/images/$iid/json 200 \
.Id=$iid \
.RepoTags[0]=$IMAGE
# Same thing, but with abbreviated image id
t GET libpod/images/${iid:0:12}/json 200 \
.Id=$iid \
.RepoTags[0]=$IMAGE
# Docker API V1.24 filter parameter compatibility
t GET images/json?filter=$IMAGE 200 \
length=1 \
.[0].Names[0]=$IMAGE
# Negative test case
t GET images/json?filter=nonesuch 200 length=0
# FIXME: docker API incompatibility: libpod returns 'id', docker 'sha256:id'
t GET images/$iid/json 200 \
.Id=sha256:$iid \
.RepoTags[0]=$IMAGE
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*Download complete.*"
t POST "images/create?fromImage=alpine&tag=latest" 200
# 10977 - handle platform parameter correctly
t POST "images/create?fromImage=testimage:20210610&platform=linux/arm64" 200
t GET "images/testimage:20210610/json" 200 \
.Architecture=arm64
# Make sure that new images are pulled
old_iid=$(podman image inspect --format "{{.ID}}" docker.io/library/alpine:latest)
podman rmi -f docker.io/library/alpine:latest
podman tag $IMAGE docker.io/library/alpine:latest
t POST "images/create?fromImage=alpine" 200 .error~null .status~".*$old_iid.*"
podman untag docker.io/library/alpine:latest
t POST "images/create?fromImage=quay.io/libpod/alpine&tag=sha256:fa93b01658e3a5a1686dc3ae55f170d8de487006fb53a28efcd12ab0710a2e5f" 200
# Display the image history
t GET libpod/images/nonesuch/history 404
for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
t GET libpod/images/$i/history 200 \
.[0].Id=$iid \
.[0].Created~[0-9]\\{10\\} \
.[0].Tags=null \
.[0].Size=0 \
.[0].Comment=
done
# Export an image on the local
t GET libpod/images/nonesuch/get 404
t GET libpod/images/$iid/get?format=foo 500
t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/get?compress=bar 400
for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do
t GET "libpod/images/$i/get" 200 '[POSIX tar archive]'
t GET "libpod/images/$i/get?compress=true" 200 '[POSIX tar archive]'
t GET "libpod/images/$i/get?compress=false" 200 '[POSIX tar archive]'
done
#compat api list images sanity checks
t GET images/json?filters='garb1age}' 500 \
.cause="invalid character 'g' looking for beginning of value"
t GET images/json?filters='{"label":["testl' 500 \
.cause="unexpected end of JSON input"
#libpod api list images sanity checks
t GET libpod/images/json?filters='garb1age}' 500 \
.cause="invalid character 'g' looking for beginning of value"
t GET libpod/images/json?filters='{"label":["testl' 500 \
.cause="unexpected end of JSON input"
# Prune images - bad all input
t POST libpod/images/prune?all='garb1age' 500 \
.cause="schema: error converting value for \"all\""
# Prune images - bad filter input
t POST images/prune?filters='garb1age}' 500 \
.cause="invalid character 'g' looking for beginning of value"
t POST libpod/images/prune?filters='garb1age}' 500 \
.cause="invalid character 'g' looking for beginning of value"
## Prune images with illformed label
t POST images/prune?filters='{"label":["tes' 500 \
.cause="unexpected end of JSON input"
t POST libpod/images/prune?filters='{"label":["tes' 500 \
.cause="unexpected end of JSON input"
#create, list and remove dangling image
podman image build -t test:test -<<EOF
from alpine
RUN >file1
EOF
podman image build -t test:test --label xyz -<<EOF
from alpine
RUN >file2
EOF
t GET images/json?filters='{"dangling":["true"]}' 200 length=1
t POST images/prune?filters='{"dangling":["true"]}' 200
t GET images/json?filters='{"dangling":["true"]}' 200 length=0
#label filter check in libpod and compat
t GET images/json?filters='{"label":["xyz"]}' 200 length=1
t GET libpod/images/json?filters='{"label":["xyz"]}' 200 length=1
t DELETE libpod/images/test:test 200
t GET images/json?filters='{"label":["xyz"]}' 200 length=0
t GET libpod/images/json?filters='{"label":["xyz"]}' 200 length=0
# to be used in prune until filter tests
podman image build -t test1:latest -<<EOF
from alpine
RUN >file3
EOF
# image should not be deleted
t GET images/json?filters='{"reference":["test1"]}' 200 length=1
t POST images/prune?filters='{"until":["500000"]}' 200
t GET images/json?filters='{"reference":["test1"]}' 200 length=1
t DELETE libpod/images/test1:latest 200
# to be used in prune until filter tests
podman image build -t docker.io/library/test1:latest -<<EOF
from alpine
RUN >file4
EOF
podman create --name test1 test1 echo hi
t DELETE images/test1:latest 409
podman rm test1
t DELETE images/test1:latest 200
t GET "images/get?names=alpine" 200 '[POSIX tar archive]'
podman pull busybox
t GET "images/get?names=alpine&names=busybox" 200 '[POSIX tar archive]'
img_cnt=$(tar xf "$WORKDIR/curl.result.out" manifest.json -O | jq "length")
is "$img_cnt" 2 "number of images in tar archive"
# check build works when uploading container file as a tar, see issue #10660
TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
function cleanBuildTest() {
podman rmi -a -f
rm -rf "${TMPD}" &> /dev/null
}
CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
cat > $TMPD/containerfile << EOF
FROM $IMAGE
EOF
tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null
t POST "libpod/build?dockerfile=containerfile" $CONTAINERFILE_TAR 200 \
.stream~"STEP 1/1: FROM $IMAGE"
# With -q, all we should get is image ID. Test both libpod & compat endpoints.
t POST "libpod/build?dockerfile=containerfile&q=true" $CONTAINERFILE_TAR 200 \
.stream~'^[0-9a-f]\{64\}$'
t POST "build?dockerfile=containerfile&q=true" $CONTAINERFILE_TAR 200 \
.stream~'^[0-9a-f]\{64\}$'
# Override content-type and confirm that libpod rejects, but compat accepts
t POST "libpod/build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 400 \
.cause='Content-Type: application/json is not supported. Should be "application/x-tar"'
t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 200 \
.stream~"STEP 1/1: FROM $IMAGE"
# Libpod: allow building from url: https://github.com/alpinelinux/docker-alpine.git and must ignore any provided tar
t POST "libpod/build?remote=https%3A%2F%2Fgithub.com%2Falpinelinux%2Fdocker-alpine.git" $CONTAINERFILE_TAR 200 \
.stream~"STEP 1/5: FROM alpine:3.14"
# Build api response header must contain Content-type: application/json
t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR application/json 200
response_headers=$(cat "$WORKDIR/curl.headers.out")
like "$response_headers" ".*application/json.*" "header does not contains application/json"
# PR #12091: output from compat API must now include {"aux":{"ID":"sha..."}}
t POST "build?dockerfile=containerfile" $CONTAINERFILE_TAR 200 \
'.aux|select(has("ID")).ID~^sha256:[0-9a-f]\{64\}$'
t POST libpod/images/prune 200
t POST libpod/images/prune 200 length=0 []
# compat api must allow loading tar which contain multiple images
podman pull quay.io/libpod/alpine:latest quay.io/libpod/busybox:latest
podman save -o ${TMPD}/test.tar quay.io/libpod/alpine:latest quay.io/libpod/busybox:latest
t POST "images/load" ${TMPD}/test.tar 200 \
.stream="Loaded image: quay.io/libpod/busybox:latest,quay.io/libpod/alpine:latest"
t GET libpod/images/quay.io/libpod/alpine:latest/exists 204
t GET libpod/images/quay.io/libpod/busybox:latest/exists 204
cleanBuildTest
# vim: filetype=sh
|