Skip to content

Instantly share code, notes, and snippets.

@w32blaster
Last active June 28, 2017 13:43
Show Gist options
  • Save w32blaster/965bad80a6613fe924eb2f82aa159e4f to your computer and use it in GitHub Desktop.
Save w32blaster/965bad80a6613fe924eb2f82aa159e4f to your computer and use it in GitHub Desktop.
Run Functional Tests in the ConcourseCI (inside the image mumoshu/dcind)
#!/bin/sh
# Colors
GREEN='\033[1;32m'
RED='\033[1;31m'
NC='\033[0m' # No Color
# To load the `start_docker` function defined in /docker-lib.sh from the docker image `mumoshu/dcind`
source /docker-lib.sh
# Run docker with the insecure registry
start_docker "my-private-registry:5043"
# login to private repository:
printf "\n\n ${GREEN} ● Login to private repository ${NC}\n"
docker login --username my-name --password myPassword https://my-private-registry:5043
cd ops-code/
# print all the commands to the console for debugging purposes
set -x
printf "\n\n ${GREEN} ● Run docker-compose and set up the production system locally. ${NC}\n"
docker-compose up -d
sleep 60
# before we proceed, make sure that all containers are running
IS_SOLR_RUNNING=$(docker inspect solr | jq -r '.[] | .State.Running')
IS_MONGO_RUNNING=$(docker inspect mongo | jq -r '.[] | .State.Running')
IS_NGINX_RUNNING=$(docker inspect nginx | jq -r '.[] | .State.Running')
IS_CORE_RUNNING=$(docker inspect core | jq -r '.[] | .State.Running')
IS_LOGGLY_RUNNING=$(docker inspect loggly | jq -r '.[] | .State.Running')
if [ "$IS_SOLR_RUNNING" = false ] || [ "$IS_MONGO_RUNNING" = false ] || [ "$IS_NGINX_RUNNING" = false ] || [ "$IS_LOGGLY_RUNNING" = false ] || [ "$IS_CORE_RUNNING" = false ]; then
printf "\n\n ${RED} ✘ Some containers are not running! \n
● Solr: ${IS_SOLR_RUNNING}
● Mongo: ${IS_MONGO_RUNNING}
● Nginx: ${IS_NGINX_RUNNING}
● Loggly: ${IS_LOGGLY_RUNNING}
● Core: ${IS_CORE_RUNNING} ${NC} \n\n"
# exit here, becuase Functional Tests don't make any sence since some containers are not running
docker-compose stop
docker rm $(docker ps -a -q)
cd ../..
source /docker-lib.sh
stop_docker
exit 1
fi
# remember that absolute path to my tests
cd ../../source-code
ABS_SOURCE=$(pwd .)
# the UID and GUI of "firefox" user (that comes from the khozzy/selenium-java-firefox image)
chown -R 1000:1000 "$ABS_SOURCE"
# Mongo is running inside a container, so, it is not "localhost". Let's find out its real IP address
MONGO_VIRTUAL_IP=$(docker inspect mongo | jq -r '.[] | .NetworkSettings.Networks.ci_default.IPAddress')
NGINX_VIRTUAL_IP=$(docker inspect nginx | jq -r '.[] | .NetworkSettings.Networks.ci_default.IPAddress')
# Run the functional tests
printf "\n\n ${GREEN} ● Run the Functional Tests ${NC}\n"
docker run -it --rm \
-w /tests \
-v "$ABS_SOURCE":/tests \
-e "SPRING_DATA_MONGODB_HOST=$MONGO_VIRTUAL_IP" \
-e "NGINX_VIRTUAL_IP=$NGINX_VIRTUAL_IP" \
--add-host my-host.com:"$NGINX_VIRTUAL_IP" \
--add-host www.my-host.com:"$NGINX_VIRTUAL_IP" \
--network=ci_default \
w32blaster/selenium-gradle \
xvfb-daemon-run gradle -q runAllTests
TEST_RESULTS=$?
if [ $TEST_RESULTS -eq 0 ];then
printf "\n\n ${GREEN} ✔ The Functional tests are successful! ${NC}\n"
else
printf "\n\n ${RED} ● The Functional Tests are failed! ${NC}\n"
fi
# save the logs and reports from tests and send them somewhere
docker logs core > build/reports/core.log
docker logs solr > build/reports/solr.log
docker logs mongo > build/reports/mongo.log
docker logs nginx > build/reports/nginx.log
printf "\n\n ${GREEN} ● Pack the reports to .tar archive ${NC}\n"
tar cfz test-results.tar.gz build/reports
printf "\n\n ${GREEN} ● Upload test results to the server ${NC}\n"
scp -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no test-results.tar.gz user@my-share-ssh-server:~
printf "\n\n ${GREEN} ● Stop the local production system ${NC}\n"
cd ../ops-code/ci
docker-compose stop
# remove all the stopped containers to free the disk space
docker rm $(docker ps -a -q)
# stop the docker service
cd ../..
source /docker-lib.sh
stop_docker
exit $TEST_RESULTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment