Class: Hako::CLI::Deploy

Inherits:
Object
  • Object
show all
Defined in:
lib/hako/cli.rb

Constant Summary collapse

DEFAULT_TIMEOUT =

20 minutes

1200

Instance Method Summary collapse

Instance Method Details

#parse!(argv) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hako/cli.rb', line 81

def parse!(argv)
  @force = false
  @dry_run = false
  @verbose = false
  @timeout = DEFAULT_TIMEOUT
  parser.parse!(argv)
  @definition_path = argv.first

  if @definition_path.nil?
    puts parser.help
    exit 1
  end
end

#parserObject



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hako/cli.rb', line 95

def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = 'hako deploy [OPTIONS] FILE'
    opts.version = VERSION
    opts.on('-f', '--force', 'Run deployment even if nothing is changed') { @force = true }
    opts.on('-t', '--tag=TAG', 'Specify tag') { |v| @tag = v }
    opts.on('-n', '--dry-run', 'Enable dry-run mode') { @dry_run = true }
    opts.on('-v', '--verbose', 'Enable verbose logging') { @verbose = true }
    opts.on('--timeout=TIMEOUT_SEC', "Timeout deployment after TIMEOUT_SEC seconds (default: #{DEFAULT_TIMEOUT})") { |v| @timeout = v.to_i }
  end
end

#run(argv) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hako/cli.rb', line 61

def run(argv)
  parse!(argv)
  require 'hako/application'
  require 'hako/commander'

  if @verbose
    Hako.logger.level = Logger::DEBUG
  end

  options =
    if @dry_run
      { expand_variables: false, ask_keys: true }
    else
      {}
    end
  Commander.new(Application.new(@definition_path, options)).deploy(force: @force, tag: @tag, dry_run: @dry_run, timeout: @timeout)
end