Class: Vanagon::CLI::Build

Inherits:
Vanagon::CLI show all
Defined in:
lib/vanagon/cli/build.rb

Constant Summary collapse

DOCUMENTATION =
<<~DOCOPT.freeze
  Usage:
  build [options] <project-name> <platforms> [<targets>]

  Options:
    -h, --help                       Display help
    -c, --configdir DIRECTORY        Configuration directory [default: #{Dir.pwd}/configs]
    -e, --engine ENGINE              Custom engine to use [default: always_be_scheduling]
    -o, --only-build COMPONENT,COMPONENT,...
                                     Only build listed COMPONENTs
    -p, --preserve [RULE]            Rule for VM preservation: never, on-failure, always
                                       [Default: always]
    -r, --remote-workdir DIRECTORY   Working directory on the remote host
    -s, --skipcheck                  Skip the "check" stage when building components
    -w, --workdir DIRECTORY          Working directory on the local host
    -v, --verbose                    Only here for backwards compatibility. Does nothing.

  Engines:
    always_be_scheduling: default engine using Puppet's ABS infrastructure
    docker: a docker container on the local host
    ec2: an Amazon EC2 instance
    hardware: a dedicated hardware device
    local: the local machine, cannot be used with a target
    pooler: [deprecated] Puppet's vmpooler
DOCOPT

Instance Method Summary collapse

Instance Method Details

#options_translate(docopt_options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/vanagon/cli/build.rb', line 55

def options_translate(docopt_options)
  translations = {
    '--verbose' => :verbose,
    '--workdir' => :workdir,
    '--remote-workdir' => :"remote-workdir",
    '--configdir' => :configdir,
    '--engine' => :engine,
    '--skipcheck' => :skipcheck,
    '--preserve' => :preserve,
    '--only-build' => :only_build,
    '<project-name>' => :project_name,
    '<platforms>' => :platforms,
    '<targets>' => :targets
  }
  return docopt_options.map { |k, v| [translations[k], v] }.to_h
end

#options_validate(options) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/vanagon/cli/build.rb', line 72

def options_validate(options)
  # Handle --preserve option checking
  valid_preserves = %w[always never on-failure]
  unless valid_preserves.include? options[:preserve]
    raise InvalidArgument, "--preserve option can only be one of: " +
                           valid_preserves.join(', ')
  end
  options[:preserve] = options[:preserve].to_sym
  return options
end

#parse(argv) ⇒ Object



33
34
35
36
37
38
# File 'lib/vanagon/cli/build.rb', line 33

def parse(argv)
  Docopt.docopt(DOCUMENTATION, { argv: argv })
rescue Docopt::Exit => e
  VanagonLogger.error e.message
  exit 1
end

#run(options) ⇒ Object

rubocop:disable Metrics/AbcSize



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vanagon/cli/build.rb', line 40

def run(options) # rubocop:disable Metrics/AbcSize
  project = options[:project_name]
  platform_list = options[:platforms].split(',')
  target_list = []
  unless options[:targets].nil? || options[:targets].empty?
    target_list = options[:targets].split(',')
  end

  platform_list.zip(target_list).each do |pair|
    platform, target = pair
    artifact = Vanagon::Driver.new(platform, project, options.merge({ :target => target }))
    artifact.run
  end
end