storj/scripts/postgres-dev.sh
Michal Niewrzal fb2711d05e scripts: update postgres helper script to set password
Latest postgres docker image requires non empty password.

Change-Id: I03017e1b7ff4803fefc24c39087d9ccd4042373b
2020-02-27 10:33:37 +00:00

25 lines
858 B
Bash
Executable File

#!/usr/bin/env bash
LOG_FILE=${STORJ_SIM_POSTGRES_LOG:-"storj-sim-postgres.log"}
CONTAINER_NAME=storj_sim_postgres
cleanup(){
docker rm -f $CONTAINER_NAME
}
trap cleanup EXIT
docker run --rm -d -p 5433:5432 --name $CONTAINER_NAME -e POSTGRES_PASSWORD=tmppass postgres:9.6 -c log_min_duration_statement=0
docker logs -f $CONTAINER_NAME > $LOG_FILE 2>&1 &
STORJ_SIM_DATABASE=${STORJ_SIM_DATABASE:-"teststorj"}
RETRIES=10
until docker exec $CONTAINER_NAME psql -h localhost -U postgres -d postgres -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do
echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
sleep 1
done
docker exec $CONTAINER_NAME psql -h localhost -U postgres -c "create database $STORJ_SIM_DATABASE;"
export STORJ_SIM_POSTGRES="postgres://postgres:tmppass@localhost:5433/$STORJ_SIM_DATABASE?sslmode=disable"