diff --git a/README.md b/README.md index 781a068..aaecd60 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 --exposed-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 ``` +## Exposed DSN + +```shell +# expose the database (you must open the exposed port on your firewall if you have one) +dokku postgres:expose lolipop + +# exposed dsn available on service info +dokku postgres:info lolipop +=====> Container Information + ... + Exposed 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 --exposed-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 eff86b3..7e7d444 100755 --- a/common-functions +++ b/common-functions @@ -385,6 +385,7 @@ service_info() { "--config-dir: ${SERVICE_ROOT}/config" "--data-dir: ${SERVICE_ROOT}/data" "--dsn: ${SERVICE_URL}" + "--exposed-dsn: $(service_exposed_url "$SERVICE")" "--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 42a4bfa..06a4906 100755 --- a/functions +++ b/functions @@ -158,3 +158,18 @@ service_url() { local PASSWORD="$(service_password "$SERVICE")" echo "$PLUGIN_SCHEME://postgres:$PASSWORD@$SERVICE_DNS_HOSTNAME:${PLUGIN_DATASTORE_PORTS[0]}/$DATABASE_NAME" } + +service_exposed_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 21dfd4a..b726639 100755 --- a/subcommands/info +++ b/subcommands/info @@ -12,6 +12,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 --exposed-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 @@ -23,6 +24,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 --exposed-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 77ffb87..3ce2e0e 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 --exposed-dsn + assert_success + run dokku "$PLUGIN_COMMAND_PREFIX:info" l --exposed-ports assert_success