Skip to content

Commit

Permalink
Allow config.json to supply environment variables as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Standard8 committed Nov 19, 2013
1 parent 0e00fbb commit f6dd483
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions users/app/post-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,47 @@ temp.mkdir('deploy', function(err, newCodeDir) {
commands.push([ 'move new code into place', 'mv ' + newCodeDir + ' ' + codeDir ]);

runNextCommand(function() {
updateEnv();
updateEnvAwsBox();
});
}

function updateEnv() {
// now update the environment with what's in the config file
if (awsboxJson.env) {
var eKeys = Object.keys(awsboxJson.env);

console.log(">> setting env vars from .awsbox.json:", eKeys.join(", "));

function setNext() {
if (!eKeys.length) postDeploy();
else {
var k = eKeys.shift();
child_process.exec(
'echo "' + awsboxJson.env[k] + '"',
function(error, so, se) {
checkErr('while setting ENV var ' + k, error);
process.env[k] = so.toString().trim();
setNext();
});
}
function updateEnv(env, next) {
var eKeys = Object.keys(env);
console.log("Env vars:", eKeys.join(", "));

function setNext() {
if (!eKeys.length) next();
else {
var k = eKeys.shift();
child_process.exec(
'echo "' + env[k] + '"',
function(error, so, se) {
checkErr('while setting ENV var ' + k, error);
process.env[k] = so.toString().trim();
setNext();
});
}
setNext()
}
setNext();
}

function updateEnvAwsBox() {
// now update the environment with what's in the config files
if (awsboxJson.env) {
console.log(">> setting env vars from .awsbox.json...");

updateEnv(awsboxJson.env, updateEnvAppConfig);
} else {
updateEnvAppConfig();
}
}

function updateEnvAppConfig() {
// now update the environment with what's in the config files
if (appconfig.env) {
console.log(">> setting env vars from config.json...");

updateEnv(appconfig.env, postDeploy);
} else {
postDeploy();
}
Expand Down

0 comments on commit f6dd483

Please sign in to comment.