Skip to content

Instantly share code, notes, and snippets.

@davidjrice
Created March 10, 2012 19:42
Show Gist options
  • Save davidjrice/2012650 to your computer and use it in GitHub Desktop.
Save davidjrice/2012650 to your computer and use it in GitHub Desktop.
Clone heroku environment variables to a .env file for foreman
desc "Clone heroku environment variables to a .env file for foreman'"
namespace :heroku do
namespace :env do
task :clone => :environment do
ignore_list = [
"DATABASE_URL",
"GEM_PATH",
"LANG",
"LOG_LEVEL"
"PATH",
"RACK_ENV",
"RAILS_ENV",
"SHARED_DATABASE_URL",
]
puts 'Fetch heroku config'
config = `heroku config`
output = ''
config.lines.each do |line|
match = line.match(/([A-Z_]*)\s*=>\s*(\w*)/)
next if ignore_list.include?(match[1])
output << "#{match[1]}=#{match[2]}\n"
end
file = "#{Rails.root}/.env"
puts "Outputting to #{file}"
File.open(file, "w+") do |f|
f.write(output)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment