SHARE
TWEET

Untitled

a guest Apr 21st, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. PROJECT_NAME="project-name"
  4. CONTAINER_NAME="container"
  5. # define some colors to use for output
  6. RED='\033[0;31m'
  7. GREEN='\033[0;32m'
  8. NC='\033[0m'
  9. # kill and remove any running containers
  10. cleanup () {
  11.   docker-compose -p ${PROJECT_NAME} kill
  12.   docker-compose -p ${PROJECT_NAME} rm -f --all
  13. }
  14. # catch unexpected failures, do cleanup and output an error message
  15. trap 'cleanup ; printf "${RED}Tests Failed For Unexpected Reasons${NC}\n"'\
  16.   HUP INT QUIT PIPE TERM
  17. # build and run the composed services
  18. docker-compose -p ${PROJECT_NAME} build && docker-compose -p ${PROJECT_NAME} up -d
  19. if [ $? -ne 0 ] ; then
  20.   printf "${RED}Docker Compose Failed${NC}\n"
  21.   exit -1
  22. fi
  23. # wait for the test service to complete and grab the exit code
  24. TEST_EXIT_CODE=`docker wait ${PROJECT_NAME}_${CONTAINER_NAME}_1`
  25. # output the logs for the test (for clarity)
  26. docker logs ${PROJECT_NAME}_${CONTAINER_NAME}_1
  27. # inspect the output of the test and display respective message
  28. if [ -z ${TEST_EXIT_CODE+x} ] || [ "$TEST_EXIT_CODE" -ne 0 ] ; then
  29.   printf "${RED}Tests Failed${NC} - Exit Code: $TEST_EXIT_CODE\n"
  30. else
  31.   printf "${GREEN}Tests Passed${NC}\n"
  32. fi
  33. # call the cleanup fuction
  34. cleanup
  35. # exit the script with the same code as the test service code
  36. exit $TEST_EXIT_CODE
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top