Skip to content

Commit

Permalink
Add --exposed-dsn option for postgres:info
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Dec 1, 2018
1 parent 98edfb9 commit 3cb5b59
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:[email protected]: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 [email protected] postgres:info lolipop --exposed-dsn)
```

## Security

The connection to the database is done over SSL. A self-signed certificate is
Expand Down
1 change: 1 addition & 0 deletions common-functions
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,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}")"
Expand Down
15 changes: 15 additions & 0 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -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_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"
}
2 changes: 2 additions & 0 deletions subcommands/info
Original file line number Diff line number Diff line change
Expand Up @@ -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 --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
Expand All @@ -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 --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
Expand Down
3 changes: 3 additions & 0 deletions tests/service_info.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3cb5b59

Please sign in to comment.