Cloud Foundry advocates the 12 Factor App approach of storing config in the environment; and provides good tooling to support this:
- cf set-env sets ENV variables at a deployed app level
cf create-service user-provided
sets ENV variables at the space level, making them shared between all apps
Whilst supported, using ENV variables in Windows & .NET apps is uncommon. Config stored in XML .Config
files is more the norm, and integrated into the framework and tooling.
AppHarbor has an elegant way of solving this, where AppSettings are overwritten during the staging process by ENV variables of the same name.
You can set configuration variables for your application. When you add a configuration variable, we'll look for the key in any config file's AppSettings section and replace or add the value with the one defined on AppHarbor when your application is released.
This is similar to the autoconfiguration done by the java-buildpack.
This feature works as follows:
Your {App|Web}.Config
should contain your development settings, eg
<configuration>
<appSettings>
<add key="PORT" value="1234" />
</appSettings>
</configuration>
With your code using the standard ConfigurationManager.AppSettings["PORT"]
technique of loading configuration values.
At development time, you use the (test) config values committed to your repo in the App.Settings
file.
When deploying to Cloud Foundry, any *.config
files are rewritten such that any key in any config file's AppSettings section is replaced with the value of the matching CF runtime ENV variable.
Thus, at run time you would effectively have a *.config
that had been rewritten to the following:
<configuration>
<appSettings>
<add key="PORT" value="61245" />
</appSettings>
</configuration>
Since ENV['PORT']
== 61245