github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/contrib/cirrus/runner.sh (about)

     1  #!/bin/bash
     2  
     3  set -eo pipefail
     4  
     5  # This script runs in the Cirrus CI environment, invoked from .cirrus.yml .
     6  # It can also be invoked manually in a `hack/get_ci_cm.sh` environment,
     7  # documentation of said usage is TBI.
     8  #
     9  # The principal deciding factor is the $TEST_FLAVOR envariable: for any
    10  # given value 'xyz' there must be a function '_run_xyz' to handle that
    11  # test. Several other envariables are used to differentiate further,
    12  # most notably:
    13  #
    14  #    PODBIN_NAME  : "podman" (i.e. local) or "remote"
    15  #    TEST_ENVIRON : 'host' or 'container'; desired environment in which to run
    16  #    CONTAINER    : 1 if *currently* running inside a container, 0 if host
    17  #
    18  
    19  # shellcheck source=contrib/cirrus/lib.sh
    20  source $(dirname $0)/lib.sh
    21  
    22  function _run_ext_svc() {
    23      $SCRIPT_BASE/ext_svc_check.sh
    24  }
    25  
    26  function _run_automation() {
    27      $SCRIPT_BASE/cirrus_yaml_test.py
    28  
    29      req_env_vars CI DEST_BRANCH IMAGE_SUFFIX TEST_FLAVOR TEST_ENVIRON \
    30                   PODBIN_NAME PRIV_NAME DISTRO_NV CONTAINER USER HOME \
    31                   UID AUTOMATION_LIB_PATH SCRIPT_BASE OS_RELEASE_ID \
    32                   OS_RELEASE_VER CG_FS_TYPE
    33      bigto ooe.sh dnf install -y ShellCheck  # small/quick addition
    34      $SCRIPT_BASE/shellcheck.sh
    35  }
    36  
    37  function _run_validate() {
    38      # git-validation tool fails if $EPOCH_TEST_COMMIT is empty
    39      # shellcheck disable=SC2154
    40      if [[ -n "$EPOCH_TEST_COMMIT" ]]; then
    41          make validate
    42      else
    43          warn "Skipping git-validation since \$EPOCH_TEST_COMMIT is empty"
    44      fi
    45  
    46  }
    47  
    48  function _run_unit() {
    49      # shellcheck disable=SC2154
    50      if [[ "$PODBIN_NAME" != "podman" ]]; then
    51          # shellcheck disable=SC2154
    52          die "$TEST_FLAVOR: Unsupported PODBIN_NAME='$PODBIN_NAME'"
    53      fi
    54      make localunit
    55  }
    56  
    57  function _run_apiv2() {
    58      # TODO Remove once VM's with dependency
    59      if [[ "$OS_RELEASE_ID" == "fedora" ]]; then
    60          dnf install -y python3-docker
    61      else
    62          apt-get -qq -y install python3-docker
    63      fi
    64      make localapiv2 |& logformatter
    65  }
    66  
    67  function _run_int() {
    68      dotest integration
    69  }
    70  
    71  function _run_sys() {
    72      dotest system
    73  }
    74  
    75  function _run_bindings() {
    76      # shellcheck disable=SC2155
    77      export PATH=$PATH:$GOSRC/hack
    78  
    79      # Subshell needed so logformatter will write output in cwd; if it runs in
    80      # the subdir, .cirrus.yml will not find the html'ized log
    81      (cd pkg/bindings/test && ginkgo -trace -noColor -debug  -r) |& logformatter
    82  }
    83  
    84  function _run_docker-py() {
    85      msg "This is docker-py stub, it is only a stub"
    86  }
    87  
    88  function _run_endpoint() {
    89      make test-binaries
    90      make endpoint
    91  }
    92  
    93  exec_container() {
    94      local var_val
    95      local cmd
    96      # Required to be defined by caller
    97      # shellcheck disable=SC2154
    98      msg "Re-executing runner inside container: $CTR_FQIN"
    99      msg "************************************************************"
   100  
   101      req_env_vars CTR_FQIN TEST_ENVIRON CONTAINER SECRET_ENV_RE
   102  
   103      # Line-separated arguments which include shell-escaped special characters
   104      declare -a envargs
   105      while read -r var_val; do
   106          envargs+=("-e $var_val")
   107      done <<<"$(passthrough_envars)"
   108  
   109      # VM Images and Container images are built using (nearly) identical operations.
   110      set -x
   111      # shellcheck disable=SC2154
   112      exec podman run --rm --privileged --net=host --cgroupns=host \
   113          -v /dev/fuse:/dev/fuse \
   114          -v "$GOPATH:$GOPATH:Z" \
   115          --workdir "$GOSRC" \
   116          -e "CONTAINER=1" \
   117          "${envargs[@]}" \
   118          $CTR_FQIN bash -c "$SCRIPT_BASE/setup_environment.sh && $SCRIPT_BASE/runner.sh"
   119  }
   120  
   121  function _run_swagger() {
   122      local download_url
   123      # Building this is a PITA, just grab binary for use in automation
   124      # Ref: https://goswagger.io/install.html#static-binary
   125      download_url=$(\
   126          curl -s https://api.github.com/repos/go-swagger/go-swagger/releases/latest | \
   127          jq -r '.assets[] | select(.name | contains("linux_amd64")) | .browser_download_url')
   128      curl -o /usr/local/bin/swagger -L'#' "$download_url"
   129      chmod +x /usr/local/bin/swagger
   130  
   131      cd $GOSRC
   132      make swagger
   133  
   134      # Cirrus-CI Artifact instruction expects file here
   135      cp -v $GOSRC/pkg/api/swagger.yaml $GOSRC/
   136  }
   137  
   138  function _run_vendor() {
   139      make vendor
   140      ./hack/tree_status.sh
   141  }
   142  
   143  function _run_build() {
   144      # Ensure always start from clean-slate with all vendor modules downloaded
   145      make clean
   146      make vendor
   147      make podman-release
   148      make podman-remote-linux-release
   149  }
   150  
   151  function _run_altbuild() {
   152      req_env_vars ALT_NAME
   153      # Defined in .cirrus.yml
   154      # shellcheck disable=SC2154
   155      msg "Performing alternate build: $ALT_NAME"
   156      msg "************************************************************"
   157      cd $GOSRC
   158      case "$ALT_NAME" in
   159          *Each*)
   160              git fetch origin
   161              make build-all-new-commits GIT_BASE_BRANCH=origin/$DEST_BRANCH
   162              ;;
   163          *Windows*)
   164              make podman-remote-windows-release
   165              make podman.msi
   166              ;;
   167          *Without*)
   168              make build-no-cgo
   169              ;;
   170          *varlink-API)
   171              export SUGGESTION='remove API.md, then "make varlink_api_generate" and commit changes.'
   172              make varlink_api_generate BUILDTAGS="varlink"
   173              ./hack/tree_status.sh
   174              ;;
   175          *varlink-binaries)
   176              make clean BUILDTAGS="varlink" binaries
   177              ;;
   178          *RPM*)
   179              make -f ./.copr/Makefile
   180              rpmbuild --rebuild ./podman-*.src.rpm
   181              ;;
   182          *Static*)
   183              req_env_vars CTR_FQIN
   184              [[ "$UID" -eq 0 ]] || \
   185                  die "Static build must execute nixos container as root on host"
   186              mkdir -p /var/cache/nix
   187              podman run -i --rm -v /var/cache/nix:/mnt/nix:Z \
   188                  $CTR_FQIN cp -rfT /nix /mnt/nix
   189              podman run -i --rm -v /var/cache/nix:/nix:Z \
   190                  -v $PWD:$PWD:Z -w $PWD $CTR_FQIN \
   191                  nix --print-build-logs --option cores 4 --option max-jobs 4 \
   192                      build --file ./nix/
   193              # result symlink is absolute from container perspective :(
   194              cp /var/cache/$(readlink result)/bin/podman ./  # for cirrus-ci artifact
   195              rm result  # makes cirrus puke
   196              ;;
   197          *)
   198              die "Unknown/Unsupported \$$ALT_NAME '$ALT_NAME'"
   199      esac
   200  }
   201  
   202  function _run_release() {
   203      if bin/podman info |& grep -Eq -- '-dev'; then
   204          die "Releases must never contain '-dev' in output of 'podman info'"
   205      fi
   206  }
   207  
   208  logformatter() {
   209      # Use similar format as human-friendly task name from .cirrus.yml
   210      # shellcheck disable=SC2154
   211      output_name="$TEST_FLAVOR-$PODBIN_NAME-$DISTRO_NV-$PRIV_NAME-$TEST_ENVIRON"
   212      # Requires stdin and stderr combined!
   213      cat - \
   214          |& awk --file "${CIRRUS_WORKING_DIR}/${SCRIPT_BASE}/timestamp.awk" \
   215          |& "${CIRRUS_WORKING_DIR}/${SCRIPT_BASE}/logformatter" "$output_name"
   216  }
   217  
   218  # Handle local|remote integration|system testing in a uniform way
   219  dotest() {
   220      local testsuite="$1"
   221      req_env_vars testsuite CONTAINER TEST_ENVIRON PRIV_NAME
   222  
   223      # shellcheck disable=SC2154
   224      if ((CONTAINER==0)) && [[ "$TEST_ENVIRON" == "container" ]]; then
   225          exec_container  # does not return
   226      fi;
   227  
   228      # shellcheck disable=SC2154
   229      if [[ "$PRIV_NAME" == "rootless" ]] && [[ "$UID" -eq 0 ]]; then
   230          req_env_vars ROOTLESS_USER
   231          msg "Re-executing runner through ssh as user '$ROOTLESS_USER'"
   232          msg "************************************************************"
   233          set -x
   234          exec ssh $ROOTLESS_USER@localhost \
   235                  -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
   236                  -o CheckHostIP=no $GOSRC/$SCRIPT_BASE/runner.sh
   237          # does not return
   238      fi
   239  
   240      # containers/automation sets this to 0 for its dbg() function
   241      # but the e2e integration tests are also sensitive to it.
   242      unset DEBUG
   243  
   244      # shellcheck disable=SC2154
   245      local localremote="$PODBIN_NAME"
   246      case "$PODBIN_NAME" in
   247          podman)  localremote="local" ;;
   248      esac
   249  
   250      make ${localremote}${testsuite} PODMAN_SERVER_LOG=$PODMAN_SERVER_LOG \
   251          |& logformatter
   252  }
   253  
   254  # Nearly every task in .cirrus.yml makes use of this shell script
   255  # wrapped by /usr/bin/time to collect runtime statistics.  Because the
   256  # --output option is used to log stats to a file, every child-process
   257  # inherits an open FD3 pointing at the log.  However, some testing
   258  # operations depend on making use of FD3, and so it must be explicitly
   259  # closed here (and for all further child-processes).
   260  # STATS_LOGFILE assumed empty/undefined outside of Cirrus-CI (.cirrus.yml)
   261  # shellcheck disable=SC2154
   262  exec 3<&-
   263  
   264  msg "************************************************************"
   265  # Required to be defined by caller
   266  # shellcheck disable=SC2154
   267  msg "Runner executing $TEST_FLAVOR $PODBIN_NAME-tests as $PRIV_NAME on $DISTRO_NV($OS_REL_VER)"
   268  if ((CONTAINER)); then
   269      # shellcheck disable=SC2154
   270      msg "Current environment container image: $CTR_FQIN"
   271  else
   272      # shellcheck disable=SC2154
   273      msg "Current environment VM image: $VM_IMAGE_NAME"
   274  fi
   275  msg "************************************************************"
   276  
   277  ((${SETUP_ENVIRONMENT:-0})) || \
   278      die "Expecting setup_environment.sh to have completed successfully"
   279  
   280  cd "${GOSRC}/"
   281  
   282  handler="_run_${TEST_FLAVOR}"
   283  
   284  if [ "$(type -t $handler)" != "function" ]; then
   285      die "Unknown/Unsupported \$TEST_FLAVOR=$TEST_FLAVOR"
   286  fi
   287  
   288  $handler