Class: BeanDocker::Docker

Inherits:
Object
  • Object
show all
Defined in:
lib/bean_docker.rb

Overview

Your code goes here…

Instance Method Summary collapse

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bean_docker.rb', line 9

def run
  image_name = "aws_beanstalk/current-app:latest"
  envvar_file_name = '/opt/elasticbeanstalk/deploy/configuration/containerconfiguration'

  begin
    container_config = JSON.parse(File.read(envvar_file_name))
  rescue => exception
    puts "Exception: #{exception}"
    puts "Enable access to this file with:\n"
    puts "  sudo chmod 664 #{envvar_file_name}"
  else
    begin
      raw_vars =  container_config['optionsettings']['aws:elasticbeanstalk:application:environment']

      alias_line = "sudo docker run -ti -w=\"/usr/src/app\""

      raw_vars.each do |raw_var|
        variable, value = raw_var.split('=')
        if value # && !value.include?('`')
          alias_line += " --env #{variable}=\"#{value.shellescape}\" "
        end
      end

      puts "Protect the environmant variables file with:\n"
      puts "  sudo chmod 660 #{envvar_file_name}"

      exec("#{alias_line} #{image_name} bash" )
    rescue => exception
      puts "Exception: #{exception}"
    end
  end
end