Class: Builderator::Tasks::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/builderator/tasks.rb

Overview

Top-level command line tasks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Thor::Actions

#run, #run_with_input, #run_without_bundler, #template, #thor_run

Constructor Details

#initialize(*_) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/builderator/tasks.rb', line 22

def initialize(*_)
  super

  Config.argv(options) ## Load command flags
  Config.load(File.join(ENV['HOME'], '.builderator/Buildfile'))
  Config.load(Util.relative_path('Buildfile').to_s)

  # Ignore existing config when we don't need it: i.e. `help`
  ignore_existing_config = ['help']
  return if ignore_existing_config.any? { |i| ARGV.include?(i) }

  Config.compile
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/builderator/tasks.rb', line 36

def self.exit_on_failure?
  true
end

Instance Method Details

#cleanObject



114
115
116
117
118
# File 'lib/builderator/tasks.rb', line 114

def clean
  invoke Tasks::Vagrant, :clean
  invoke Tasks::Berkshelf, :clean
  invoke Tasks::Vendor, :clean
end

#cleanupObject

Globally enable/disable workspace cleanup



41
# File 'lib/builderator/tasks.rb', line 41

class_option 'cleanup', :type => :boolean, :default => true

#config(key = nil) ⇒ Object

Helper/utility commands



105
# File 'lib/builderator/tasks.rb', line 105

desc 'config', 'Print compiled configuration'

#container(profile = :docker) ⇒ Object



87
88
89
90
91
# File 'lib/builderator/tasks.rb', line 87

def container(profile = :docker)
  prepare

  invoke Tasks::Packer, :build, [profile], options
end

#ec2(*args) ⇒ Object



68
69
70
71
# File 'lib/builderator/tasks.rb', line 68

def ec2(*args)
  prepare
  invoke Tasks::Vagrant, :ec2, args, options
end

#generate(project = :default) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/builderator/tasks.rb', line 140

def generate(project = :default)
  fail 'Please provide a valid build name with the `--build-name=VALUE` option!' unless Config.has?(:build_name)
  Config.generator.project.use(project)

  Config.generator.project.current.resource.each do |rname, resource|
    next if (options['ignore'] && options['ignore'].include?(rname.to_s)) ||
            resource.action == :ignore

    if (options['sync'] && options['sync'].include?(rname.to_s)) ||
       resource.action == :sync
      template resource.template, resource.path.first
      next
    end

    if (options['rm'] && options['rm'].include?(rname.to_s)) ||
       resource.action == :rm
      resource.path.each { |rm| remove_file rm }
      next
    end

    ## Create
    template resource.template, resource.path.first, :skip => true
  end
end

#image(profile = :default) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/builderator/tasks.rb', line 77

def image(profile = :default)
  prepare

  invoke Tasks::Packer, :build, [profile], options
  invoke Tasks::Packer, :copy, [profile], options if options['copy']
  invoke Tasks::Packer, :remote_tag, [profile], options if options['remote_tag']
end

#local(*args) ⇒ Object



62
63
64
65
# File 'lib/builderator/tasks.rb', line 62

def local(*args)
  prepare
  invoke Tasks::Vagrant, :local, args, options
end

#prepareObject

Tasks common to local, ec2, and ami builds



46
# File 'lib/builderator/tasks.rb', line 46

desc 'prepare', 'Common preparation tasks for Vagrant and Packer'