github.com/boson-project/source-to-image@v1.2.0/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/sclorg/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 docker.io/centos/php-70-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 docker.io/centos/php-70-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}" docker.io/centos/php-70-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" docker.io/centos/php-70-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" docker.io/centos/php-70-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 docker.io/centos/ruby-24-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 docker.io/centos/php-70-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 add-host option"
   140  set +e
   141  s2i build https://github.com/openshift/ruby-hello-world centos/ruby-23-centos7 --add-host rubygems.org:0.0.0.0 test-ruby-app &> "${WORK_DIR}/s2i-add-host.log"
   142  grep "Gem::RemoteFetcher::FetchError: Errno::ECONNREFUSED" "${WORK_DIR}/s2i-add-host.log"
   143  check_result $? "${WORK_DIR}/s2i-add-host.log"
   144  set -e
   145  test_debug "s2i build with remote git repo"
   146  s2i build https://github.com/sclorg/cakephp-ex docker.io/centos/php-70-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-git-proto.log"
   147  check_result $? "${WORK_DIR}/s2i-git-proto.log"
   148  
   149  test_debug "s2i build with runtime image"
   150  s2i build --ref=10.x --context-dir=helloworld https://github.com/wildfly/quickstart docker.io/openshift/wildfly-101-centos7 test-jee-app-thin --runtime-image=docker.io/openshift/wildfly-101-centos7 &> "${WORK_DIR}/s2i-runtime-image.log"
   151  check_result $? "${WORK_DIR}/s2i-runtime-image.log"
   152  
   153  test_debug "s2i build with Dockerfile output"
   154  s2i build https://github.com/sclorg/cakephp-ex docker.io/centos/php-70-centos7 --as-dockerfile=${WORK_DIR}/asdockerfile/Dockerfile --loglevel=5 >& "${WORK_DIR}/s2i-dockerfile.log"
   155  check_result $? "${WORK_DIR}/s2i-dockerfile.log"
   156  
   157  
   158  test_debug "s2i build with --run==true option"
   159  if [[ "$OSTYPE" == "cygwin" ]]; then
   160    ( cd hack/windows/sigintwrap && make )
   161    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" &
   162  else
   163    s2i build --ref=10.x --context-dir=helloworld https://github.com/wildfly/quickstart docker.io/openshift/wildfly-101-centos7 test-jee-app --run=true --loglevel=5 &> "${WORK_DIR}/s2i-run.log" &
   164  fi
   165  S2I_PID=$!
   166  TIME_SEC=1000
   167  TIME_MIN=$((60 * $TIME_SEC))
   168  max_wait=15*TIME_MIN
   169  echo "Waiting up to ${max_wait} for the build to finish ..."
   170  expire=$(($(time_now) + $max_wait))
   171  
   172  set +e
   173  while [[ $(time_now) -lt $expire ]]; do
   174      grep  "as a result of the --run=true option" "${WORK_DIR}/s2i-run.log"
   175      if [ $? -eq 0 ]; then
   176          echo "[INFO] Success running command s2i --run=true"
   177  
   178          # use sigint so that s2i post processing will remove docker container
   179          kill -2 "${S2I_PID}"
   180          NEEDKILL=""
   181          sleep 30
   182          docker ps -a | grep test-jee-app
   183  
   184          if [ $? -eq 1 ]; then
   185              echo "[INFO] Success terminating associated docker container"
   186              touch "${WORK_DIR}/ran-clean"
   187              exit 0
   188          else
   189              echo "[INFO] Associated docker container still found, review docker ps -a output above, and here is the dump of ${WORK_DIR}/s2i-run.log"
   190              cat "${WORK_DIR}/s2i-run.log"
   191              exit 1
   192          fi
   193      fi
   194      sleep 1
   195  done
   196  
   197  echo "[INFO] Problem with s2i --run=true, dumping ${WORK_DIR}/s2i-run.log"
   198  cat "${WORK_DIR}/s2i-run.log"
   199  set -e
   200  exit 1