mirror of
https://github.com/sprockets/sprockets-postgres.git
synced 2024-11-10 19:29:28 +00:00
77 lines
1.7 KiB
Bash
Executable file
77 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
set -e
|
|
|
|
# Common constants
|
|
COLOR_RESET='\033[0m'
|
|
COLOR_GREEN='\033[0;32m'
|
|
COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-${PWD##*/}}"
|
|
TEST_HOST="${TEST_HOST:-localhost}"
|
|
|
|
echo "Integration test host: ${TEST_HOST}"
|
|
|
|
get_exposed_port() {
|
|
if [ -z $3 ]
|
|
then
|
|
docker-compose port $1 $2 | cut -d: -f2
|
|
else
|
|
docker-compose port --index=$3 $1 $2 | cut -d: -f2
|
|
fi
|
|
}
|
|
|
|
report_start() {
|
|
printf "Waiting for $1 ... "
|
|
}
|
|
|
|
report_done() {
|
|
printf "${COLOR_GREEN}done${COLOR_RESET}\n"
|
|
}
|
|
|
|
wait_for_healthy_containers() {
|
|
IDs=$(docker-compose ps -q | paste -sd " " -)
|
|
report_start "${1} containers to report healthy"
|
|
counter="0"
|
|
while true
|
|
do
|
|
if [ "$(docker inspect -f "{{.State.Health.Status}}" ${IDs} | grep -c healthy)" -eq "${1}" ]; then
|
|
break
|
|
fi
|
|
counter=$((++counter))
|
|
if [ "${counter}" -eq 120 ]; then
|
|
echo " ERROR: containers failed to start"
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
report_done
|
|
}
|
|
|
|
# Ensure Docker is Running
|
|
echo "Docker Information:"
|
|
echo ""
|
|
docker version
|
|
echo ""
|
|
|
|
# Activate the virtual environment
|
|
if test -e env/bin/activate
|
|
then
|
|
. ./env/bin/activate
|
|
fi
|
|
|
|
mkdir -p build
|
|
|
|
# Stop any running instances and clean up after them, then pull images
|
|
docker-compose down --volumes --remove-orphans
|
|
docker-compose up -d --quiet-pull
|
|
|
|
wait_for_healthy_containers 1
|
|
|
|
printf "Loading fixture data ... "
|
|
docker-compose exec postgres psql -q -o /dev/null -U postgres -d postgres -f /fixtures/testing.sql
|
|
report_done
|
|
|
|
cat > build/test-environment<<EOF
|
|
export ASYNC_TEST_TIMEOUT=5
|
|
export POSTGRES_URL=postgresql://postgres@${TEST_HOST}:$(get_exposed_port postgres 5432)/postgres
|
|
EOF
|
|
|
|
printf "\nBootstrap complete\n\nDon't forget to \"source build/test-environment\"\n"
|