class Formatron::Chef::Berkshelf

Wrapper for the berkshelf cli

Constants

CONFIG_FILE
CONFIG_FILE_CONTENTS

Public Class Methods

new( directory:, keys:, chef_server_url:, username:, ssl_verify: ) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/formatron/chef/berkshelf.rb, line 23
def initialize(
  directory:,
  keys:,
  chef_server_url:,
  username:,
  ssl_verify:
)
  @config_file = File.join directory, CONFIG_FILE
  @keys = keys
  @chef_server_url = chef_server_url
  @username = username
  @ssl_verify = ssl_verify
end

Public Instance Methods

init() click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/formatron/chef/berkshelf.rb, line 38
def init
  File.write(@config_file, CONFIG_FILE_CONTENTS % {
    server_url: @chef_server_url,
    user: @username,
    key_file: @keys.user_key,
    ssl_verify: @ssl_verify
  })
end
upload(cookbook:, environment:) click to toggle source
# File lib/formatron/chef/berkshelf.rb, line 47
def upload(cookbook:, environment:)
  # rubocop:disable Metrics/LineLength
  command = "berks install -b #{File.join(cookbook, 'Berksfile')}"
  fail "failed to download cookbooks for opscode environment: #{environment}" unless Util::Shell.exec command
  command = "berks upload -c #{@config_file} -b #{File.join(cookbook, 'Berksfile')}"
  fail "failed to upload cookbooks for opscode environment: #{environment}" unless Util::Shell.exec command
  command = "berks apply #{environment} -c #{@config_file} -b #{File.join(cookbook, 'Berksfile.lock')}"
  fail "failed to apply cookbooks to opscode environment: #{environment}" unless Util::Shell.exec command
  # rubocop:enable Metrics/LineLength
end