github.com/nak3/source-to-image@v1.1.10-0.20180319140719-2ed55639898d/hack/test-stirunimage.sh (about)

     1  #!/bin/bash
     2  
     3  set -o errexit
     4  set -o nounset
     5  set -o pipefail
     6  
     7  export PATH="$PWD/_output/local/bin/$(go env GOHOSTOS)/$(go env GOHOSTARCH):$PATH"
     8  
     9  function time_now()
    10  {
    11      date +%s000
    12  }
    13  
    14  mkdir -p /tmp/sti
    15  WORK_DIR=$(mktemp -d /tmp/sti/test-work.XXXX)
    16  S2I_WORK_DIR=${WORK_DIR}
    17  if [[ "$OSTYPE" == "cygwin" ]]; then
    18      S2I_WORK_DIR=$(cygpath -w ${WORK_DIR})
    19  fi
    20  mkdir -p ${WORK_DIR}
    21  NEEDKILL="yes"
    22  S2I_PID=""
    23  function cleanup()
    24  {
    25      set +e
    26      #some failures will exit the shell script before check_result() can dump the logs (ssh seems to be such a case)
    27      if [ -a "${WORK_DIR}/ran-clean" ]; then
    28          echo "Cleaning up working dir ${WORK_DIR}"
    29      else
    30          echo "Dumping logs since did not run successfully before cleanup of ${WORK_DIR} ..."
    31          cat ${WORK_DIR}/*.log
    32      fi
    33      rm -rf ${WORK_DIR}
    34      # use sigint so that s2i post processing will remove docker container
    35      if [ -n "${NEEDKILL}" ]; then
    36          if [ -n "${S2I_PID}" ]; then
    37              kill -2 "${S2I_PID}"
    38          fi
    39      fi
    40      echo
    41      echo "Complete"
    42  }
    43  
    44  function check_result() {
    45      local result=$1
    46      if [ $result -eq 0 ]; then
    47          echo
    48          echo "TEST PASSED"
    49          echo
    50          if [ -n "${2}" ]; then
    51              rm $2
    52          fi
    53      else
    54          echo
    55          echo "TEST FAILED ${result}"
    56          echo
    57          cat $2
    58          cleanup
    59          exit $result
    60      fi
    61  }
    62  
    63  function test_debug() {
    64      echo
    65      echo $1
    66      echo
    67  }
    68  
    69  trap cleanup EXIT SIGINT
    70  
    71  echo "working dir:  ${WORK_DIR}"
    72  echo "s2i working dir:  ${S2I_WORK_DIR}"
    73  pushd ${WORK_DIR}
    74  
    75  test_debug "cloning source into working dir"
    76  
    77  git clone https://github.com/openshift/cakephp-ex &> "${WORK_DIR}/s2i-git-clone.log"
    78  check_result $? "${WORK_DIR}/s2i-git-clone.log"
    79  
    80  test_debug "s2i build with relative path without file://"
    81  
    82  s2i build cakephp-ex openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-rel-noproto.log"
    83  check_result $? "${WORK_DIR}/s2i-rel-noproto.log"
    84  
    85  test_debug "s2i build with volume options"
    86  s2i build cakephp-ex openshift/php-55-centos7 test --volume "${WORK_DIR}:/home/:z" --loglevel=5 &> "${WORK_DIR}/s2i-volume-correct.log"
    87  check_result $? "${WORK_DIR}/s2i-volume-correct.log"
    88  
    89  popd
    90  
    91  test_debug "s2i build with absolute path with file://"
    92  
    93  if [[ "$OSTYPE" == "cygwin" ]]; then
    94    S2I_WORK_DIR_URL="file:///${S2I_WORK_DIR//\\//}/cakephp-ex"
    95  else
    96    S2I_WORK_DIR_URL="file://${S2I_WORK_DIR}/cakephp-ex"
    97  fi
    98  
    99  s2i build "${S2I_WORK_DIR_URL}" openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-abs-proto.log"
   100  check_result $? "${WORK_DIR}/s2i-abs-proto.log"
   101  
   102  test_debug "s2i build with absolute path without file://"
   103  
   104  s2i build "${S2I_WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-abs-noproto.log"
   105  check_result $? "${WORK_DIR}/s2i-abs-noproto.log"
   106  
   107  ## don't do ssh tests here because credentials are needed (even for the git user), which
   108  ## don't exist in the vagrant/jenkins setup
   109  
   110  test_debug "s2i build with non-git repo file location"
   111  
   112  rm -rf "${WORK_DIR}/cakephp-ex/.git"
   113  s2i build "${S2I_WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test --loglevel=5 --loglevel=5 &> "${WORK_DIR}/s2i-non-repo.log"
   114  check_result $? ""
   115  grep "Copying sources" "${WORK_DIR}/s2i-non-repo.log"
   116  check_result $? "${WORK_DIR}/s2i-non-repo.log"
   117  
   118  test_debug "s2i rebuild"
   119  s2i build https://github.com/sclorg/s2i-php-container.git --context-dir=5.5/test/test-app registry.access.redhat.com/openshift3/php-55-rhel7 rack-test-app --incremental=true --loglevel=5 &> "${WORK_DIR}/s2i-pre-rebuild.log"
   120  check_result $? "${WORK_DIR}/s2i-pre-rebuild.log"
   121  s2i rebuild rack-test-app:latest rack-test-app:v1 -p never --loglevel=5 &> "${WORK_DIR}/s2i-rebuild.log"
   122  check_result $? "${WORK_DIR}/s2i-rebuild.log"
   123  
   124  test_debug "s2i usage"
   125  
   126  s2i usage openshift/ruby-20-centos7 --loglevel=5 &> "${WORK_DIR}/s2i-usage.log"
   127  check_result $? ""
   128  grep "Sample invocation" "${WORK_DIR}/s2i-usage.log"
   129  check_result $? "${WORK_DIR}/s2i-usage.log"
   130  
   131  test_debug "s2i build with overriding assemble/run scripts"
   132  s2i build https://github.com/openshift/source-to-image openshift/php-55-centos7 test --context-dir=test_apprepo >& "${WORK_DIR}/s2i-override-build.log"
   133  grep "Running custom assemble" "${WORK_DIR}/s2i-override-build.log"
   134  check_result $? "${WORK_DIR}/s2i-override-build.log"
   135  docker run test >& "${WORK_DIR}/s2i-override-run.log"
   136  grep "Running custom run" "${WORK_DIR}/s2i-override-run.log"
   137  check_result $? "${WORK_DIR}/s2i-override-run.log"
   138  
   139  test_debug "s2i build with remote git repo"
   140  s2i build https://github.com/openshift/cakephp-ex openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-git-proto.log"
   141  check_result $? "${WORK_DIR}/s2i-git-proto.log"
   142  
   143  test_debug "s2i build with --run==true option"
   144  if [[ "$OSTYPE" == "cygwin" ]]; then
   145    ( cd hack/windows/sigintwrap && make )
   146    hack/windows/sigintwrap/sigintwrap 's2i build --ref=10.x --context-dir=helloworld https://github.com/wildfly/quickstart openshift/wildfly-101-centos7 test-jee-app --run=true --loglevel=5' &> "${WORK_DIR}/s2i-run.log" &
   147  else
   148    s2i build --ref=10.x --context-dir=helloworld https://github.com/wildfly/quickstart openshift/wildfly-101-centos7 test-jee-app --run=true --loglevel=5 &> "${WORK_DIR}/s2i-run.log" &
   149  fi
   150  S2I_PID=$!
   151  TIME_SEC=1000
   152  TIME_MIN=$((60 * $TIME_SEC))
   153  max_wait=15*TIME_MIN
   154  echo "Waiting up to ${max_wait} for the build to finish ..."
   155  expire=$(($(time_now) + $max_wait))
   156  
   157  set +e
   158  while [[ $(time_now) -lt $expire ]]; do
   159      grep  "as a result of the --run=true option" "${WORK_DIR}/s2i-run.log"
   160      if [ $? -eq 0 ]; then
   161          echo "[INFO] Success running command s2i --run=true"
   162  
   163          # use sigint so that s2i post processing will remove docker container
   164          kill -2 "${S2I_PID}"
   165          NEEDKILL=""
   166          sleep 30
   167          docker ps -a | grep test-jee-app
   168  
   169          if [ $? -eq 1 ]; then
   170              echo "[INFO] Success terminating associated docker container"
   171              touch "${WORK_DIR}/ran-clean"
   172              exit 0
   173          else
   174              echo "[INFO] Associated docker container still found, review docker ps -a output above, and here is the dump of ${WORK_DIR}/s2i-run.log"
   175              cat "${WORK_DIR}/s2i-run.log"
   176              exit 1
   177          fi
   178      fi
   179      sleep 1
   180  done
   181  
   182  echo "[INFO] Problem with s2i --run=true, dumping ${WORK_DIR}/s2i-run.log"
   183  cat "${WORK_DIR}/s2i-run.log"
   184  set -e
   185  exit 1