Best Way to Provide Config Variables
Marco Ceppi
marco.ceppi at canonical.com
Sat Nov 9 03:22:45 UTC 2013
What you're describing is exactly what relations in charms, possibly even
juju itself, was designed to do! The MySQL charm describes in it's
metadata.yaml file several interfaces that it knows how to "talk" on. One
of those interfaces is named "mysql" and it's designed to provide it's
connection information (as well as create unique user credentials, a
database, etc) to connected services. There's a preliminary document on how
to implement the MySQL relation in to your charm. By doing so you'll be
able to deploy MySQL, relate it to your charm, and have the charm create
the configuration for you. Information on interfaces:
https://juju.ubuntu.com/docs/authors-charm-interfaces.html. We're working
on documenting interfaces, in fact there's a draft for the MySQL doc, but
for the most part in your relation-changed hook you'll want to relation-get
the following keys:
host
user
password
database
A simple example of this can be seen in our "getting started" charm
Vanilla. Here's the db-relation-changed for that charm:
http://manage.jujucharms.com/~marcoceppi/precise/vanilla/hooks/database-relation-changed
Here's some additional resources:
- https://juju.ubuntu.com/docs/authors-charm-writing.html#step04
- https://juju.ubuntu.com/docs/authors-relations-in-depth.html
- https://juju.ubuntu.com/docs/authors-hook-environment.html
Thanks,
Marco Ceppi
On Fri, Nov 8, 2013 at 8:30 PM, Jason Hamilton <jasonscotthamilton at gmail.com
> wrote:
> So I want to provide the MySQL charm database connection info to software
> in my charm. Let's say for example, I want to provide a PHP program inside
> my charm with the MySQL database info.
>
> I was thinking the best way would be through environment variables. This
> is what Heroku + Elastic Beanstalk does for Python apps and it is also
> promoted here http://12factor.net/config. The other option I was
> thinking was putting them in a text or config file. This is how the
> current LAMP charm does it. This latter option seems like more work for
> the developer but would support the ideas here:
> http://peterlyons.com/problog/2010/02/environment-variables-considered-harmful
> .
>
> I am leaning towards environment variables but would like some feedback on
> the best practice. Maybe there is a better method that I have not even
> thought of?
>
> Jason
>
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20131108/2dacc3f5/attachment.html>
More information about the Juju
mailing list