feat(dbtest): Mount DB dumps and create templates

Mount the benchmark dump directory when running
the test database and create a new script for creating
templates from the dumps. This makes it easy to create
pre-populated databases for benchmark tests.

Fixes https://hashicorp.atlassian.net/browse/ICU-4040
pull/2049/head
Johan Brandhorst-Satzkorn 4 years ago committed by Timothy Messier
parent 9e424db0a3
commit 5d042c7ec7
No known key found for this signature in database
GPG Key ID: EFD2F184F7600572

@ -1,6 +1,7 @@
FROM postgres:11-alpine
ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh
ADD restore-benchmark-dumps.sh /docker-entrypoint-initdb.d/01-restore-benchmark-dumps.sh
ADD postgresql.conf /etc/postgresql/postgresql.conf
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

@ -1,6 +1,7 @@
FROM postgres:12-alpine
ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh
ADD restore-benchmark-dumps.sh /docker-entrypoint-initdb.d/01-restore-benchmark-dumps.sh
ADD postgresql.conf /etc/postgresql/postgresql.conf
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

@ -1,6 +1,7 @@
FROM postgres:13-alpine
ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh
ADD restore-benchmark-dumps.sh /docker-entrypoint-initdb.d/01-restore-benchmark-dumps.sh
ADD postgresql.conf /etc/postgresql/postgresql.conf
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

@ -1,6 +1,7 @@
FROM postgres:alpine
ADD init-db.sh /docker-entrypoint-initdb.d/00-init-db.sh
ADD restore-benchmark-dumps.sh /docker-entrypoint-initdb.d/01-restore-benchmark-dumps.sh
ADD postgresql.conf /etc/postgresql/postgresql.conf
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

@ -47,6 +47,7 @@ database-up:
-e PGDATA=/pgdata \
--mount type=tmpfs,destination=/pgdata \
-v "$(CWD)/../../../internal/db/schema/migrations":/migrations \
-v "$(CWD)/benchmark_dumps":/benchmark_dumps \
$(TEST_IMAGE_TAG) \
-c 'config_file=/etc/postgresql/postgresql.conf' \
$(PG_OPTS) 1> /dev/null

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
shopt -s globstar
for file in $(ls -v /benchmark_dumps/*.dump); do
echo "Creating template database based on: ${file}"
db_name="boundary_$(basename ${file} .dump)_template"
psql -v "ON_ERROR_STOP=1" --username "$POSTGRES_USER" --dbname "${POSTGRES_DB}" -q <<EOSQL
create database ${db_name} owner ${POSTGRES_USER};
EOSQL
echo "Restoring ${file} into ${db_name}"
pg_restore -j $(nproc) --username "${POSTGRES_USER}" --dbname ${db_name} "${file}"
psql -v "ON_ERROR_STOP=1" --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" -q <<EOSQL
update pg_database set datistemplate = true, datallowconn = false where datname = '${db_name}';
EOSQL
done
Loading…
Cancel
Save