Merge pull request #9 from ansible-semaphore/feature/env-variables

Extend credintials.json from environment
This commit is contained in:
Alan Campbell 2015-03-24 14:19:10 -04:00
commit d170d8df3c
3 changed files with 43 additions and 6 deletions

View File

@ -30,7 +30,7 @@ Install requirements:
- mongodb & redis
- Sudo access (this might change). To run jobs, this tool writes private keys to /root/.ssh and copies playbook directories to /root/.
1. `cp lib/credentials.example.json lib/credentials.json` (<- make custom to your environment)
1. Copy `lib/credentials.default.json` to `lib/credentials.json` and customise, or export relevant environment variables
2. `bower install`
3. `node bin/semaphore`
@ -42,6 +42,22 @@ Email: 'admin@semaphore.local'
Password: 'CastawayLabs'
```
Environment Variables
---------------------
Use these variables to override the config.
| Variable Name | Description | Default Value |
| ------------- | ---------------------- | ------------------------------- |
| PORT | Web Port | `80` |
| REDIS_PORT | Redis Port | `6379` |
| REDIS_HOST | Redis Hostname | `127.0.0.1` |
| REDIS_KEY | Redis auth key | |
| BUGSNAG_KEY | Bugsnag API key | |
| SMTP_USER | Mandrill smtp username | |
| SMTP_PASS | Mandrill smtp password | |
| MONGODB_URL | Mongodb URL | `mongodb://127.0.0.1/semaphore` |
Note to Ansible guys
--------------------

View File

@ -1,14 +1,35 @@
var fs = require('fs');
var fs = require('fs'),
env = process.env;
try {
var credentials = require('./credentials.json')
var credentials = require('./credentials.json');
} catch (e) {
console.log("\nNo credentials.json File!\n")
process.exit(1);
if (!(process.env.MONGODB_URL && process.env.REDIS_HOST)) {
console.log("\nNo credentials.json File or env variables!\n");
process.exit(1);
} else {
credentials = require('./credentials.default.json');
}
}
exports.credentials = credentials;
['redis_port', 'redis_host', 'redis_key', 'bugsnag_key', 'port'].forEach(function (key) {
if (env[key.toUpperCase()]) {
exports.credentials[key] = env[key.toUpperCase()];
}
});
if (env.SMTP_USER) {
exports.credentials.smtp.user = env.SMTP_USER;
}
if (env.SMTP_PASS) {
exports.credentials.smtp.pass = env.SMTP_PASS;
}
if (env.MONGODB_URL) {
exports.credentials.db = env.MONGODB_URL;
}
exports.version = require('../package.json').version;
exports.hash = 'dirty';
exports.production = process.env.NODE_ENV == "production";

View File

@ -17,5 +17,5 @@
"auto_reconnect": true
}
},
"port": 3000
"port": 80
}