Created
April 11, 2019 08:27
-
-
Save mgasiorowski/c2aaa75522f4a81d03d54156ea3a3c40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PROJECT_NAME="project-name" | |
CONTAINER_NAME="container" | |
# define some colors to use for output | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' | |
# kill and remove any running containers | |
cleanup () { | |
docker-compose -p ${PROJECT_NAME} kill | |
docker-compose -p ${PROJECT_NAME} rm -f --all | |
} | |
# catch unexpected failures, do cleanup and output an error message | |
trap 'cleanup ; printf "${RED}Tests Failed For Unexpected Reasons${NC}\n"'\ | |
HUP INT QUIT PIPE TERM | |
# build and run the composed services | |
docker-compose -p ${PROJECT_NAME} build && docker-compose -p ${PROJECT_NAME} up -d | |
if [ $? -ne 0 ] ; then | |
printf "${RED}Docker Compose Failed${NC}\n" | |
exit -1 | |
fi | |
# wait for the test service to complete and grab the exit code | |
TEST_EXIT_CODE=`docker wait ${PROJECT_NAME}_${CONTAINER_NAME}_1` | |
# output the logs for the test (for clarity) | |
docker logs ${PROJECT_NAME}_${CONTAINER_NAME}_1 | |
# inspect the output of the test and display respective message | |
if [ -z ${TEST_EXIT_CODE+x} ] || [ "$TEST_EXIT_CODE" -ne 0 ] ; then | |
printf "${RED}Tests Failed${NC} - Exit Code: $TEST_EXIT_CODE\n" | |
else | |
printf "${GREEN}Tests Passed${NC}\n" | |
fi | |
# call the cleanup fuction | |
cleanup | |
# exit the script with the same code as the test service code | |
exit $TEST_EXIT_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment