Sha256: 639cc6af29a5132f814e6485f750fc0c142c0c91603e18bb0d325a5a6e2ed3f6

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require 'pty'
require 'shellwords'

namespace :env_json do
  desc 'print env_json computed environment'
  task print_env: :environment do
    pp EnvJson.env
  end

  desc 'load env into ElasticBeanstalk'
  task :eb do
    eb_environment_name = ENV['ENVIRONMENT_NAME']

    EnvJson.load_env_from_source_with_overrides(Rails.root.join('config/env.json'), ENV.fetch('RAILS_ENV'))

    eb_formated_env = EnvJson.env.map{|key,value| "#{Shellwords.escape key}=#{Shellwords.escape value}" }.join(' ')
    eb_environment_name_switch = eb_environment_name ? "-e #{eb_environment_name}" : nil
    eb_command = "eb setenv #{eb_environment_name_switch} -v #{eb_formated_env}"

    begin
      PTY.spawn(eb_command) do |stdin, stdout, pid|
        begin
          stdin.each { |line| print line }
        rescue Errno::EIO
          puts "Errno:EIO error, but this probably just means that the process has finished giving output"
        end
      end
    rescue PTY::ChildExited
      puts "The child process exited!"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
env_json-0.3.2 lib/env_json/rails_tasks.rb
env_json-0.3.0 lib/env_json/rails_tasks.rb