-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap
executable file
·102 lines (83 loc) · 2.74 KB
/
bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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
rm -rf build
mkdir -p build build/data
# 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
PGPORT=$(get_exposed_port postgres 5432)
echo "Running pgbench ... "
docker-compose exec postgres /usr/bin/pgbench -i -U postgres postgres
printf "Loading fixture schema ... "
docker-compose exec postgres /usr/bin/psql -U postgres -d postgres -q -o /dev/null -f /fixtures/schema.sql
report_done
printf "Generating fixture data ... "
bin/generate-fixture-data.py -U postgres -h ${TEST_HOST} -p ${PGPORT} -d postgres
report_done
printf "Creating test backups ... "
docker-compose exec postgres /usr/bin/pg_dump -Fc -U postgres -f /data/dump.not-compressed -d postgres --compress=0
docker-compose exec postgres /usr/bin/pg_dump -Fc -U postgres -f /data/dump.compressed -d postgres --compress=9
docker-compose exec postgres /usr/bin/pg_dump -Fc -U postgres -f /data/dump.no-data -d postgres --compress=0 -s
docker-compose exec postgres /usr/bin/pg_dump -Fc -U postgres -f /data/dump.data-only -d postgres --compress=0 -a
docker-compose exec postgres /usr/bin/pg_dump -Fc -U postgres -f /data/dump.inserts -d postgres --compress=0 --inserts
report_done
printf "Fixing permissions ... "
docker-compose exec postgres chmod -R a+r /data
report_done
cat > build/test-environment<<EOF
export PGHOST=${TEST_HOST}
export PGPORT=${PGPORT}
export PGDATABASE=postgres
export PGUSER=postgres
export POSTGRES_URI=postgresql://postgres@${TEST_HOST}:${PGPORT}/postgres
EOF
printf "\nBootstrap complete\n\nDon't forget to \". build/test-environment\"\n"