mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-06-26 00:50:49 +00:00
Update postgres script.
This commit is contained in:
parent
5ca51e11d5
commit
734b490e03
|
@ -3,7 +3,7 @@ set -x
|
|||
set -eo pipefail
|
||||
|
||||
# Check if a custom user has been set, otherwise default to 'postgres'
|
||||
DB_USER=${POSTGRES_USER:=postgres}
|
||||
DB_USER="${POSTGRES_USER:=postgres}"
|
||||
# Check if a custom password has been set, otherwise default to 'password'
|
||||
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
|
||||
# Check if a custom password has been set, otherwise default to 'newsletter'
|
||||
|
@ -16,6 +16,13 @@ DB_HOST="${POSTGRES_HOST:=localhost}"
|
|||
# Allow to skip Docker if a dockerized Postgres database is already running
|
||||
if [[ -z "${SKIP_DOCKER}" ]]
|
||||
then
|
||||
# if a postgres container is running, print instructions to kill it and exit
|
||||
RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}')
|
||||
if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then
|
||||
echo >&2 "there is a postgres container already running, kill it with"
|
||||
echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}"
|
||||
exit 1
|
||||
fi
|
||||
# Launch postgres using Docker
|
||||
docker run \
|
||||
-e POSTGRES_USER=${DB_USER} \
|
||||
|
@ -23,6 +30,7 @@ then
|
|||
-e POSTGRES_DB=${DB_NAME} \
|
||||
-p "${DB_PORT}":5432 \
|
||||
-d postgres \
|
||||
--name "postgres_$(date '+%s')" \
|
||||
postgres -N 1000
|
||||
# ^ Increased maximum number of connections for testing purposes
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue