graphql-engine/scripts/containers/citus
Samir Talwar c0a0a5fe87 docker: Mount database data directories as named volumes.
I'm trying to shore up the Python integration tests to make them more reliable. In doing so, I noticed this.

---

This ensures that the data directories are always in a mutable file system, and not going through overlayfs.

In my testing, this sped up PostgreSQL database initialization a lot. In particular, `CREATE DATABASE` commands went from > 5s to < 0.1s.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5248
GitOrigin-RevId: 5104aea32c92559c323803020d727bebfdafb8e6
2022-08-04 10:11:10 +00:00

57 lines
1.7 KiB
Plaintext

### This file is not meant to be run directly, but to be sourced from
### the dev script. It defines all the functions required to run a
### citus docker container.
######################
# Configuration #
######################
if [ "$MODE" = "test" ]; then
CITUS_PORT=55432
else
CITUS_PORT=65432
fi
CITUS_PASSWORD=hasuraCITUS2
CITUS_VOLUME_NAME='hasura-dev-citus-single'
CITUS_CONTAINER_NAME="hasura-dev-citus-single-$CITUS_PORT"
CITUS_DB_URL="postgres://postgres:$CITUS_PASSWORD@127.0.0.1:$CITUS_PORT/postgres"
CITUS_DB_DOCKER_URL="postgres://postgres:$CITUS_PASSWORD@127.0.0.1:5432/postgres"
CITUS_DOCKER="docker exec -u postgres -it $CITUS_CONTAINER_NAME psql $CITUS_DB_DOCKER_URL"
######################
# Functions #
######################
function citus_launch_container {
echo_pretty "Launching Citus container: $CITUS_CONTAINER_NAME"
docker volume create "$CITUS_VOLUME_NAME"
docker run \
--name "$CITUS_CONTAINER_NAME" \
-p "127.0.0.1:$CITUS_PORT:5432" \
--expose="$CITUS_PORT" \
--volume="${CITUS_VOLUME_NAME}:/var/lib/postgresql/data" \
--env=POSTGRES_PASSWORD="$CITUS_PASSWORD" \
--detach \
citusdata/citus:10.1
}
function citus_wait {
echo -n "Waiting for citus to come up"
until ( $CITUS_DOCKER -c "SELECT * FROM citus_version();" ) &>/dev/null; do
echo -n '.' && sleep 0.2
done
echo " Ok"
}
function citus_cleanup {
echo_pretty "Removing $CITUS_CONTAINER_NAME and its volumes in 5 seconds!"
echo_pretty " PRESS CTRL-C TO ABORT removal of all containers, or ENTER to clean up right away"
read -t5 || true
docker stop "$CITUS_CONTAINER_NAME"
docker rm -v "$CITUS_CONTAINER_NAME"
docker volume rm "$CITUS_VOLUME_NAME"
}