-
-
Save nabucosound/8181671 to your computer and use it in GitHub Desktop.
#!/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') |
FYI much quicker to set them all in one heroku config:set a=b c=d etc
If you prefer a manual review and you do have bash/zsh:
heroku config -s -a source-heroku-app > config.txt
Now review config.txt and remove any unwanted config lines
cat config.txt | tr '\n' ' ' | xargs heroku config:set -a target-heroku-app
Thanks Tim. That was ideal for my purposes
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!
For those not using bash and have Ruby: