Class: Scaltainer::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/scaltainer/command.rb

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
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
# File 'lib/scaltainer/command.rb', line 6

def self.parse(args)
  configfile, statefile, wait, orchestrator, pushgateway = 'scaltainer.yml', nil, 0, :swarm, nil
  OptionParser.new do |opts|
    opts.banner = "Usage: scaltainer [options]"
    opts.on("-f", "--conf-file FILE", "Specify configuration file (default: scaltainer.yml)") do |file|
      configfile = file
    end
    opts.on("--state-file FILE", "Specify state file (default: <conf-file>.state)") do |file|
      statefile = file
    end
    opts.on("-w", "--wait SECONDS", "Specify wait time between repeated calls, 0 for no repetition (default: 0)") do |w|
      wait = w.to_i
    end
    opts.on("-o", "--orchestrator swarm:kubernetes", [:swarm, :kubernetes], "Specify orchestrator type (default: swarm)") do |o|
      orchestrator = o
    end
    opts.on("-g", "--prometheus-push-gateway ADDRESS", "Specify prometheus push gateway address in the form of host:port") do |gw|
      pushgateway = gw
    end
    opts.on("-v", "--version", "Show version and exit") do
      puts Scaltainer::VERSION
      exit 0
    end
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      puts "\nEnvironment variables: \n"
      puts "Docker Swarm options:"
      puts "- DOCKER_URL: defaults to local socket"
      puts "Kubernetes options:"
      puts "- KUBECONFIG: set to Kubernetes config (default: $HOME/.kube/config) if you want to connect to the current configured cluster"
      puts "- KUBERNETES_API_SERVER: overrides option in KUBECONFIG and defaults to https://kubernetes.default:443"
      puts "- KUBERNETES_SKIP_SSL_VERIFY: KUBECONFIG option overrides this, set to any value to skip SSL verification"
      puts "- KUBERNETES_API_ENDPOINT: defaults to /api"
      puts "- KUBERNETES_API_VERSION: overrides option in KUBECONFIG and defaults to v1"
      puts "- KUBERNETES_CONTROLLER_KIND: controller kind to scale, allowed values: deployment (default), replication_controller, or replica_set"
      puts "  Make sure the KUBERNETES_CONTROLLER_KIND you specify is part of the api specified using KUBERNETES_API_ENDPOINT and KUBERNETES_API_VERSION"
      puts "General options:"
      puts "- HIREFIRE_TOKEN"
      puts "- NEW_RELIC_API_KEY"
      puts "- RESPONSE_TIME_WINDOW: defaults to 5"
      puts "- LOG_LEVEL: defaults to INFO"
      puts "- DOCKER_SECRETS_PATH_GLOB: path glob containing env files to load"
      exit
    end     
  end.parse!

  statefile = "#{configfile}.state" unless statefile

  raise ConfigurationError.new("File not found: #{configfile}") unless File.exists?(configfile)

  load_env

  logger = Logger.new(STDOUT)
  logger.level = %w(debug info warn error fatal unknown).find_index((ENV['LOG_LEVEL'] || '').downcase) || 1

  return configfile, statefile, logger, wait, orchestrator, pushgateway
end