Class: Elevage::Build

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/elevage/build.rb

Overview

Create new platform definition files and environments folder structure, used by the command line ‘build` option

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject

rubocop:enable LineLength



34
35
36
# File 'lib/elevage/build.rb', line 34

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#buildObject

Process and execute the ‘build` command



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/elevage/build.rb', line 41

def build
  # Make the logfile directory if it doesn't exist
  Dir.mkdir(options[:logfiles]) unless Dir.exist?(options[:logfiles])

  # Fetch the environment and make sure it passes basic health checks
  @environment = Elevage::Environment.new(env)
  fail(IOError) unless @environment.healthy?

  # =============================================================
  # Option sanity checking.
  #
  # What are we going to reject as invalid options?
  #
  if options[:all] && options[:tier] || options[:all] && options[:component] || options[:tier] && options[:component]
    warn 'The --all, --tier and --component options may not be specified together.'
    exit false
  end

  if options[:node] && !options[:component]
    warn 'When requesting a --node you must specify which --component.'
    exit false
  end

  unless options[:all] || options[:tier] || options[:component]
    warn 'You must specify one of --all, --tier=<tier>, or --component=<component>'
    exit false
  end

  # Determine what, exactly, we're supposed to build
  if options[:all]
    # =============================================================
    # Build ALL THE THINGS!
    #
    @environment.provision(type: :all,
                           options: options)

  elsif options[:tier]
    # =============================================================
    # Build most of the things...
    #
    if options[:tier].eql?('tier')
      warn 'Was asked to build a tier, but was not told which one!'
      exit false
    end
    @environment.provision(type: :tier,
                           tier: options[:tier],
                           options: options)

  elsif options[:component]
    # =============================================================
    # Build a few things...
    #
    if options[:component].eql?('component')
      warn 'Was asked to build a component, but was not told which one!'
      exit false
    end
    # See if we're actually only supposed to build just one thing...
    if options[:node]
      @environment.provision(type: :node,
                             component: options[:component],
                             instance: options[:node],
                             options: options)
    else
      @environment.provision(type: :component,
                             component: options[:component],
                             options: options)
    end
  end
end