Class: Vanagon::CLI::BuildRequirements

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

Constant Summary collapse

DOCUMENTATION =
<<~DOCOPT.freeze
  Usage:
  build_requirements [options] <project-name> <platform>

  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]
    -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

Methods inherited from Vanagon::CLI

#options_validate

Instance Method Details

#options_translate(docopt_options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/vanagon/cli/build_requirements.rb', line 55

def options_translate(docopt_options)
  translations = {
    '--verbose' => :verbose,
    '--workdir' => :workdir,
    '--configdir' => :configdir,
    '--engine' => :engine,
    '<project-name>' => :project_name,
    '<platform>' => :platform,
  }
  return docopt_options.map { |k, v| [translations[k], v] }.to_h
end

#parse(argv) ⇒ Object



28
29
30
31
32
33
# File 'lib/vanagon/cli/build_requirements.rb', line 28

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vanagon/cli/build_requirements.rb', line 35

def run(options) # rubocop:disable Metrics/AbcSize
  platform = options[:platform]
  project = options[:project_name]
  driver = Vanagon::Driver.new(platform, project)

  components = driver.project.components
  component_names = components.map(&:name)
  build_requirements = []
  components.each do |component|
    build_requirements << component.build_requires.reject do |requirement|
      # only include external requirements: i.e. those that do not match
      # other components in the project
      component_names.include?(requirement)
    end
  end

  VanagonLogger.warn "**** External packages required to build #{project} on #{platform}: ***"
  VanagonLogger.warn JSON.pretty_generate(build_requirements.flatten.uniq.sort)
end