Setting datasources and configs using ENV variables

This seemingly mild mannered commit is full of all kinds of galactic, amazeballs :boom: :boom: :boom:

Add this to your ./www/farcryConstructor.cfm:

<cfset THIS.bUseEnv = true>

Then you can configure datasources (and any config) directly via environment variables.

For example, a mySQL database

FARCRY_DSN: "chelsea",
FARCRY_DBTYPE: "mysql",
FARCRY_DSN_CLASS: "org.gjt.mm.mysql.Driver",
FARCRY_DSN_CONNECTIONSTRING: "jdbc:mysql://192.168.33.9:3306/chelsea?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useLegacyDatetimeCode=true",
FARCRY_DSN_USERNAME: "vagrant",
FARCRY_DSN_PASSWORD: "vagrant"

For example, an H2 database

FARCRY_DSN: "chelsea",
FARCRY_DBTYPE: "h2",
FARCRY_DSN_CLASS: "org.h2.Driver",
FARCRY_DSN_CONNECTIONSTRING: "jdbc:h2:chelsea/chelsea;MODE=MySQL",
FARCRY_DSN_USERNAME: "vagrant",
FARCRY_DSN_PASSWORD: "vagrant"

Why do this? Well imagine you are running everything in Docker containers :whale: and you want to have your application auto-magically configure itself for the dev or production environments.

2 Likes

If you have a hankering to see this in action, you should be able to vagrant up this project and have a sticky beak :bird:

For Example, an MSSQL Database

FARCRY_DSN: "my_db_name",
FARCRY_DBTYPE: "mssql2005",
FARCRY_DSN_CLASS: "com.microsoft.jdbc.sqlserver.SQLServerDriver",
FARCRY_DSN_CONNECTIONSTRING: "jdbc:sqlserver://192.168.1.9:1433;DATABASENAME=my_db_name;sendStringParametersAsUnicode=true;SelectMethod=direct",
FARCRY_DSN_USERNAME: "sa",
FARCRY_DSN_PASSWORD: "very_strong_password"
1 Like

Forgot to mention you can also configure any standard FarCry config in the same way. For example, if you wanted to configure your app’s memcached plugin:

FARCRY_CONFIG_MEMCACHED_SERVERS: "cache:11211"