Class: ConvoxInstaller::Requirements
- Inherits:
-
Object
- Object
- ConvoxInstaller::Requirements
- Defined in:
- lib/convox_installer/requirements.rb
Instance Attribute Summary collapse
-
#ecr_label ⇒ Object
Returns the value of attribute ecr_label.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #command_present?(command) ⇒ Boolean
- #ensure_requirements! ⇒ Object
-
#find_command(command) ⇒ Object
Stubbed in tests.
-
#initialize(options = {}) ⇒ Requirements
constructor
A new instance of Requirements.
- #quit! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Requirements
Returns a new instance of Requirements.
11 12 13 14 15 |
# File 'lib/convox_installer/requirements.rb', line 11 def initialize( = {}) @ecr_label = [:ecr_label] @logger = Logger.new($stdout) logger.level = [:log_level] || Logger::INFO end |
Instance Attribute Details
#ecr_label ⇒ Object
Returns the value of attribute ecr_label.
9 10 11 |
# File 'lib/convox_installer/requirements.rb', line 9 def ecr_label @ecr_label end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/convox_installer/requirements.rb', line 9 def logger @logger end |
Instance Method Details
#command_present?(command) ⇒ Boolean
72 73 74 75 76 77 78 79 80 |
# File 'lib/convox_installer/requirements.rb', line 72 def command_present?(command) path = find_command command if path.present? logger.debug "=> Found #{command}: #{path}" return true end logger.debug "=> Could not find #{command}!" false end |
#ensure_requirements! ⇒ Object
17 18 19 20 21 22 23 24 25 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 |
# File 'lib/convox_installer/requirements.rb', line 17 def ensure_requirements! logger.debug 'Checking for required commands...' @missing_packages = [] unless command_present? 'convox' @missing_packages << { name: 'convox', brew: 'convox', docs: 'https://docs.convox.com/introduction/installation' } end unless command_present? 'aws' @missing_packages << { name: 'aws', brew: 'awscli', docs: 'https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html' } end unless command_present? 'terraform' @missing_packages << { name: 'terraform', brew: 'terraform', docs: 'https://learn.hashicorp.com/tutorials/terraform/install-cli' } end if @missing_packages.any? logger.error 'This script requires the convox and AWS CLI tools.' if OS.mac? logger.error 'Please run: brew install ' \ "#{@missing_packages.map { |p| p[:brew] }.join(' ')}" else logger.error 'Installation Instructions:' @missing_packages.each do |package| logger.error "* #{package[:name]}: #{package[:docs]}" end end quit! end client = Convox::Client.new if client.convox_3_cli? logger.debug "=> Convox CLI is version 3.x.x (#{client.cli_version_string})" return end logger.error 'This script requires Convox CLI version 3.x.x. ' \ "Your Convox CLI version is: #{client.cli_version_string}" logger.error "Please run 'brew update convox' or follow the instructions " \ 'at https://docs.convox.com/getting-started/introduction' quit! end |
#find_command(command) ⇒ Object
Stubbed in tests
83 84 85 |
# File 'lib/convox_installer/requirements.rb', line 83 def find_command(command) `which #{command} 2>/dev/null`.chomp end |
#quit! ⇒ Object
87 88 89 |
# File 'lib/convox_installer/requirements.rb', line 87 def quit! exit 1 end |