-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·158 lines (136 loc) · 3.64 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·158 lines (136 loc) · 3.64 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env sh
#
# NAME
# bootstrap — bootstrap the project
#
# vim: set ts=4 sw=4 sts=4 noet:
# NOTE THAT THIS FILE IS INDENTED WITH 4-SPACE HARD TABS
# as is required for <<-EOF heredocs to work. Please keep
# it this way!
# -- Start bootstrap setup --
set -e
if test -n "$CI_DEBUG_TRACE" -o -n "$SHELLDEBUG"
then
set -x
fi
if test "${CI}" = 'true'
then
echo "::group::Build logs"
fi
unset PYTHONDEBUG
export COMPOSE_DISABLE_ENV_FILE=1
export PIP_DISABLE_PIP_VERSION_CHECK=1
export PYTHON_ROOT_USER_ACTION=ignore
export PYTHONWARNINGS=ignore
TEST_HOST=${TEST_HOST:-127.0.0.1}
docker_exec() {
if test "${CI}" = 'true'
then
docker exec -t postgres "$@"
else
docker compose exec postgres "$@"
fi
}
get_exposed_port() {
if test -f compose.yaml
then
if port=$(docker compose port "$1" --protocol "${3:-tcp}" "$2")
then
echo "${port#*:}"
else
echo "Failed to find port for $1:$2" >&2
return 1
fi
else
echo "Failed to find port for $1:$2 - compose.yaml not found" >&2
return 1
fi
}
if test -e ./.venv/bin/activate
then
. ./.venv/bin/activate
else
python3 -m venv --upgrade-deps .venv
. ./.venv/bin/activate
fi
mkdir -p build
pip install --upgrade pip
printf 'Installing maturin and dev dependencies...'
pip install maturin
maturin develop --extras dev
echo ' done.'
if test -d .git && test -f .pre-commit-config.yaml
then
printf 'Installing pre-commit hook...'
pre-commit install --install-hooks
echo ' done.'
fi
if test "${CI}" != 'true'
then
printf 'Cleaning environment...'
docker compose down --remove-orphans --volumes
echo ' done.'
printf 'Starting environment...'
docker compose up --wait --wait-timeout 120
echo ' done.'
fi
if test "${CI}" = 'true'
then
PGPORT=5432
else
PGPORT="$(get_exposed_port postgres 5432)"
fi
printf 'Generating .env...'
if test "${CI}" = 'true'
then
# In CI, use localhost since port is exposed from service container
cat > .env <<EOF
export FILE_CACHE_ENABLED=no
export TEST_HOST=localhost
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=postgres
export PGUSER=postgres
export PGPASSWORD=postgres
export POSTGRES_URI=postgresql://postgres:postgres@localhost:5432/postgres
EOF
else
cat > .env <<EOF
export FILE_CACHE_ENABLED=no
export TEST_HOST=${TEST_HOST}
export PGHOST=${TEST_HOST}
export PGPORT=${PGPORT}
export PGDATABASE=postgres
export PGUSER=postgres
export POSTGRES_URI=postgresql://postgres@${TEST_HOST}:${PGPORT}/postgres
EOF
fi
echo ' done.'
echo "Running pgbench ... "
docker_exec /usr/bin/pgbench -i -U postgres postgres
printf "Loading fixture schema ... "
docker_exec /usr/bin/psql -U postgres -d postgres -q -o /dev/null -f /fixtures/schema.sql
echo ' done.'
printf "Generating fixture data ... "
if test "${CI}" = 'true'
then
# In CI, connect to localhost since port is exposed from service container
PGPASSWORD=postgres python bin/generate-fixture-data.py -U postgres -h localhost -p 5432 -d postgres
else
python bin/generate-fixture-data.py -U postgres -h "${TEST_HOST}" -p "${PGPORT}" -d postgres
fi
echo ' done.'
printf "Creating test backups ... "
docker_exec /usr/bin/pg_dump -Fc -U postgres -f /data/dump.not-compressed -d postgres --compress=0
docker_exec /usr/bin/pg_dump -Fc -U postgres -f /data/dump.compressed -d postgres --compress=9
docker_exec /usr/bin/pg_dump -Fc -U postgres -f /data/dump.no-data -d postgres --compress=0 -s
docker_exec /usr/bin/pg_dump -Fc -U postgres -f /data/dump.data-only -d postgres --compress=0 -a
docker_exec /usr/bin/pg_dump -Fc -U postgres -f /data/dump.inserts -d postgres --compress=0 --inserts
echo ' done.'
printf "Fixing permissions ... "
docker_exec chmod -R a+r /data
echo ' done.'
if test "${CI}" = 'true'
then
echo '::endgroup::'
fi