class EcsRailsConsole::Cli

Attributes

command[R]
environment[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/ecs_rails_console/cli.rb, line 15
def initialize(options)
  super()
  @environment = options[:environment]
  @command = options[:command]
end
run!(options) click to toggle source
# File lib/ecs_rails_console/cli.rb, line 11
def self.run!(options)
  new(options).run!
end

Public Instance Methods

run!() click to toggle source
# File lib/ecs_rails_console/cli.rb, line 21
def run!
  puts "Cluster name: #{cluster_name}"

  task_description = run_task

  public_ip = get_public_ip(task_description)

  puts "it is running on: #{public_ip}"

  system("ssh #{SSH_OPTIONS} #{ssh_user}@#{public_ip} 'cd /app ; #{command}'")
rescue Aws::ECS::Errors::ExpiredTokenException
  puts "\nHey, it seems your token expired. Authenticate on AWS give another try."
end

Private Instance Methods

aws_credentials() click to toggle source
# File lib/ecs_rails_console/cli.rb, line 39
def aws_credentials
  config.slice(
    "profile",
    "access_key_id",
    "secret_access_key",
    "region"
  ).transform_keys(&:to_sym)
end
config() click to toggle source
# File lib/ecs_rails_console/cli.rb, line 48
def config
  @config ||= YAML.load_file(CONFIG_FILE)[environment] || {}
end
ssh_user() click to toggle source
# File lib/ecs_rails_console/cli.rb, line 52
def ssh_user
  config[:ssh_user] || 'root'
end