From a73ea6a8b5e87868aa8fcea9607935353f8e73ec Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Tue, 24 Mar 2015 18:11:56 +0000 Subject: [PATCH 1/3] Extend credintials.json from environment --- README.md | 20 +++++++++++- lib/config.js | 31 ++++++++++++++++--- ....example.json => credentials.default.json} | 2 +- 3 files changed, 47 insertions(+), 6 deletions(-) rename lib/{credentials.example.json => credentials.default.json} (95%) diff --git a/README.md b/README.md index 86d71681..bb50b805 100644 --- a/README.md +++ b/README.md @@ -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,24 @@ 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 -------------------- diff --git a/lib/config.js b/lib/config.js index dceb3385..15338ec1 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,14 +1,37 @@ -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; +} + +console.log(exports.credentials) + exports.version = require('../package.json').version; exports.hash = 'dirty'; exports.production = process.env.NODE_ENV == "production"; diff --git a/lib/credentials.example.json b/lib/credentials.default.json similarity index 95% rename from lib/credentials.example.json rename to lib/credentials.default.json index 030c455a..aa284827 100644 --- a/lib/credentials.example.json +++ b/lib/credentials.default.json @@ -17,5 +17,5 @@ "auto_reconnect": true } }, - "port": 3000 + "port": 80 } \ No newline at end of file From ae49f542ba3780a34760827abcac5b98279ecea8 Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Tue, 24 Mar 2015 18:17:18 +0000 Subject: [PATCH 2/3] fix readme table --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index bb50b805..6eeeafa8 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,8 @@ 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` | @@ -58,7 +57,6 @@ Use these variables to override the config. | SMTP_USER | Mandrill smtp username | | | SMTP_PASS | Mandrill smtp password | | | MONGODB_URL | Mongodb URL | `mongodb://127.0.0.1/semaphore` | -+---------------+------------------------+---------------------------------+ Note to Ansible guys -------------------- From de773d99cd3cd844feffb1093992446d8fe83e4f Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Tue, 24 Mar 2015 18:18:26 +0000 Subject: [PATCH 3/3] Remove extraneous console.log --- lib/config.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/config.js b/lib/config.js index 15338ec1..8374da2f 100644 --- a/lib/config.js +++ b/lib/config.js @@ -30,8 +30,6 @@ if (env.MONGODB_URL) { exports.credentials.db = env.MONGODB_URL; } -console.log(exports.credentials) - exports.version = require('../package.json').version; exports.hash = 'dirty'; exports.production = process.env.NODE_ENV == "production";