Class: Hyrb::Tasks::Provision::DigitalOcean

Inherits:
Hyrb::Task
  • Object
show all
Defined in:
lib/hyrb/tasks/provision.rb

Instance Attribute Summary

Attributes inherited from Hyrb::Task

#env, #pipeline

Instance Method Summary collapse

Methods inherited from Hyrb::Task

depends, #initialize, prompt, prompts, #run_before

Constructor Details

This class inherits a constructor from Hyrb::Task

Instance Method Details

#run(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hyrb/tasks/provision.rb', line 17

def run(env)
  ssh_key_ids = env.project.developers(env.developers).map(&:digital_ocean_id).compact

  flavor_id = option_list(env.digital_ocean_cache, :flavors, 2) do |f, i|
    "#{i+1}: #{f.name} ram / #{f.cpu} cpu / #{'$%.2f/mo' % f.cost_per_month}"
  end.id

  image_id = option_list(env.digital_ocean_cache, :images, 16) do |f, i|
    "#{i+1}: #{f.name} / id: #{f.id}"
  end.id

  region_id = option_list(env.digital_ocean_cache, :regions, 2) do |f, i|
    "#{i+1}: #{f.name} / id: #{f.id}"
  end.id

  say "Creating Digital Ocean Server"
  server = env.digital_ocean_client.servers.create({
    name: env.environment.server_name,
    flavor_id: flavor_id,
    image_id: image_id,
    region_id: region_id,
    ssh_key_ids: ssh_key_ids,
  })

  env.environment.provider = 'digital_ocean'
  env.environment.server_id = server.id

  sleep(4) until server.reload.ready?
  env.environment.host = server.public_ip_address

  env.environment.save!

  say "Created Digital Ocean Server!", :green
  say "IP Address: #{server.public_ip_address} / ID: #{server.id}", :green
  say "\n\tssh root@#{server.public_ip_address}\n"
  beep
end