aboutsummaryrefslogtreecommitdiff
path: root/test/apiv2/70-short-names.at
blob: dbf816f55cdda293aa8addf9b6f2a2572fa91893 (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
# -*- sh -*-
#
# Tests for exercising short-name resolution in the compat API.
#

# Pull the libpod/quay image which is used in all tests below.
t POST "images/create?fromImage=quay.io/libpod/alpine:latest" 200 .error~null .status~".*Download complete.*"

# 14291 - let a short-name resolve to a *local* non Docker-Hub image.
t POST containers/create Image=alpine 201 .Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t GET containers/$cid/json 200 .Image="quay.io/libpod/alpine:latest"
podman rm -f $cid

########## TAG

t POST   "images/quay.io/libpod/alpine/tag?repo=foo"  201
t DELETE "images/docker.io/library/foo"               200


########## BUILD

function test_build {
    from=$1
    tag=$2
    fqn=$3

    TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX)
    CONTAINERFILE_TAR="${TMPD}/containerfile.tar"
    cat > $TMPD/containerfile << EOF
FROM $from
RUN  touch /foo
EOF
    tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null

    curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \
        -H "content-type: application/x-tar" \
        --dump-header "${TMPD}/headers.txt" \
        -o "${TMPD}/response.txt" \
        "http://$HOST:$PORT/build?dockerfile=containerfile&t=$tag" &> /dev/null

    if ! grep -q '200 OK' "${TMPD}/headers.txt"; then
        cat "${TMPD}/headers.txt"
        cat "${TMPD}/response.txt"
        echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/x-tar)"
        exit 1
    fi

    rm -rf $TMPD
    t DELETE "images/$fqn" 200
}

t POST   "images/quay.io/libpod/alpine/tag?repo=foo" 201
test_build foo bar "docker.io/library/bar:latest"
t DELETE "images/foo"                                200


########## TAG

# The libpod endpoint will resolve to it without issues.
t GET "libpod/images/alpine/exists" 204

# Now let's tag the image with 'foo'.  Remember, it will be normalized to
# docker.io/library/foo.
t GET  "libpod/images/docker.io/library/foo/exists" 404
t POST "images/quay.io/libpod/alpine/tag?repo=foo"  201
t GET  "libpod/images/docker.io/library/foo/exists" 204


########## REMOVE

t DELETE "images/foo"    200                          # removes the previously tagged image


########## GET

# Same procedure as above but with the /get endpoint.
t POST   "images/quay.io/libpod/alpine/tag?repo=foo" 201
t GET    "images/foo/get"                            200 '[POSIX tar archive]'
t DELETE "images/foo"                                200
t GET    "images/alpine/get"                         200


########## HISTORY

t GET    "images/alpine/history"                     200
t GET    "images/quay.io/libpod/alpine/history"      200
t POST   "images/quay.io/libpod/alpine/tag?repo=foo" 201
t GET    "libpod/images/foo/history"                 200
t DELETE "images/foo"                                200


########## PUSH

t POST   "images/alpine/push?destination=localhost:9999/do:exist"                    200
t POST   "images/quay.io/libpod/alpine/push?destination=localhost:9999/do/not:exist" 200 # Error is in the response
t POST   "images/quay.io/libpod/alpine/tag?repo=foo"                                 201
t POST   "images/foo/push?destination=localhost:9999/do/not:exist"                   200 # Error is in the response
t DELETE "images/foo"                                                                200


########## CREATE A CONTAINER

t POST   "containers/create"                         Image=alpine                       201
t POST   "containers/create"                         Image=quay.io/libpod/alpine:latest 201
cid=$(jq -r '.Id' <<<"$output")
t POST   "images/quay.io/libpod/alpine/tag?repo=foo"                                    201
t POST   "containers/create"                         Image=foo                          201
cid=$(jq -r '.Id' <<<"$output")
t DELETE "images/foo"                                                                   200
t DELETE "containers/$cid"                                                              204

########## COMMIT CONTAINER

t POST   "containers/create"                      Image=quay.io/libpod/alpine:latest 201
cid=$(jq -r '.Id' <<<"$output")
t GET    "images/alpine/get"                                                         200
t POST   "commit?container=$cid&repo=foo&tag=tag"                                    201
t GET    "images/foo/get"                                                            404 .cause="image not known"
t GET    "images/foo:tag/get"                                                        200
t DELETE "images/docker.io/library/foo:tag"                                          200
t DELETE "containers/$cid"                                                           204


######### SMOKE TESTS WITHOUT DOCKER.IO ENFORCEMENT

# Note that we need to restart the service with a custom containers.conf to
# disable the docker.io enforcement.

stop_service
CONTAINERS_CONF=$(pwd)/test/apiv2/containers.conf start_service

t POST   "images/create?fromImage=quay.io/libpod/alpine:latest"       200 .error~null .status~".*Download complete.*"
t POST   "images/alpine/tag?repo=foo"                                 201
t GET    "images/localhost/foo:latest/get"                            200
t DELETE "images/foo"                                                 200
t GET    "images/alpine/history"                                      200
t POST   "images/alpine/push?destination=localhost:9999/do/not:exist" 200 # Error is in the response
t POST   "containers/create" Image=alpine                             201
cid=$(jq -r '.Id' <<<"$output")
t POST   "commit?container=$cid&repo=foo&tag=tag"                     201
t DELETE "images/localhost/foo:tag"                                   200
t DELETE "containers/$cid"                                            204

test_build alpine bar "localhost/bar:latest"


stop_service
start_service