github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/apiv2/10-images.at (about)

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