What exactly does "berks update <cookbook-name>" do?

Stephen C picture Stephen C · Jan 10, 2014 · Viewed 7.3k times · Source

According to "berks help update", the command is supposed to:

"Update the cookbooks (and dependencies) specified in the Berksfile"

(Yes ... that's all it says!).

But what exactly does this mean?

And how does this vary with different kinds of "cookbook" specification in your Berksfile?

Answer

sethvargo picture sethvargo · Jan 13, 2014

The update command will attempt to find the newest versions of each cookbook (that still meet any version requirements you've defined). For example, suppose you have the following Berksfile:

cookbook 'foo', '~> 1.0.0'

This tells Berkshelf to accept any version in the 1.0.x series. So you run berks install and (hypothetically) foo-1.0.5 is installed into your local berkshelf. The lockfile will "lock" the definition for foo at version 1.0.5, so other developers and future installs will always use version 1.0.5 (that's the entire point of the lockfile).

(A few months pass by...)

Now you want to update the cookbook to the latest version. But because of SemVer, you want to remain in the 1.0.x series. Running berks update will unlock the hard dependency in the lockfile, but keep the constraint in the Berksfile. So (hypothetically), if the community site had the following foo cookbook versions:

  • 1.0.5
  • 1.0.6
  • 1.0.8
  • 1.1.0
  • 2.0.0

berks update would update your local version to 1.0.8, since that's the latest published version that still satisfies your constraint.