Class: AvoDeploy::Bootstrap

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

Class Method Summary collapse

Class Method Details

.run(stage = :default, verbose = false, debug = false) ⇒ Object

Runs the avocado bootstrap

Parameters:

  • stage (Symbol) (defaults to: :default)

    the stage to bootstrap

  • verbose (Boolean) (defaults to: false)

    run in verbose mode

  • debug (Boolean) (defaults to: false)

    run in boolean mode



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/avodeploy/bootstrap.rb', line 26

def self.run(stage = :default, verbose = false, debug = false)
  if stage.is_a?(String)
    stage = stage.to_sym
  end

  begin
    # defaults
    AvoDeploy::Deployment.configure do
      set :stage, stage

      setup_stage :default do
        # a default stage is needed for some use cases,
        # especially if you don't know which stages were defined by the user
      end
    end

    if File.exist?(Dir.pwd.concat('/Avofile')) == false
      raise RuntimeError, 'Could not find Avofile. Run `avo install` first.'
    end

    instance = AvoDeploy::Deployment.instance

    if debug
      instance.log.level = Logger::DEBUG
    elsif verbose
      instance.log.level = Logger::INFO
    else
      instance.log.level = instance.config.get(:log_level)
    end

    # load user config initially to determine strategy
    begin
      load File.join(Dir.pwd, 'Avofile')
    rescue RuntimeError => e
      # `find_chain_index_containing': could not find a chain containing task create_deployment_tarball (RuntimeError)
      # error not neccessary because dependencies are not loaded
    end

    instance.log.debug 'LoadingĀ user configuration...'
    # override again by user config to allow manipulation of tasks
    load File.join(Dir.pwd, 'Avofile')

    # requested stage was not found
    if instance.config.loaded_stage.nil?
      raise ArgumentError, 'The requested stage does not exist.'
    end
  rescue Exception => e
    #if debug
      raise e
    #else
    #  AvoDeploy::Deployment.instance.log.error e.message.red
    #end

    Kernel.exit(true)
  end

  AvoDeploy::Deployment.instance
end