2021-04-08 18:02:56 +03:00
|
|
|
### 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
|
2022-08-04 13:08:54 +03:00
|
|
|
CITUS_VOLUME_NAME='hasura-dev-citus-single'
|
2021-04-08 18:02:56 +03:00
|
|
|
CITUS_CONTAINER_NAME="hasura-dev-citus-single-$CITUS_PORT"
|
2021-05-21 05:46:58 +03:00
|
|
|
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"
|
2021-04-08 18:02:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Functions #
|
|
|
|
######################
|
|
|
|
|
2022-08-04 13:08:54 +03:00
|
|
|
function citus_launch_container {
|
2021-04-08 18:02:56 +03:00
|
|
|
echo_pretty "Launching Citus container: $CITUS_CONTAINER_NAME"
|
2022-08-04 13:08:54 +03:00
|
|
|
docker volume create "$CITUS_VOLUME_NAME"
|
2021-04-08 18:02:56 +03:00
|
|
|
docker run \
|
|
|
|
--name "$CITUS_CONTAINER_NAME" \
|
2022-08-04 13:08:54 +03:00
|
|
|
-p "127.0.0.1:$CITUS_PORT:5432" \
|
2021-04-08 18:02:56 +03:00
|
|
|
--expose="$CITUS_PORT" \
|
2022-08-04 13:08:54 +03:00
|
|
|
--volume="${CITUS_VOLUME_NAME}:/var/lib/postgresql/data" \
|
|
|
|
--env=POSTGRES_PASSWORD="$CITUS_PASSWORD" \
|
|
|
|
--detach \
|
2023-05-04 14:38:31 +03:00
|
|
|
citusdata/citus:11.3.0
|
2021-04-08 18:02:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2022-08-04 13:08:54 +03:00
|
|
|
function citus_cleanup {
|
2021-04-08 18:02:56 +03:00
|
|
|
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"
|
2022-08-04 13:08:54 +03:00
|
|
|
docker volume rm "$CITUS_VOLUME_NAME"
|
2021-04-08 18:02:56 +03:00
|
|
|
}
|