Class: Forger::Create

Inherits:
Base
  • Object
show all
Includes:
AwsService, ErrorMessages
Defined in:
lib/forger/create.rb,
lib/forger/create/info.rb,
lib/forger/create/params.rb,
lib/forger/create/waiter.rb,
lib/forger/create/error_messages.rb

Defined Under Namespace

Modules: ErrorMessages Classes: Info, Params, Waiter

Constant Summary

Constants inherited from Base

Base::BUILD_ROOT, Base::SCRIPTS_INFO_PATH

Instance Method Summary collapse

Methods included from ErrorMessages

#handle_ec2_service_error!, #invalid_group_not_found, #invalid_parameter_combination, #invalid_subnet_id_not_found, #map_exception_to_method, #print_error_message

Methods included from AwsService

#ec2

Methods inherited from Base

#derandomize, #initialize, #randomize

Constructor Details

This class inherits a constructor from Forger::Base

Instance Method Details

#paramsObject

params are main derived from profile files



67
68
69
# File 'lib/forger/create.rb', line 67

def params
  @params ||= Params.new(@options).generate
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/forger/create.rb', line 14

def run
  Profile.new(@options).check!

  Hook.run(:before_run_instances, @options)
  sync_scripts_to_s3

  puts "Creating EC2 instance #{@name.colorize(:green)}"
  info = Info.new(@options, params)
  info.ec2_params
  if @options[:noop]
    puts "NOOP mode enabled. EC2 instance not created."
    return
  end
  resp = run_instances(params)

  instance_id = resp.instances.first.instance_id
  info.spot(instance_id)
  puts "EC2 instance #{@name} created: #{instance_id} 🎉"
  puts "Visit https://console.aws.amazon.com/ec2/home to check on the status"
  info.cloudwatch(instance_id)

  Waiter.new(@options.merge(instance_id: instance_id)).wait
end

#run_instances(params) ⇒ Object



38
39
40
41
42
# File 'lib/forger/create.rb', line 38

def run_instances(params)
  ec2.run_instances(params)
rescue Aws::EC2::Errors::ServiceError => e
  handle_ec2_service_error!(e)
end

#sync_scripts_to_s3Object

Configured by config/settings.yml. Example: config/settings.yml:

Format 1: Simple String

development:
  s3_folder: mybucket/path/to/folder

Format 2: Hash

development:
  s3_folder:
    default: mybucket/path/to/folder
    dev_profile1: mybucket/path/to/folder
    dev_profile1: another-bucket/storage/path


59
60
61
62
63
64
# File 'lib/forger/create.rb', line 59

def sync_scripts_to_s3
  return unless Forger.settings["s3_folder"]
  upload = Script::Upload.new(@options)
  return if upload.empty?
  upload.run
end