dokku/dokku-rethinkdb

Connecting to dokku-rethinkdb

aleclarson opened this issue · 12 comments

Using dokku config:get my-app RETHINKDB_URL
returns rethinkdb://dokku-rethinkdb-foo:28015/my-app
but how should I pass that to the driver?

The following code fails to connect:

const rethinkdb = require('rethinkdb')
const r = rethinkdb({
  host: 'rethinkdb://dokku-rethinkdb-foo/foo',
})

Here's the error:

Failed to connect to rethinkdb://dokku-rethinkdb-foo/foo:28015

I also tried host: 'rethinkdb://dokku-rethinkdb-foo:28015/foo' but it did not work.

If your driver doesn't understand how to read a DSN, then you'll need to parse the DSN and set the properties manually.

Surprisingly, neither the official Javascript driver, nor neumino/rethinkdbdash support such a thing.

It doesn't seem like my app container has access to rethinkdb.

Here's what I did:

dokku apps:create my-app
dokku rethinkdb:create foo
dokku rethinkdb:link foo my-app
dokku enter my-app
node
> var socket = net.connect('rethinkdb://dokku-rethinkdb-foo:28015/foo');
> Error: connect ENOENT rethinkdb://dokku-rethinkdb-foo:28015/foo

And dokku rethinkdb:info foo returns:

=====> Container Information
       Config dir:          /var/lib/dokku/services/rethinkdb/foo/config
       Data dir:            /var/lib/dokku/services/rethinkdb/foo/data
       Dsn:                 rethinkdb://dokku-rethinkdb-foo:28015/foo
       Exposed ports:       28015->2937 29015->17420 8080->11337 
       Id:                  bd03ee2c4efe00d8ab06b6c2551811f20cc7362b49f979a162a349ca689a33fd
       Internal ip:         172.17.0.2               
       Links:               my-app                    
       Service root:        /var/lib/dokku/services/rethinkdb/foo
       Status:              running                  
       Version:             rethinkdb:2.3.5

Is there anything I can do to test this connection outside of node?

Using curl http://172.17.0.2:8080, I've confirmed that my container can access rethinkdb.

I'm still interested in why the DSN can't be connected to.

Is it reliable to hard code the internal IP into my application?

Found a way to convert dokku-rethinkdb-foo into 172.17.0.2:

dns.lookup('dokku-rethinkdb-foo', function(error, host) {
  console.log(host); // '172.17.0.2'
})

I guess that will have to do for now.

Hmm, still cannot connect.

var socket = net.connect('http://172.17.0.2:28015/foo');
// Error: connect ENOENT http://172.17.0.2:28015/foo

Btw, I can guarantee net.connect is the right method of connecting, since that's what the official RethinkDB driver uses.

Okay, I can get it connected to http://172.17.0.2:28015 like so:

var socket = net.connect('28015', '172.17.0.2');

Now is it necessary to connect to /foo, or am I allowed to leave that out?
If it's required, I'm not sure how to do that. Can't find anything on Google.

Hmm, the RethinkDB driver seems to be working, despite connecting to http://172.17.0.2:28015 (without the /foo part).

So I guess it's not required? Wasted a lot of time thinking it was required. 😢

my-app would be your "database" or whatever rethinkdb calls that.

Oh okay. It doesn't look like it's working correctly.

Using dbList in the web UI says there's no foo database.

r.dbList().run()
// [
//   "rethinkdb" ,
//   "test"
// ]

@josegonzalez Have you looked into why the foo database is not being created as expected?

I'm assuming dokku-rethinkdb never supported such a thing. AFAIK, it would require the Python client driver. Does this repo use that at all?

Guess we don't create the database. You can file an issue for that, seems we can do it via rql as shown here.

I likely won't work on the issue since I don't use rethinkdb, but if you'd like to contribute that enhancement, that would be wonderful.