Created
August 16, 2015 04:12
-
-
Save chsh/737a81e418c6bfae656a to your computer and use it in GitHub Desktop.
Rake tasks to fetch/push aws elasticbeanstalk env vars on environment.
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
namespace :eb do | |
namespace :env do | |
desc "Fetch env vars from eb" | |
task :fetch, [:envname] do |t, params| | |
lines = `eb printenv #{params[:envname]}`.strip.split(/\r?\n/) | |
lines.shift if lines[0] =~ /Environment Variables:/ | |
hash = {} | |
lines.sort.each do |line| | |
if line =~ /^\s+(.+)\s+=\s+(.+)$/ | |
hash[$1] = $2 | |
end | |
end | |
File.open("eb-env.yml", 'w') { |f| f.write hash.to_yaml } | |
puts "#{params[:envname]}'s env vars have been saved to 'eb-env.yml'" | |
end | |
desc "Push env vars to eb" | |
task :push, [:envname] do |t, params| | |
hash = YAML.load_file("eb-env.yml") | |
varkeys = [] | |
hash.each do |key, value| | |
varkeys << "#{key}=#{value}" | |
end | |
cmd = "eb setenv #{varkeys.join(' ')} -e #{params[:envname]}" | |
puts cmd | |
puts `#{cmd}` | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment