Skip to content

Commit

Permalink
Read properties from the environment.
Browse files Browse the repository at this point in the history
Although this is generally discouraged, it is the recommended practice for production configuration for Heroku deployed applications.  This will enable an application to be deployed to Heroku without any code change from the local setup, or deployment setup on other environments.
  • Loading branch information
robb1e committed Mar 24, 2012
1 parent 70ec330 commit d80b421
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -89,6 +89,10 @@ or version control, according to their variety:
These properties are provided by a war resource usually located at
`/conf/global.properties`.

8. _Environment properties_: Properties which are defined at the operating system level.
These should not be used unless required by deployment in a restrictive hosting
environment, i.e. Heroku.


Only properties of types 3 through 7 should be provided to applications. They
should be sourced as specified, first property definition wins, in the order
Expand Down Expand Up @@ -275,5 +279,7 @@ And result in a `conf.toString` with contents:

# Properties from classpath:conf/global.properties

# Properties from System

Note that nonactive `datasource.connection.timeout.ms` from `global.properties`
is not reported.
Expand Up @@ -35,7 +35,8 @@ private[conf] class GuardianConfigurationStrategy(
getOperationsProperties(applicationName),
getDeveloperStageBasedProperties(webappConfDirectory),
getDeveloperServiceDomainBasedProperties(webappConfDirectory),
getDeveloperCommonProperties(webappConfDirectory))
getDeveloperCommonProperties(webappConfDirectory),
getSystemProperties)

val placeholderProcessed = new PlaceholderProcessingConfiguration(properties)

Expand Down Expand Up @@ -91,4 +92,9 @@ private[conf] class GuardianConfigurationStrategy(

new PropertiesBasedConfiguration(location, properties)
}

def getSystemProperties = {
LOG.info("Loading system properties")
new PropertiesBasedConfiguration("System", System.getProperties())
}
}
Expand Up @@ -93,15 +93,15 @@ class GuardianConfigurationStrategyTest extends FunSuite with ShouldMatchers wit
configuration.hasProperty("stage") should be(false)
}

test("should not override properties with system properties if defined") {
test("should contain properties from system") {
try {
System.setProperty("source", "system.override.property")
System.setProperty("random.system.property", "meh")

val configuration = strategy.getConfiguration("webapp", "conf")

configuration("source") should be("developer.account.override.properties")
configuration.hasProperty("random.system.property") should be(false)
configuration.hasProperty("random.system.property") should be(true)
} finally {
System.clearProperty("source")
System.clearProperty("random.system.property")
Expand Down Expand Up @@ -172,6 +172,9 @@ class GuardianConfigurationStrategyTest extends FunSuite with ShouldMatchers wit
"\n" +
"# Properties from classpath:conf/global.properties\n" +
"developer.common.properties=available\n" +
"\n" +
"# Properties from System\n" +
"user.home=" + System.getProperty("user.home") + "\n" +
"\n")

System.setProperties(system)
Expand Down

0 comments on commit d80b421

Please sign in to comment.