From 7746ad14599a9dbc1dd1635d3008875788f77da9 Mon Sep 17 00:00:00 2001 From: Dennis Coldwell Date: Sat, 5 Dec 2015 22:58:27 -0800 Subject: [PATCH] run-pgcli script now accepts DB_URL based arguments --- Dockerfile | 2 +- run-pgcli.sh | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab8c2a6..4da14c6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,5 +3,5 @@ MAINTAINER Dennis Coldwell RUN apt-get -y update && apt-get -y install libpq-dev build-essential RUN pip install pgcli==0.20.1 ADD run-pgcli.sh /bin/run-pgcli.sh -CMD ["run-pgcli.sh"] +ENTRYPOINT ["run-pgcli.sh"] diff --git a/run-pgcli.sh b/run-pgcli.sh index 409e709..c809418 100755 --- a/run-pgcli.sh +++ b/run-pgcli.sh @@ -3,10 +3,19 @@ # Simple wrapper for the pgli tool. This script allows us to pull in linked # docker containers if the user decides to bring up the cli that way. -if [ -z ${POSTGRES_PORT_5432_TCP_ADDR+x} ]; then - # POSTGRES linked variables aren't set, just call pgcli without params - pgcli -else +db_url=$1 + +if [ -n "$db_url" ]; then + # 1st priority goes to any argument passed to the script + pgcli "$db_url" +elif [ -n "$DB_URL" ]; then + # next, if a DB_URL environment variable is set, use that + pgcli "$DB_URL" +elif [ -n "$POSTGRES_PORT_5432_TCP_ADDR" ]; then + # if nothing is set, we try to construct a db_url from the env vars that docker + # automatically sets for the postgres container pgcli postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRES_PASSWORD@$POSTGRES_PORT_5432_TCP_ADDR:$POSTGRES_PORT_5432_TCP_PORT +else + echo "Database URL not provided, please try again." fi