Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to use lockfile directly #3

Merged
merged 1 commit into from
Sep 15, 2015

Conversation

jsirex
Copy link
Contributor

@jsirex jsirex commented Sep 15, 2015

It gives good possibility to update environment from CI server.
Method load_berksfile_lock skips all validations and uses lock file directly.
For example CI server always requires to do berks install because, some of cookbooks might be not present on CI server. Also this works much faster.

Also, I think its better to not modify or auto-complete path. Because an chef-environment.rb is a ruby file, we always able to calculate right path to Berkshelf or Berkshelf.lock.

In our case we're have environments folder in chef repo. Each environment described by 3 files:

  • - berksfile
  • .rb - chef environment file
  • .lock - berksfile lock

staging:

source 'https://supermarket.chef.io'
source 'http://company-berkshelf-api'

group :common do
  cookbook 'proj-base'
  cookbook 'proj-java', '~> 2.0'
  cookbook 'proj-chef', '~> 0.1'
end

group :balancer do
  cookbook 'proj-haproxy', '~> 2.4'
end

staging.rb

require 'chef-berksfile-env'

name 'staging'
default_attributes(...)
override_attributes(...)
# Cookbook Constraints from Berksfile
load_berksfile File.basename(__FILE__, '.rb')
# or with this PR
# load_berksfile_lock File.basename(__FILE__, '.rb') + '.lock'

Now you can do something like:

berks install -b staging # resolve all
berks update chef -b dev # update chef on dev
knife environment from file staging.rb # apply env
berks apply staging -b staging.lock # trick to update only versions

It gives good possibility to update environment from CI server.
Method load_berksfile_lock skips all validations and uses lock file
directly. For example CI server always requires to do `berks install`
because, some of cookbooks might be not present on CI server.
Also this works much faster.
@bbaugher
Copy link
Owner

Now that Berkshelf supports the lock file with the same name and it seems __FILE__ will resolve to the actual ruby file unlike what I thought it would be pretty easy to change the logic to expect the Berksfile to live right next to the environment with the same name as you suggest. This was what I was hoping to do originally.

I'm fine merging this though

bbaugher added a commit that referenced this pull request Sep 15, 2015
Add ability to use lockfile directly
@bbaugher bbaugher merged commit c36425c into bbaugher:master Sep 15, 2015
@bbaugher bbaugher added this to the 1.2.0 milestone Sep 15, 2015
@bbaugher
Copy link
Owner

This was released as 1.2.0 (https://rubygems.org/gems/chef-berksfile-env/versions/1.2.0)

@jsirex jsirex deleted the feature/load_lockfile branch September 15, 2015 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants