deis / helloworld

A hello world app, written in Go.
MIT License
10 stars 31 forks source link

application dev question #4

Closed iansmith closed 8 years ago

iansmith commented 9 years ago

I'm not sure where this question should go but I'll try here.

I've got some go demo applications running on my deis cluster in AWS. They work fine with the "herokuish" workflow. That's going great.

I understand that I should be setting my DATABASE_URL var on the applications to tell them how to reach the database. In fact, I have this working fine for development on my local workstation.

My question is two fold: One, how does one decide what the DATABASE_URL should be for the deis deployment? I noticed some likely looking keys in etcd but clearly my app shouldn't be groping through etcd, it should be configured "from the outside" into an env var, right? How do I know what that value should be? deisctl list shows a database server running, but I'm not sure how to pick the DATABASE_URL to point at it.

Related to this: I have an sql provisioning script that needs to run before the applications are turned on. I looked at running a command through deis run but that seems to want to run something inside one of my app containers, which isn't really what I want. I'd like to do something like heroku run bash and then quest use psql from the command line. (PS: I guess this heroku pg:connect or something similar.) I suppose I could build a separate container and deploy that with psql and a copy of my provisioning sql in it but that brings us back to the issue of how to set the DATABASE_URL so it can point at the postgres instance?

Final part: Is there a way to do "sudo -u postgres createdb foo". I sshed to the cluster, found the machine that was running postgres and noticed this in the ps list:

root      2786  0.0  0.0  43000  3148 ?        S    Jan04   0:00 sudo -i -u postgres /usr/lib/postgresql/9.3/bin/postgres -c config-file=/etc/postgresql/9.3/main/postgresql.conf -c listen-addresses=*

But if I try to do sudo -u postgres (either as root or core) it says

sudo: unknown user: postgres
sudo: unable to initialize policy plugin

Any help would be appreciated. Thanks. ian

bacongobbler commented 9 years ago

Hi @iansmith. Let me try to break this post down:

My question is two fold: One, how does one decide what the DATABASE_URL should be for the deis deployment?

In terms of the 12 factor model, DATABASE_URL is an environment variable used to connect to an external database. For example, if you have a postgres database set up internally at 192.168.1.100 with user:password as your credentials and dbname as your database name, most languages support the following format as the URI to a postgres database: postgres://user:pass@192.168.1.100/dbname. More info at https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java

The second part of your question seems to be how you can connect to Deis' internal database. The short answer to that is you shouldn't (the database and any other platform components really should not be shared with applications should a malicious user decide to go ahead and destroy the deis database), however you can find out all of the database information/credentials through etcd via /deis/database/host, /deis/database/port etc. You would then configure your app to use this via deis config:set DATABASE_URL=....

Final part: Is there a way to do "sudo -u postgres createdb foo".

Yes. The database is running inside a docker container, so you'd need to throw yourself into the container instead of the host:

$ docker exec -it deis-database bash
$ su postgres
$ pqsl
$ CREATE DATABASE foo;

In the future, please feel free to post these questions over to our mailing list, and if you have any issues then please feel free to drop by at deis/deis.

Thanks!