Created
December 30, 2013 12:40
-
-
Save nabucosound/8181671 to your computer and use it in GitHub Desktop.
Script to copy environment variables from an existing heroku app to another one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/ | |
set -e | |
sourceApp="$1" | |
targetApp="$2" | |
while read key value; do | |
key=${key%%:} | |
echo "Setting $key=$value" | |
heroku config:set "$key=$value" --app "$targetApp" | |
done < <(heroku config --app "$sourceApp" | sed -e '1d') |
If you have them already in a .env file you can just do this
https://gist.github.com/oscarmorrison/be81140ca8d6afdf9e58667df9849a50
Very Nice , It is very useful .
An interactive script to add multiple config variables reading from a file to the heroku server in one line dynamic options command. https://gist.github.com/md-farhan-memon/e90e30cc0d67d0a0cd7779d6adfe62d1
For those not using bash and have NodeJs:
const { exec } = require("child_process");
const args = process.argv.slice(2);
const sourceApp = args[0];
const targetApp = args[1];
const ignoredKeys = ["DATABASE_URL", "PAPERTRAIL_API_TOKEN"];
exec(`heroku config --app ${sourceApp} --json`, (err, stdout, stderr) => {
if (err) return console.error(`Error: ${stderr}`);
const configVars = JSON.parse(stdout);
ignoredKeys.map((keys) => delete configVars[keys]);
for (const key in configVars) {
const value = configVars[key];
exec(
`heroku config:set ${key}=${value} --app ${targetApp}`,
(err, stdout, stderr) => {
if (err) return console.error(`Error: ${stderr}`);
console.log(`${key} = ${value}`);
}
);
}
});
1-liner to copy all variables but the ones starting with DATABASE_URL
or HEROKU_
(which are dynamically set by heroku):
heroku config -s -a source-heroku-app | grep -vE '^DATABASE_URL|^HEROKU_' | xargs heroku config:set --app target-heroku-app
Thanks for the one liner @julienma!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Tim. That was ideal for my purposes