Skip to content

Commit

Permalink
Merge pull request #65 from jaysh/jaysh-dynamic-gateway-ip
Browse files Browse the repository at this point in the history
Remove the assumption that 172.17.42.1 is always the gateway IP.
  • Loading branch information
Kloadut committed Feb 20, 2015
2 parents 8c00975 + 042fb76 commit 35edfeb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions commands
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ function get_postgresql_id() {
echo $ID
}

function get_postgresql_ip() {
ID=$(get_postgresql_id)
IP=$(docker inspect --format '{{ .NetworkSettings.Gateway }}' $ID)
echo $IP
}

function get_postgresql_port() {
ID=$(get_postgresql_id)
PORT=$(docker port "$ID" 5432 | sed 's/0.0.0.0://')
Expand All @@ -52,9 +58,10 @@ function get_postgresql_port() {

function connect_to_db() {
export PGPASSWORD=$(cat "$DOKKU_ROOT/.postgresql/pwd_$APP")
IP=$(get_postgresql_ip)
PORT=$(get_postgresql_port)

psql -h 172.17.42.1 -p $PORT -U root db
psql -h $IP -p $PORT -U root db
}

case "$1" in
Expand Down Expand Up @@ -143,9 +150,10 @@ case "$1" in
check_postgresql_container
check_postgresql_tool pg_dump
export PGPASSWORD=$(cat "$DOKKU_ROOT/.postgresql/pwd_$APP")
IP=$(get_postgresql_ip)
PORT=$(get_postgresql_port)

pg_dump -h 172.17.42.1 -p $PORT -U root -c -O db
pg_dump -h $IP -p $PORT -U root -c -O db

# echo to stderr, as stdout will probably be redirected to a file
echo 1>&2
Expand All @@ -155,16 +163,17 @@ case "$1" in
postgresql:info)
check_postgresql_container
DB_PASSWORD=$(cat "$DOKKU_ROOT/.postgresql/pwd_$APP")
IP=$(get_postgresql_ip)
PORT=$(get_postgresql_port)

echo
echo " Host: 172.17.42.1"
echo " Host: $IP"
echo " Port: $PORT"
echo " User: 'root'"
echo " Password: '$DB_PASSWORD'"
echo " Database: 'db'"
echo
echo " Url: 'postgres://root:$DB_PASSWORD@172.17.42.1:$PORT/db'"
echo " Url: 'postgres://root:$DB_PASSWORD@$IP:$PORT/db'"
echo
;;

Expand All @@ -181,9 +190,10 @@ case "$1" in
exit 1
fi
DB_PASSWORD=$(cat "$DOKKU_ROOT/.postgresql/pwd_$3")
IP=$(get_postgresql_ip)
PORT=$(get_postgresql_port)
# Link database using dokku command
dokku config:set $APP "DATABASE_URL=postgres://root:$DB_PASSWORD@172.17.42.1:$PORT/db"
dokku config:set $APP "DATABASE_URL=postgres://root:$DB_PASSWORD@$IP:$PORT/db"
echo
echo "-----> $APP linked to $DB_IMAGE database"
fi
Expand Down

0 comments on commit 35edfeb

Please sign in to comment.