Class: Workup::Application

Inherits:
Thor
  • Object
show all
Defined in:
lib/workup/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Application

Returns a new instance of Application.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/workup/application.rb', line 32

def initialize(*args)
  @log ||= begin
    log = ::Logging.logger['workup']
    log.add_appenders('stdout')
    log.level = :debug
    log
  end

  Workup::Helpers.check_user!

  super(*args)
end

Instance Attribute Details

#logObject (readonly)

Returns the value of attribute log.



30
31
32
# File 'lib/workup/application.rb', line 30

def log
  @log
end

Instance Method Details

#chef_clientObject



89
90
91
92
93
94
95
96
97
98
# File 'lib/workup/application.rb', line 89

def chef_client
  raise 'Workup directory does not exist' unless File.exist?(options[:workup_dir])
  clientrb_path = File.join(options[:workup_dir], 'client.rb')

  client_cmd = ['chef-client', '--no-fork', '--config', clientrb_path]
  client_cmd << '-A' if Gem.win_platform?
  client_cmd << '--why-run' if options[:dry_run]

  execute(*client_cmd, live_stdout: STDOUT, live_stderr: STDERR)
end

#chef_zeroObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/workup/application.rb', line 72

def chef_zero
  raise 'Workup directory does not exist' unless File.exist?(options[:workup_dir])
  policy_path = File.join(options[:workup_dir], 'Policyfile.rb')
  lock_path = File.join(options[:workup_dir], 'Policyfile.lock.json')
  chefzero_path = File.join(options[:workup_dir], 'chef-zero')

  log.info 'Updating lock file... '
  execute('chef', (File.exist?(lock_path) ? 'update' : 'install'), policy_path,
                          env: { GIT_SSL_NO_VERIFY: options['verify_ssl'] ? '0' : '1' },
                          cwd: options[:workup_dir])

  log.info 'Creating chef-zero directory... '
  execute('chef', 'export', '--force', policy_path, chefzero_path,
                          env: { GIT_SSL_NO_VERIFY: options['verify_ssl'] ? '0' : '1' })
end

#defaultObject



65
66
67
68
69
# File 'lib/workup/application.rb', line 65

def default
  log.info "Starting workup\n"
  chef_zero
  chef_client
end