github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/system/build-testimage (about)

     1  #!/bin/bash
     2  #
     3  # build-testimage - script for producing a test image for podman CI
     4  #
     5  # The idea is to have a small multi-purpose image that can be pulled once
     6  # by system tests and used for as many tests as possible. This image
     7  # should live on quay.io, should be small in size, and should include
     8  # as many components as needed by system tests so they don't have to
     9  # pull other images.
    10  #
    11  # Unfortunately, "small" is incompatible with "systemd" so tests
    12  # still need a fedora image for that.
    13  #
    14  
    15  # Buildah binary
    16  BUILDAH=${BUILDAH:-buildah}
    17  
    18  # Tag for this new image
    19  YMD=$(date +%Y%m%d)
    20  
    21  # git-relative path to this script
    22  create_script=$(cd $(dirname $0) && git ls-files --full-name $(basename $0))
    23  if [ -z "$create_script" ]; then
    24      create_script=$0
    25  fi
    26  
    27  # Creation timestamp, Zulu time
    28  create_time_z=$(env TZ=UTC date +'%Y-%m-%dT%H:%M:%SZ')
    29  
    30  set -ex
    31  
    32  # We'll need to create a Containerfile plus various other files to add in
    33  #
    34  # Please document the reason for all flags, apk's, and anything non-obvious
    35  tmpdir=$(mktemp -t -d $(basename $0).tmp.XXXXXXX)
    36  cd $tmpdir
    37  
    38  # 'image mount' test will confirm that this file exists and has our YMD tag
    39  echo $YMD >testimage-id
    40  
    41  # ...but set the timestamp on the file itself to a constant well-known
    42  # value, for use by the 'run --tz' test. Date value chosen for nerdiness
    43  # and because it's in the past. (Much as I'd love FFFFFFFF, we can't
    44  # use any future date because of unpredictable leap second adjustments).
    45  touch --date=@1600000000 testimage-id
    46  
    47  # 'pod' test will use this for --infra-command
    48  cat >pause <<EOF
    49  #!/bin/sh
    50  #
    51  # Trivial little pause script, used in one of the pod tests
    52  #
    53  echo Confirmed: testimage pause invoked as \$0
    54  while :; do
    55      sleep 0.1
    56  done
    57  EOF
    58  chmod 755 pause
    59  
    60  # alpine because it's small and light and reliable
    61  #    - check for updates @ https://hub.docker.com/_/alpine
    62  # busybox-extras provides httpd needed in 500-networking.bats
    63  cat >Containerfile <<EOF
    64  ARG REPO=please-override-repo
    65  FROM docker.io/\${REPO}/alpine:3.13.5
    66  RUN apk add busybox-extras
    67  ADD testimage-id pause /home/podman/
    68  LABEL created_by=$create_script
    69  LABEL created_at=$create_time_z
    70  WORKDIR /home/podman
    71  CMD ["/bin/echo", "This container is intended for podman CI testing"]
    72  EOF
    73  
    74  # --squash-all    : needed by 'tree' test in 070-build.bats
    75  podman rmi -f testimage &> /dev/null || true
    76  
    77  # There should always be a testimage tagged ':0000000<X>' (eight digits,
    78  # zero-padded sequence ID) in the same location; this is used by tests
    79  # which need to pull a non-locally-cached image. This image will rarely
    80  # if ever need to change, nor in fact does it even have to be a copy of
    81  # this testimage since all we use it for is 'true'.
    82  # However, it does need to be multiarch :-(
    83  zerotag_latest=$(skopeo list-tags docker://quay.io/libpod/testimage |\
    84                       jq -r '.Tags[]' |\
    85                       sort --version-sort |\
    86                       grep '^000' |\
    87                       tail -n 1)
    88  zerotag_next=$(printf "%08d" $((zerotag_latest + 1)))
    89  
    90  # We don't always need to push the :00xx image, but build it anyway.
    91  zeroimg=quay.io/libpod/testimage:${zerotag_next}
    92  buildah manifest create $zeroimg
    93  
    94  # We need to use buildah because (as of 2021-02-23) only buildah has --manifest
    95  # and because Dan says arch emulation is not currently working on podman
    96  # (no further details).
    97  # Arch emulation on Fedora requires the qemu-user-static package.
    98  for arch in amd64 arm64 ppc64le s390x;do
    99      # docker.io repo is usually the same name as the desired arch; except
   100      # for arm64, where podman needs to have the arch be 'arm64' but the
   101      # image lives in 'arm64v8'.
   102      repo=$arch
   103      if [[ $repo = "arm64" ]]; then
   104          repo="${repo}v8"
   105      fi
   106  
   107      ${BUILDAH} bud \
   108                 --arch=$arch \
   109                 --build-arg REPO=$repo \
   110                 --manifest=testimage \
   111                 --squash \
   112                 .
   113  
   114      # The zero-tag image
   115      ${BUILDAH} pull --arch $arch     docker.io/$repo/busybox:1.33.1
   116      ${BUILDAH} manifest add $zeroimg docker.io/$repo/busybox:1.33.1
   117  done
   118  
   119  # Clean up
   120  cd /tmp
   121  rm -rf $tmpdir
   122  
   123  # Tag image and push (all arches) to quay.
   124  remote_tag=quay.io/libpod/testimage:$YMD
   125  podman tag testimage ${remote_tag}
   126  cat <<EOF
   127  
   128  If you're happy with these images, run:
   129  
   130     ${BUILDAH} manifest push --all  ${remote_tag} docker://${remote_tag}
   131     ${BUILDAH} manifest push --all  ${zeroimg} docker://${zeroimg}
   132  
   133  (You do not always need to push the :0000 image)
   134  
   135  EOF