Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exposed DSN option for postgres:info command #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nicolas-brousse
Copy link

I love to use pgcli on my laptop. I use it to log on my heroku databases (pgcli $(heroku config:get DATABASE_URL)). And I would like to be able to do the same on dokku, so I created this PR.

I tested it on one dokku instance and it works correclty. And I'm able to do the following now.

$ pgcli $(ssh [email protected] postgres:info postgres-database --external-dsn)

I'm new in dokku usage, so I don't know all your conventions. Maybe this could not be done for some reason, or you want I do some changes. Let me know 🙂

@nicolas-brousse nicolas-brousse changed the title Add external DSN option for postgres:info Add external DSN option for postgres:info command Nov 20, 2018
@joshmanders
Copy link

joshmanders commented Nov 20, 2018

ssh [email protected] config:get <app> DATABASE_URL

Should work the same way.

@nicolas-brousse
Copy link
Author

$ ssh [email protected] config:get <app> DATABASE_URL

Must returns the same value as ssh [email protected] postgres:info postgres-database --dsn does. In my case it returns the internal DSN. So it's not really the same.

functions Outdated
local PORTS=($(cat "$PORT_FILE"))
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
local DATABASE_NAME="$(get_database_name "$SERVICE")"
local GLOBAL_VHOST_PATH="$DOKKU_ROOT/VHOST"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this file does not exist?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I missed it. Thanks for the point

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some changes here too.

local PORT_FILE="$SERVICE_ROOT/PORT"
[[ ! -f $PORT_FILE ]] && echo '-' && return 0

local PORTS=($(cat "$PORT_FILE"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This port may not be exposed to the public, so this external dsn would fail to work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "This port may not be exposed to the public"?

You mean because of a firewall for example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The port is by default only on the internal ip address. You'd need to call SERVICE:expose on the service (with the port you want to map it to specified) and only then would this code work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe I missed some explanation. I currently run ssh [email protected] postgres:expose postgres-database before pgcli $(ssh [email protected] postgres:info postgres-database --external-dsn). If not External dsn returns - as Exposed ports do.

$ ssh [email protected] postgres:info postgres-database          
=====> Container Information
       Config dir:          /var/lib/dokku/services/postgres/postgres-database/config
       Data dir:            /var/lib/dokku/services/postgres/postgres-database/data
       Dsn:                 postgres://postgres:xxxxxxxxxxxx@dokku-postgres-postgres-database:5432/postgres_database
       External dsn:        -                        
       Exposed ports:       -                        
       Id:                  9dc918204b5fb0a4b8848a71
       Internal ip:         172.17.0.3               
       Links:               postgres-database       
       Service root:        /var/lib/dokku/services/postgres/postgres-database
       Status:              running                  
       Version:             postgres:10.4  
$ ssh [email protected] postgres:expose postgres-database
$ ssh [email protected] postgres:info postgres-database          
=====> Container Information
       Config dir:          /var/lib/dokku/services/postgres/postgres-database/config
       Data dir:            /var/lib/dokku/services/postgres/postgres-database/data
       Dsn:                 postgres://postgres:xxxxxxxxxxxx@dokku-postgres-postgres-database:5432/postgres_database
       External dsn:        postgres://postgres:[email protected]:28804/postgres_database                        
       Exposed ports:       5432->28804                        
       Id:                  9dc918204b5fb0a4b8848a71
       Internal ip:         172.17.0.3               
       Links:               postgres-database       
       Service root:        /var/lib/dokku/services/postgres/postgres-database
       Status:              running                  
       Version:             postgres:10.4 

Maybe I have to update the README for more explanation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I'm just concerned that if the db is not exposed, then people will get confused and start filing issues about how this doesn't work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll work on updating README and maybe add precision on command help info about the option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do some changes on README and flag description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be empty if the service is not exposed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External dsn: already returns - if the service is not exposed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fine for you?

@nicolas-brousse nicolas-brousse force-pushed the add-external-dsn-option-for-postgres-info-cmd branch 2 times, most recently from a3bffba to 3879ff9 Compare November 29, 2018 22:09
@nicolas-brousse
Copy link
Author

Also I'm not sure about external-dsn as flag name. Should it be exposed-dsn or something else?

@josegonzalez
Copy link
Member

exposed-dsn sounds fine.

@nicolas-brousse
Copy link
Author

I'll rename external-dsn to exposed-dsn so.

@nicolas-brousse nicolas-brousse force-pushed the add-external-dsn-option-for-postgres-info-cmd branch from 3879ff9 to 5f2a81d Compare December 1, 2018 18:53
@nicolas-brousse nicolas-brousse changed the title Add external DSN option for postgres:info command Add exposed DSN option for postgres:info command Dec 1, 2018
@nicolas-brousse nicolas-brousse force-pushed the add-external-dsn-option-for-postgres-info-cmd branch 2 times, most recently from df40c30 to 3cb5b59 Compare December 1, 2018 19:38
@nicolas-brousse
Copy link
Author

Hey josegonzalez. Are you still interested on this changes? I could found time in following weeks to end the work 🙂

@josegonzalez
Copy link
Member

josegonzalez commented Mar 19, 2020

Yes but I'd like this to be in the common-functions, so therefore generic so that we could do this to each database plugin.

@nicolas-brousse
Copy link
Author

nicolas-brousse commented Mar 19, 2020

The thing is like for service_url (that is in functions file too) we do not know the user that should be use to generate the URI.

Do we need to have something like for redis plugin?

https://github.com/dokku/dokku-redis/blob/fb1b189aeac0411226f66e2099560fe2061601e9/functions#L158

Should I move both service_url and service_exposed_url inside common-functions?

@josegonzalez
Copy link
Member

@nicolas-brousse do you mean hostname, not user?

@nicolas-brousse
Copy link
Author

A user that is part of the hostname yes schema://user:password@host.

The connection user (postgres) is not currently contained in a variable.

@josegonzalez
Copy link
Member

Ah I see what you mean. In that case, ignore my comment.

Can you rebase this and provide the same PR to the other database plugins?

@nicolas-brousse
Copy link
Author

Yes sure.

But just to know, I noticed that for redis plugin, there is the variable $SERVICE used. Do you think we could apply the same here?

https://github.com/dokku/dokku-redis/blob/fb1b189aeac0411226f66e2099560fe2061601e9/functions#L154-L159

@josegonzalez
Copy link
Member

Not sure thats always valid for all plugins.

@nicolas-brousse
Copy link
Author

Not sure either. I'll just rebase then, and do the same in other database plugins 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants