(DuplicateDependencyDefined)
- if a dependency is added whose name conflicts
Options Hash: (**options)
:git
(String)
--
:path
(String)
--
:group
(Symbol, Array)
--
Parameters:
constraint
(String, Semverse::Constraint)
--
name
(String)
--
defadd_dependency(name,constraint=nil,options={})if@dependencies[name]# Only raise an exception if the dependency is a true duplicategroups=(options[:group].nil?||options[:group].empty?)?[:default]:options[:group]unless(@dependencies[name].groups&groups).empty?raiseDuplicateDependencyDefined.new(name)endend# this appears to be dead code# if options[:path]# metadata_file = File.join(options[:path], "metadata.rb")# endoptions[:constraint]=constraint@dependencies[name]=Dependency.new(self,name,options)end
Example: a cookbook dependency that will be retrieved from a Git server - Example: a cookbook dependency that will be retrieved from a path on disk - Example: a cookbook dependency that will be retrieved from one of the default locations -
defextension(name)require"berkshelf/#{name}"truerescueLoadErrorraiseLoadError,"Could not load an extension by the name `#{name}'. "\"Please make sure it is installed."end
deffrom_options(options={})options[:berksfile]||=File.join(Dir.pwd,Berkshelf::DEFAULT_FILENAME)symbolized=Hash[options.map{|k,v|[k.to_sym,v]}]from_file(options[:berksfile],symbolized.select{|k,|%i{except only delete}.include?k})end
definitialize(path,options={})@filepath=File.expand_path(path)@dependencies={}@sources={}@delete=options[:delete]# defaults for what solvers to use@required_solver=nil@preferred_solver=:gecodeifoptions[:except]&&options[:only]raiseArgumentError,"Cannot specify both :except and :only!"elsifoptions[:except]except=Array(options[:except]).collect(&:to_sym)@filter=->(dependency){(except&dependency.groups).empty?}elsifoptions[:only]only=Array(options[:only]).collect(&:to_sym)@filter=->(dependency){!(only&dependency.groups).empty?}else@filter=->(dependency){true}endend
defupdate(*names)validate_lockfile_present!validate_cookbook_names!(names)Berkshelf.log.info"Updating cookbooks"# Calculate the list of cookbooks to unlockifnames.empty?Berkshelf.log.debug" Unlocking all the things!"lockfile.unlock_allelsenames.eachdo|name|Berkshelf.log.debug" Unlocking #{name}"lockfile.unlock(name,true)endend# NOTE: We intentionally do NOT pass options to the installerinstallend
def upload(*args)
Returns:
(Array)
-
Raises:
(FrozenCookbook)
-
(DependencyNotFound)
-
(UploadFailure)
-
Other tags:
Example: Upload and freeze the `chef-sugar` cookbook - Example: Upload and freeze all cookbooks - Example: Upload the 'apache2' and 'mysql' cookbooks - Example: Upload all cookbooks -
defvendor(destination)Dir.mktmpdir("vendor")do|scratch|cached_cookbooks=installreturnnilifcached_cookbooks.empty?cached_cookbooks.eachdo|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 separatorsrc=cookbook.path.to_s.tr("\\","/")files=FileSyncer.glob(File.join(src,"**/*"))# strip directoriesfiles.reject!{|file_path|File.directory?(file_path)}# convert to relative Pathname objects for chefignorefiles.map!{|file_path|Chef::Util::PathHelper.relative_path_from(cookbook.path.to_s,file_path)}chefignore=Chef::Cookbook::Chefignore.new(find_chefignore(cookbook.path.to_s)||cookbook.path.to_s)# apply chefignorefiles.reject!{|file_path|chefignore.ignored?(file_path)}# convert Pathname objects back to stringsfiles.map!(&:to_s)# copy each file to destinationfiles.eachdo|rpath|FileUtils.mkdir_p(File.join(cookbook_destination,File.dirname(rpath)))FileUtils.cp(File.join(cookbook.path.to_s,rpath),File.join(cookbook_destination,rpath))endcookbook.compile_metadata(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-4810FileSyncer.sync(scratch,destination,exclude: EXCLUDED_VCS_FILES_WHEN_VENDORING,delete: @delete)enddestinationend
def verify
This function will return true or raise the first errors encountered.
with the Lockfile of this Berksfile. Perform a validation with `Validator#validate` on each cached cookbook associated
defviz(outfile=nil,format="png")outfile=File.join(Dir.pwd,outfile||"graph.png")validate_lockfile_present!validate_lockfile_trusted!vizualiser=Visualizer.from_lockfile(lockfile)caseformatwhen"dot"vizualiser.to_dot_file(outfile)when"png"vizualiser.to_png(outfile)elseraiseConfigurationError,"Vizualiser format #{format} not recognised."endend