Skip to content

Commit 7746ad1

Browse files
committed
run-pgcli script now accepts DB_URL based arguments
1 parent 7e38f3d commit 7746ad1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ MAINTAINER Dennis Coldwell <dennis.coldwell@gmail.com>
33
RUN apt-get -y update && apt-get -y install libpq-dev build-essential
44
RUN pip install pgcli==0.20.1
55
ADD run-pgcli.sh /bin/run-pgcli.sh
6-
CMD ["run-pgcli.sh"]
6+
ENTRYPOINT ["run-pgcli.sh"]
77

run-pgcli.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
# Simple wrapper for the pgli tool. This script allows us to pull in linked
44
# docker containers if the user decides to bring up the cli that way.
55

6-
if [ -z ${POSTGRES_PORT_5432_TCP_ADDR+x} ]; then
7-
# POSTGRES linked variables aren't set, just call pgcli without params
8-
pgcli
9-
else
6+
db_url=$1
7+
8+
if [ -n "$db_url" ]; then
9+
# 1st priority goes to any argument passed to the script
10+
pgcli "$db_url"
11+
elif [ -n "$DB_URL" ]; then
12+
# next, if a DB_URL environment variable is set, use that
13+
pgcli "$DB_URL"
14+
elif [ -n "$POSTGRES_PORT_5432_TCP_ADDR" ]; then
15+
# if nothing is set, we try to construct a db_url from the env vars that docker
16+
# automatically sets for the postgres container
1017
pgcli postgres://$POSTGRES_ENV_POSTGRES_USER:$POSTGRES_ENV_POSTGRES_PASSWORD@$POSTGRES_PORT_5432_TCP_ADDR:$POSTGRES_PORT_5432_TCP_PORT
18+
else
19+
echo "Database URL not provided, please try again."
1120
fi
1221

0 commit comments

Comments
 (0)