Class: Engineyard::Local::Command::Up

Inherits:
Base show all
Defined in:
lib/engineyard-local/command/up.rb

Instance Attribute Summary

Attributes inherited from Base

#env, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods inherited from Vagrant::Command::Base

#cookbook_status, #initialize

Methods included from Helpers

#insert_linebreaks, #merge_run_options, #run

Constructor Details

This class inherits a constructor from Engineyard::Local::Command::Base

Class Method Details

.setup_stack(options) ⇒ Object

install the application bundle and create/migrate the database TODO check for the database.yml and fail gracefully



8
9
10
11
12
13
14
15
16
# File 'lib/engineyard-local/command/up.rb', line 8

def self.setup_stack(options)
  Vagrant::Action::Builder.new do
    use Middleware::DNA unless options["no-dna"]
    use Middleware::Chef unless options["no-chef"]
    use Middleware::Bundle unless options["no-bundle"]
    use Middleware::Rails::DB unless options["no-db-setup"]
    use Middleware::Rails::Assets
  end
end

Instance Method Details

#box_defaultsObject



18
19
20
# File 'lib/engineyard-local/command/up.rb', line 18

def box_defaults
  Local.config[:box_defaults]
end

#box_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/engineyard-local/command/up.rb', line 22

def box_exists?(name)
  env.boxes.map { |box| box.name }.include?(name)
end

#exec(name = box_defaults[:name], uri = box_uri) ⇒ Object

convention based streamlining of Vagrant’s up



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/engineyard-local/command/up.rb', line 27

def exec(name=box_defaults[:name], uri=box_uri)
  if box_exists?(name)
    env.ui.warn(I18n.t("eylocal.up.box_exists", :name => name))
  else
    env.cli("box", "add", name, uri)
  end

  # if a Vagrant file does NOT exist create one
  if env.root_path.nil?
    env.cli("init", name)
  end

  # resets vagrant root path so that it can detect the
  # newly initialized Vagrantfile, and the newly added box
  # TODO submit alternate reset of root path to Vagrant
  env.send(:remove_instance_variable, :@root_path)
  env.load_config!
  env.boxes.reload!

  env.ui.info(I18n.t("eylocal.up.root_path", :root_path => env.root_path))
  if !pwd_matches_root_path
    env.ui.info(I18n.t("eylocal.up.root_path_instructions",
                       :root_path => env.root_path, :pwd => Dir.pwd))
  end

  # don't build a box if its already built
  with_target_vms do |vm|
    if vm.created?
      env.ui.info I18n.t("vagrant.commands.up.vm_created")
      if ! ( vm.state == 'running' )
        vm.start
      end
    else
      up = Vagrant.actions.get(:up)
      # insert the tag before the box is in a state where it can't be saved eg running
      up.insert_before(Vagrant::Action::VM::CheckGuestAdditions, Middleware::Tag)
      up.insert_before(Vagrant::Action::VM::CheckGuestAdditions, Middleware::Network, @options)

      opts = merge_run_options(vm)
      vm.env.action_runner.run(up, opts)
    end
  end

  # finish the box setup
  run self.class.setup_stack(options)
end