diff --git a/README.md b/README.md index df20416..0cebb10 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ dokku postgres:info lolipop # you can also retrieve a specific piece of service info via flags dokku postgres:info lolipop --data-dir dokku postgres:info lolipop --dsn +dokku postgres:info lolipop --external-dsn dokku postgres:info lolipop --exposed-ports dokku postgres:info lolipop --id dokku postgres:info lolipop --internal-ip @@ -265,6 +266,27 @@ The `import` command should be used with any non-plain-text files exported by `p dokku postgres:connect db < ./dump.sql ``` +## External DSN + +```shell +# expose the database +dokku postgres:expose lolipop + +# external dsn available on service info +dokku postgres:info lolipop +=====> Container Information + ... + External dsn: postgres://postgres:SOME_PASSWORD@dokku.me:28804/lolipop + Exposed ports: 5432->28804 + ... +``` + +So now you connect to your database with [`pgcli`](https://www.pgcli.com/) or with your favorite app. + +```shell +pgcli $(ssh dokku@dokku.me postgres:info lolipop --external-dsn) +``` + ## Security The connection to the database is done over SSL. A self-signed certificate is diff --git a/common-functions b/common-functions index f2a9716..884b0b2 100755 --- a/common-functions +++ b/common-functions @@ -332,6 +332,7 @@ service_info() { declare SERVICE="$1" INFO_FLAG="$2" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local SERVICE_URL=$(service_url "$SERVICE") + local SERVICE_EXTERNAL_URL=$(service_external_url "$SERVICE") local PORT_FILE="$SERVICE_ROOT/PORT" local SERVICE_CONTAINER_ID="$(cat "$SERVICE_ROOT/ID")" local flag key valid_flags @@ -340,6 +341,7 @@ service_info() { "--config-dir: ${SERVICE_ROOT}/config" "--data-dir: ${SERVICE_ROOT}/data" "--dsn: ${SERVICE_URL}" + "--external-dsn: ${SERVICE_EXTERNAL_URL}" "--exposed-ports: $(service_exposed_ports "$SERVICE")" "--id: ${SERVICE_CONTAINER_ID}" "--internal-ip: $(get_container_ip "${SERVICE_CONTAINER_ID}")" diff --git a/functions b/functions index 71f4150..ad7cc9b 100755 --- a/functions +++ b/functions @@ -152,3 +152,18 @@ service_url() { local SERVICE_DNS_HOSTNAME="$(service_dns_hostname "$SERVICE")" echo "$PLUGIN_SCHEME://postgres:$PASSWORD@$SERVICE_DNS_HOSTNAME:${PLUGIN_DATASTORE_PORTS[0]}/$DATABASE_NAME" } + +service_external_url() { + local SERVICE="$1" + local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + local PORT_FILE="$SERVICE_ROOT/PORT" + [[ ! -f $PORT_FILE ]] && echo '-' && return 0 + local GLOBAL_VHOST_FILE="$DOKKU_ROOT/VHOST" + [[ ! -f $GLOBAL_VHOST_FILE ]] && echo '-' && return 0 + + local PORTS=($(cat "$PORT_FILE")) + local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")" + local DATABASE_NAME="$(get_database_name "$SERVICE")" + local GLOBAL_VHOSTS=($(cat "$GLOBAL_VHOST_FILE")) + echo "$PLUGIN_SCHEME://postgres:$PASSWORD@${GLOBAL_VHOSTS[0]}:${PORTS[0]}/$DATABASE_NAME" +} diff --git a/subcommands/info b/subcommands/info index e76da83..60bbbf0 100755 --- a/subcommands/info +++ b/subcommands/info @@ -11,6 +11,7 @@ service-info-cmd() { #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --config-dir #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --data-dir #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --dsn + #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --external-dsn #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --exposed-ports #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --id #E dokku $PLUGIN_COMMAND_PREFIX:info lolipop --internal-ip @@ -22,6 +23,7 @@ service-info-cmd() { #F --config-dir, show the service configuration directory #F --data-dir, show the service data directory #F --dsn, show the service DSN + #F --external-dsn, show the exposed service DSN (you must expose the service first) #F --exposed-ports, show service exposed ports #F --id, show the service container id #F --internal-ip, show the service internal ip diff --git a/tests/service_info.bats b/tests/service_info.bats index 980d6a8..c8f0d51 100755 --- a/tests/service_info.bats +++ b/tests/service_info.bats @@ -47,6 +47,9 @@ teardown() { run dokku "$PLUGIN_COMMAND_PREFIX:info" l --dsn assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:info" l --external-dsn + assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:info" l --exposed-ports assert_success