Skip to content

Commit

Permalink
run-pgcli script now accepts DB_URL based arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dencold committed Dec 6, 2015
1 parent 7e38f3d commit 7746ad1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ MAINTAINER Dennis Coldwell <dennis.coldwell@gmail.com>
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"]

17 changes: 13 additions & 4 deletions run-pgcli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7746ad1

Please sign in to comment.