dotcloud provides lots of useful information as environment variables but my nginx.conf cannot access environment variables. What's a good way around this?
Here's the scenario: I'd like to redirect certain URLs from my www static service to my rest service, so I'm currently hardcoding the target URL into nginx.conf. I'd rather use the DOTCLOUD_REST_HTTP_HOST variable since that would allow my service to easily migrate.
This is a good case for using the
postinstallscript for your service. dotCloud provides build hooks for running at each stage of the push and deploy cycle, and thepostinstallhook runs last, where it has access to all your environment variables. You could read the variables from~/environment.jsonor from the actual environment (the file is slightly more dependable, since what gets put into the environment may vary by service type, for historical reasons).Here is an example
dotcloud.yml:and an example
nginx.conf(found in www/nginx.conf):and finally, the example
postinstall(found in www/postinstall) where read the value of $LIMITRATEVAR out of the environment and update nginx.conf withsed: