Class: Berkshelf::Berksfile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Mixin::Logging, Cleanroom
Defined in:
lib/berkshelf/berksfile.rb

Constant Summary collapse

DEFAULT_API_URL =
"https://supermarket.chef.io".freeze
EXCLUDED_VCS_FILES_WHEN_VENDORING =

Don’t vendor VCS files. Reference GNU tar –exclude-vcs: www.gnu.org/software/tar/manual/html_section/tar_49.html

[".arch-ids", "{arch}", ".bzr", ".bzrignore", ".bzrtags", "CVS", ".cvsignore", "_darcs", ".git", ".hg", ".hgignore", ".hgrags", "RCS", "SCCS", ".svn", "**/.git"].freeze

Instance Attribute Summary collapse

Attributes included from Mixin::Logging

#logger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Berksfile

Create a new Berksfile object.

Parameters:

  • path (String)

    path on disk to the file containing the contents of this Berksfile

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :except (Symbol, Array<String>)

    Group(s) to exclude which will cause any dependencies marked as a member of the group to not be installed

  • :only (Symbol, Array<String>)

    Group(s) to include which will cause any dependencies marked as a member of the group to be installed and all others to be ignored



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/berkshelf/berksfile.rb', line 63

def initialize(path, options = {})
  @filepath         = File.expand_path(path)
  @dependencies     = Hash.new
  @sources          = Hash.new
  @delete           = options[:delete]

  # defaults for what solvers to use
  @required_solver  = nil
  @preferred_solver = :gecode

  if options[:except] && options[:only]
    raise ArgumentError, "Cannot specify both :except and :only!"
  elsif options[:except]
    except = Array(options[:except]).collect(&:to_sym)
    @filter = ->(dependency) { (except & dependency.groups).empty? }
  elsif options[:only]
    only = Array(options[:only]).collect(&:to_sym)
    @filter = ->(dependency) { !(only & dependency.groups).empty? }
  else
    @filter = ->(dependency) { true }
  end
end

Instance Attribute Details

#filepathString (readonly)

Returns The path on disk to the file representing this instance of Berksfile.

Returns:

  • (String)

    The path on disk to the file representing this instance of Berksfile



42
43
44
# File 'lib/berkshelf/berksfile.rb', line 42

def filepath
  @filepath
end

#preferred_solverSymbol (readonly)

Returns The solver engine preferred by this instance of Berksfile.

Returns:

  • (Symbol)

    The solver engine preferred by this instance of Berksfile



50
51
52
# File 'lib/berkshelf/berksfile.rb', line 50

def preferred_solver
  @preferred_solver
end

#required_solverSymbol (readonly)

Returns The solver engine required by this instance of Berksfile.

Returns:

  • (Symbol)

    The solver engine required by this instance of Berksfile



46
47
48
# File 'lib/berkshelf/berksfile.rb', line 46

def required_solver
  @required_solver
end

Class Method Details

.from_file(file, options = {}) ⇒ Berksfile

Parameters:

  • file (#to_s)

    a path on disk to a Berksfile to instantiate from

Returns:

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/berkshelf/berksfile.rb', line 19

def from_file(file, options = {})
  raise BerksfileNotFound.new(file) unless File.exist?(file)

  begin
    new(file, options).evaluate_file(file)
  rescue => ex
    raise BerksfileReadError.new(ex)
  end
end

.from_options(options = {}) ⇒ Object

Instantiate a Berksfile from the given options. This method is used heavily by the CLI to reduce duplication.

Parameters:

  • path (String)

    path on disk to the file containing the contents of this Berksfile

  • options (Hash) (defaults to: {})

    a customizable set of options



10
11
12
13
# File 'lib/berkshelf/berksfile.rb', line 10

def from_options(options = {})
  options[:berksfile] ||= File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME)
  from_file(options[:berksfile], options.slice(:except, :only, :delete))
end

Instance Method Details

#[](name) ⇒ Dependency Also known as: get_dependency

Parameters:

  • name (String)

    name of the dependency to return

Returns:



394
395
396
# File 'lib/berkshelf/berksfile.rb', line 394

def [](name)
  @dependencies[name]
end

#add_dependency(name, constraint = nil, options = {}) ⇒ Array<Dependency]

Add a dependency of the given name and constraint to the array of dependencies.

Parameters:

  • name (String)

    the name of the dependency to add

  • constraint (String, Semverse::Constraint) (defaults to: nil)

    the constraint to lock the dependency to

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :group (Symbol, Array)

    the group or groups that the cookbook belongs to

  • :path (String)

    a filepath to the cookbook on your local disk

  • :git (String)

    the Git URL to clone

Returns:

Raises:



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/berkshelf/berksfile.rb', line 303

def add_dependency(name, constraint = nil, options = {})
  if @dependencies[name]
    # Only raise an exception if the dependency is a true duplicate
    groups = (options[:group].nil? || options[:group].empty?) ? [:default] : options[:group]
    if !(@dependencies[name].groups & groups).empty?
      raise DuplicateDependencyDefined.new(name)
    end
  end

  if options[:path]
     = File.join(options[:path], "metadata.rb")
  end

  options[:constraint] = constraint

  @dependencies[name] = Dependency.new(self, name, options)
end

#chef_api(*args) ⇒ Object

TODO:

remove in Berkshelf 4.0

Raises:



278
279
280
281
282
# File 'lib/berkshelf/berksfile.rb', line 278

def chef_api(*args)
  raise DeprecatedError.new "Your Berksfile contains a chef_api location. Chef API locations have " +
    " been replaced by the source location. Please remove your site location and try again. For more " +
    " information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
end

#cookbook(name, version_constraint, options = {}) ⇒ Object #cookbook(name, options = {}) ⇒ Object

Add a cookbook dependency to the Berksfile to be retrieved and have its dependencies recursively retrieved and resolved.

Examples:

a cookbook dependency that will be retrieved from one of the default locations

cookbook 'artifact'

a cookbook dependency that will be retrieved from a path on disk

cookbook 'artifact', path: '/Users/reset/code/artifact'

a cookbook dependency that will be retrieved from a Git server

cookbook 'artifact', git: 'git://github.com/RiotGames/artifact-cookbook.git'

Overloads:

  • #cookbook(name, version_constraint, options = {}) ⇒ Object

    Parameters:

    • name (#to_s)
    • version_constraint (#to_s)

    Options Hash (options):

    • :group (Symbol, Array)

      the group or groups that the cookbook belongs to

    • :path (String)

      a filepath to the cookbook on your local disk

    • :git (String)

      the Git URL to clone

    See Also:

  • #cookbook(name, options = {}) ⇒ Object

    Parameters:

    • name (#to_s)

    Options Hash (options):

    • :group (Symbol, Array)

      the group or groups that the cookbook belongs to

    • :path (String)

      a filepath to the cookbook on your local disk

    • :git (String)

      the Git URL to clone

    See Also:



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/berkshelf/berksfile.rb', line 144

def cookbook(*args)
  options = args.last.is_a?(Hash) ? args.pop : Hash.new
  name, constraint = args

  options[:path] &&= File.expand_path(options[:path], File.dirname(filepath))
  options[:group] = Array(options[:group])

  if @active_group
    options[:group] += @active_group
  end

  add_dependency(name, constraint, options)
end

#cookbooksArray<CachedCookbook>

Behaves the same as #dependencies, but this method returns an array of CachedCookbook objects instead of dependency objects. This method relies on the #retrieve_locked method to load the proper cached cookbook from the Berksfile + lockfile combination.

Returns:

See Also:

  • for a description of the +options+ hash
  • for a list of possible exceptions that might be raised and why


351
352
353
# File 'lib/berkshelf/berksfile.rb', line 351

def cookbooks
  dependencies.map { |dependency| retrieve_locked(dependency) }
end

#dependenciesArray<Dependency>

Returns:



334
335
336
# File 'lib/berkshelf/berksfile.rb', line 334

def dependencies
  @dependencies.values.sort.select(&@filter)
end

#extension(name) ⇒ true

Activate a Berkshelf extension at runtime.

Examples:

Activate the Mercurial extension

extension 'hg'

Parameters:

  • name (String)

    the name of the extension to activate

Returns:

  • (true)

Raises:

  • (LoadError)

    if the extension cannot be loaded



98
99
100
101
102
103
104
# File 'lib/berkshelf/berksfile.rb', line 98

def extension(name)
  require "berkshelf/#{name}"
  true
rescue LoadError
  raise LoadError, "Could not load an extension by the name `#{name}'. " \
    "Please make sure it is installed."
end

#find(name) ⇒ Dependency?

Find a dependency defined in this berksfile by name.

Parameters:

  • name (String)

    the name of the cookbook dependency to search for

Returns:

  • (Dependency, nil)

    the cookbook dependency, or nil if one does not exist



361
362
363
# File 'lib/berkshelf/berksfile.rb', line 361

def find(name)
  @dependencies[name]
end

#group(*args) ⇒ Object



159
160
161
162
163
# File 'lib/berkshelf/berksfile.rb', line 159

def group(*args)
  @active_group = args
  yield
  @active_group = nil
end

#groupsHash

Returns a hash containing group names as keys and an array of Dependencies that are a member of that group as values

Example:

{
  nautilus: [
    #<Dependency: nginx (~> 1.0.0)>,
    #<Dependency: mysql (~> 1.2.4)>
  ],
  skarner: [
    #<Dependency: nginx (~> 1.0.0)>
  ]
}.

Returns:

  • (Hash)

    a hash containing group names as keys and an array of Dependencies that are a member of that group as values

    Example:

    {
      nautilus: [
        #<Dependency: nginx (~> 1.0.0)>,
        #<Dependency: mysql (~> 1.2.4)>
      ],
      skarner: [
        #<Dependency: nginx (~> 1.0.0)>
      ]
    }
    


379
380
381
382
383
384
385
386
387
388
# File 'lib/berkshelf/berksfile.rb', line 379

def groups
  {}.tap do |groups|
    dependencies.each do |dependency|
      dependency.groups.each do |group|
        groups[group] ||= []
        groups[group] << dependency
      end
    end
  end
end

#has_dependency?(dependency) ⇒ Boolean

Check if the Berksfile has the given dependency, taking into account group and –only/–except flags.

Parameters:

  • dependency (String, Dependency)

    the dependency or name of dependency to check presence of

Returns:

  • (Boolean)


328
329
330
331
# File 'lib/berkshelf/berksfile.rb', line 328

def has_dependency?(dependency)
  name = Dependency.name(dependency)
  dependencies.map(&:name).include?(name)
end

#installArray<CachedCookbook>

Install the dependencies listed in the Berksfile, respecting the locked versions in the Berksfile.lock.

  1. Check that a lockfile exists. If a lockfile does not exist, all dependencies are considered to be “unlocked”. If a lockfile is specified, a definition is created via the following algorithm:

    • For each source, see if there exists a locked version that still satisfies the version constraint in the Berksfile. If there exists such a source, remove it from the list of unlocked sources. If not, then either a version constraint has changed, or a new source has been added to the Berksfile. In the event that a locked_source exists, but it no longer satisfies the constraint, this method will raise a OutdatedCookbookSource, and inform the user to run berks update COOKBOOK to remedy the issue.

    • Remove any locked sources that no longer exist in the Berksfile (i.e. a cookbook source was removed from the Berksfile).

  2. Resolve the collection of locked and unlocked dependencies.

  3. Write out a new lockfile.

Returns:

Raises:

  • (OutdatedDependency)

    if the lockfile constraints do not satisfy the Berksfile constraints



425
426
427
# File 'lib/berkshelf/berksfile.rb', line 425

def install
  Installer.new(self).run
end

#listHash<Dependency, CachedCookbook>

The cached cookbooks installed by this Berksfile.

Returns:

Raises:



481
482
483
484
485
486
487
# File 'lib/berkshelf/berksfile.rb', line 481

def list
  validate_lockfile_present!
  validate_lockfile_trusted!
  validate_dependencies_installed!

  lockfile.graph.locks.values
end

#lockfileLockfile

Get the lockfile corresponding to this Berksfile. This is necessary because the user can specify a different path to the Berksfile. So assuming the lockfile is named “Berksfile.lock” is a poor assumption.

Returns:

  • (Lockfile)

    the lockfile corresponding to this berksfile, or a new Lockfile if one does not exist



725
726
727
# File 'lib/berkshelf/berksfile.rb', line 725

def lockfile
  @lockfile ||= Lockfile.from_berksfile(self)
end

#metadata(options = {}) ⇒ Object

Use a Cookbook metadata file to determine additional cookbook dependencies to retrieve. All dependencies found in the metadata will use the default locations set in the Berksfile (if any are set) or the default locations defined by Berkshelf.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :path (String)

    path to the metadata file



174
175
176
177
178
179
180
# File 'lib/berkshelf/berksfile.rb', line 174

def (options = {})
  path          = options[:path] || File.dirname(filepath)
   = File.expand_path(File.join(path, "metadata.rb"))
        = Ridley::Chef::Cookbook::Metadata.from_file()

  add_dependency(.name, nil, path: path, metadata: true)
end

#outdated(*names) ⇒ Hash

List of all the cookbooks which have a newer version found at a source that satisfies the constraints of your dependencies.

Examples:

berksfile.outdated #=> {
  "nginx" => {
    "local" => #<Version 1.8.0>,
    "remote" => {
      #<Source uri: "https://supermarket.chef.io"> #=> #<Version 2.6.2>
    }
  }
}

Returns:

  • (Hash)

    a hash of cached cookbooks and their latest version grouped by their remote API source. The hash will be empty if there are no newer cookbooks for any of your dependencies (that still satisfy the given) constraints in the Berksfile.



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/berkshelf/berksfile.rb', line 507

def outdated(*names)
  validate_lockfile_present!
  validate_lockfile_trusted!
  validate_dependencies_installed!
  validate_cookbook_names!(names)

  lockfile.graph.locks.inject({}) do |hash, (name, dependency)|
    sources.each do |source|
      cookbooks = source.versions(name)

      latest = cookbooks.select do |cookbook|
        dependency.version_constraint.satisfies?(cookbook.version) &&
          Semverse::Version.coerce(cookbook.version) > dependency.locked_version
      end.sort_by { |cookbook| cookbook.version }.last

      unless latest.nil?
        hash[name] ||= {
          "local" => dependency.locked_version,
          "remote" => {
            source => Semverse::Version.coerce(latest.version),
          },
        }
      end
    end

    hash
  end
end

#package(path) ⇒ String

Package the given cookbook for distribution outside of berkshelf. If the name attribute is not given, all cookbooks in the Berksfile will be packaged.

Parameters:

  • path (String)

    the path where the tarball will be created

Returns:

  • (String)

    the path to the package

Raises:



611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/berkshelf/berksfile.rb', line 611

def package(path)
  packager = Packager.new(path)
  packager.validate!

  outdir = Dir.mktmpdir do |temp_dir|
    Berkshelf.ui.mute { vendor(File.join(temp_dir, "cookbooks")) }
    packager.run(temp_dir)
  end

  Berkshelf.formatter.package(outdir)
  outdir
end

#retrieve_locked(dependency) ⇒ CachedCookbook

Retrieve information about a given cookbook that is installed by this Berksfile. Unlike #find, which returns a dependency, this method returns the corresponding CachedCookbook for the given name.

Parameters:

  • name (Dependency)

    the name of the cookbook to find

Returns:

  • (CachedCookbook)

    the CachedCookbook that corresponds to the given name parameter

Raises:

  • (LockfileNotFound)

    if there is no lockfile containing that cookbook

  • (CookbookNotFound)

    if there is a lockfile with a cookbook, but the cookbook is not downloaded



468
469
470
# File 'lib/berkshelf/berksfile.rb', line 468

def retrieve_locked(dependency)
  lockfile.retrieve(dependency)
end

#site(*args) ⇒ Object

TODO:

remove in Berkshelf 4.0

Raises:



259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/berkshelf/berksfile.rb', line 259

def site(*args)
  if args.first == :opscode
    Berkshelf.formatter.deprecation "Your Berksfile contains a site location pointing to the Opscode Community " +
      "Site (site :opscode). Site locations have been replaced by the source location. Change this to: " +
      "'source \"https://supermarket.chef.io\"' to remove this warning. For more information visit " +
      "https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
    source(DEFAULT_API_URL)
    return
  end

  raise DeprecatedError.new "Your Berksfile contains a site location. Site locations have been " +
    " replaced by the source location. Please remove your site location and try again. For more information " +
    " visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations"
end

#solver(name, precedence = :preferred) ⇒ Object

Configure a specific engine for the ‘solve’ gem to use when computing dependencies. You may optionally specify how strong a requirement this is. If omitted, the default precedence is :preferred.

If :required is specified and cannot be loaded, Resolver#resolve will raise an ArgumentError. If :preferred is specified and cannot be loaded, Resolver#resolve silently catch any errors and use whatever default method the ‘solve’ gem provides (as of 2.0.1, solve defaults to :ruby).

Examples:

solver :gecode
solver :gecode, :preferred
solver :gecode, :required
solver :ruby
solver :ruby, :preferred
solver :ruby, :required

Parameters:

  • name (Symbol)

    name of engine for solver gem to use for depsolving

  • precedence (Symbol) (defaults to: :preferred)

    how strong a requirement using this solver is valid values are :required, :preferred

Raises:



230
231
232
233
234
235
236
237
238
# File 'lib/berkshelf/berksfile.rb', line 230

def solver(name, precedence = :preferred)
  if name && precedence == :required
    @required_solver = name
  elsif name && precedence == :preferred
    @preferred_solver = name
  else
    raise ArgumentError, "Invalid solver precedence ':#{precedence}'"
  end
end

#source(api_url, **options) ⇒ Array<Source>

Add a Berkshelf API source to use when building the index of known cookbooks. The indexes will be searched in the order they are added. If a cookbook is found in the first source then a cookbook in a second source would not be used.

Examples:

source "https://supermarket.chef.io"
source "https://berks-api.riotgames.com"

Parameters:

  • api_url (String)

    url for the api to add

  • options (Hash)

    extra source options

Returns:

Raises:



200
201
202
203
# File 'lib/berkshelf/berksfile.rb', line 200

def source(api_url, **options)
  source = Source.new(self, api_url, **options)
  @sources[source.uri.to_s] = source
end

#source_for(name, version) ⇒ Object

Parameters:

  • dependency (Dependency)

    the dependency to find the source for



252
253
254
# File 'lib/berkshelf/berksfile.rb', line 252

def source_for(name, version)
  sources.find { |source| source.cookbook(name, version) }
end

#sourcesArray<Source>

Returns:



242
243
244
245
246
247
248
# File 'lib/berkshelf/berksfile.rb', line 242

def sources
  if @sources.empty?
    raise NoAPISourcesDefined
  else
    @sources.values
  end
end

#update(*names) ⇒ Object

Update the given set of dependencies (or all if no names are given).

Parameters:

  • options (Hash)

    a customizable set of options



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/berkshelf/berksfile.rb', line 433

def update(*names)
  validate_lockfile_present!
  validate_cookbook_names!(names)

  Berkshelf.log.info "Updating cookbooks"

  # Calculate the list of cookbooks to unlock
  if names.empty?
    Berkshelf.log.debug "  Unlocking all the things!"
    lockfile.unlock_all
  else
    names.each do |name|
      Berkshelf.log.debug "  Unlocking #{name}"
      lockfile.unlock(name, true)
    end
  end

  # NOTE: We intentionally do NOT pass options to the installer
  install
end

#upload(names = []) ⇒ Array<CachedCookbook> #upload(names = [], options = {}) ⇒ Array<CachedCookbook>

Upload the cookbooks installed by this Berksfile

Examples:

Upload all cookbooks

berksfile.upload

Upload the ‘apache2’ and ‘mysql’ cookbooks

berksfile.upload('apache2', 'mysql')

Upload and freeze all cookbooks

berksfile.upload(freeze: true)

Upload and freeze the ‘chef-sugar` cookbook

berksfile.upload('chef-sugar', freeze: true)

Overloads:

  • #upload(names = []) ⇒ Array<CachedCookbook>

    Parameters:

    • names (Array<String>) (defaults to: [])

      the list of cookbooks (by name) to upload to the remote Chef Server

  • #upload(names = [], options = {}) ⇒ Array<CachedCookbook>

    Parameters:

    • names (Array<String>) (defaults to: [])

      the list of cookbooks (by name) to upload to the remote Chef Server

    • options (Hash<Symbol, Object>) (defaults to: {})

      the list of options to pass to the uploader

    Options Hash (options):

    • :force (Boolean) — default: false

      upload the cookbooks even if the version already exists and is frozen on the remote Chef Server

    • :freeze (Boolean) — default: true

      freeze the uploaded cookbooks on the remote Chef Server so that it cannot be overwritten on future uploads

    • :ssl_verify (Hash) — default: true

      use SSL verification while connecting to the remote Chef Server

    • :halt_on_frozen (Boolean) — default: false

      raise an exception (FrozenCookbook) if one of the cookbooks already exists on the remote Chef Server and is frozen

    • :server_url (String)

      the URL (endpoint) to the remote Chef Server

    • :client_name (String)

      the client name for the remote Chef Server

    • :client_key (String)

      the client key (pem) for the remote Chef Server

Returns:

  • (Array<CachedCookbook>)

    the list of cookbooks that were uploaded to the Chef Server

Raises:

  • (UploadFailure)

    if you are uploading cookbooks with an invalid or not-specified client key

  • (DependencyNotFound)

    if one of the given cookbooks is not a dependency defined in the Berksfile

  • (FrozenCookbook)

    if the cookbook being uploaded is a #metadata cookbook and is already frozen on the remote Chef Server; indirect dependencies or non-metadata dependencies are just skipped



592
593
594
595
596
597
598
# File 'lib/berkshelf/berksfile.rb', line 592

def upload(*args)
  validate_lockfile_present!
  validate_lockfile_trusted!
  validate_dependencies_installed!

  Uploader.new(self, *args).run
end

#vendor(destination) ⇒ String?

Install the Berksfile or Berksfile.lock and then sync the cached cookbooks into directories within the given destination matching their name.

Parameters:

  • destination (String)

    filepath to vendor cookbooks to

Returns:

  • (String, nil)

    the expanded path cookbooks were vendored to or nil if nothing was vendored



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
# File 'lib/berkshelf/berksfile.rb', line 632

def vendor(destination)
  Dir.mktmpdir("vendor") do |scratch|
    chefignore       = nil
    cached_cookbooks = install
     = []

    return nil if cached_cookbooks.empty?

    cached_cookbooks.each do |cookbook|
      Berkshelf.formatter.vendor(cookbook, destination)
      cookbook_destination = File.join(scratch, cookbook.cookbook_name)
      FileUtils.mkdir_p(cookbook_destination)

      # Dir.glob does not support backslash as a File separator
      src   = cookbook.path.to_s.tr('\\', "/")
      files = FileSyncer.glob(File.join(src, "*"))

      chefignore = Ridley::Chef::Chefignore.new(cookbook.path.to_s) rescue nil
      chefignore.apply!(files) if chefignore

      unless cookbook.compiled_metadata?
        cookbook.(cookbook_destination)
      end

       << File.join(cookbook.cookbook_name, "metadata.rb")

      FileUtils.cp_r(files, cookbook_destination)
    end

    # Don't vendor the raw metadata (metadata.rb). The raw metadata is
    # unecessary for the client, and this is required until compiled metadata
    # (metadata.json) takes precedence over raw metadata in the Chef-Client.
    #
    # We can change back to including the raw metadata in the future after
    # this has been fixed or just remove these comments. There is no
    # circumstance that I can currently think of where raw metadata should
    # ever be read by the client.
    #
    # - Jamie
    #
    # See the following tickets for more information:
    #
    #   * https://tickets.opscode.com/browse/CHEF-4811
    #   * https://tickets.opscode.com/browse/CHEF-4810
    FileSyncer.sync(scratch, destination, exclude:  + EXCLUDED_VCS_FILES_WHEN_VENDORING, delete: @delete)
  end

  destination
end

#verifyObject

Perform a validation with ‘Validator#validate` on each cached cookbook associated with the Lockfile of this Berksfile.

This function will return true or raise the first errors encountered.



686
687
688
689
690
691
692
# File 'lib/berkshelf/berksfile.rb', line 686

def verify
  validate_lockfile_present!
  validate_lockfile_trusted!
  Berkshelf.formatter.msg "Verifying (#{lockfile.cached.length}) cookbook(s)..."
  Validator.validate(lockfile.cached)
  true
end

#viz(outfile = nil, format = "png") ⇒ String

Visualize the current Berksfile as a “graph” using DOT.

Parameters:

  • outfile (String) (defaults to: nil)

    the name/path to outfile the file

Returns:

  • (String)

    path the path where the image was written



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'lib/berkshelf/berksfile.rb', line 701

def viz(outfile = nil, format = "png")
  outfile = File.join(Dir.pwd, outfile || "graph.png")

  validate_lockfile_present!
  validate_lockfile_trusted!
  vizualiser = Visualizer.from_lockfile(lockfile)

  case format
  when "dot"
    vizualiser.to_dot_file(outfile)
  when "png"
    vizualiser.to_png(outfile)
  else
    raise ConfigurationError, "Vizualiser format #{format} not recognised."
  end
end