chef-berksfile-env 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +191 -0
- data/VERSION +1 -0
- data/lib/chef-berksfile-env.rb +74 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cebb2a95fa35b7986b6a32c5f4f738d518bd6258
|
4
|
+
data.tar.gz: d6a132d622102305156486eb75775e7338b962ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec44bf227d0161fae92da35c6a99a4ba864aa457a57547ca463bd7351a8f20c611dad5780153b233fd322afbc0ff9224206b3e2b6a65d64c409cf55bf4c8aa53
|
7
|
+
data.tar.gz: e0531192d3eba832ae40c646bd74e8f2c9e072d435cfe2dff1156c3400e5212fc58bcb835a45af7fff24259a82543319d7423ac22ef9336047e9a72e1707cfed
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Chef-Berksfile-Env
|
2
|
+
==================
|
3
|
+
|
4
|
+
A Chef plugin which allows you to lock down your Chef Environment with a Berksfile.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
/opt/chef/embedded/bin/gem install chef-berksfile-env
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
In your chef repo create a Berksfile next to your Chef environment file like this,
|
15
|
+
|
16
|
+
chef-repo/environments/[ENV_NAME]/Berksfile
|
17
|
+
|
18
|
+
This is the default location that will used by the plugin. We have to put the berkshelf in its own
|
19
|
+
directory since [multiple berksfiles can't exist in the same directory](https://github.com/berkshelf/berkshelf/issues/1247).
|
20
|
+
|
21
|
+
The berksfile should include any cookbooks that your nodes or roles explicitly mention for that environment,
|
22
|
+
|
23
|
+
source "https://supermarket.getchef.com"
|
24
|
+
|
25
|
+
cookbook "java"
|
26
|
+
cookbook "yum", "~> 2.0"
|
27
|
+
...
|
28
|
+
|
29
|
+
Next we need to generate our Berksfile's lock file,
|
30
|
+
|
31
|
+
berks install
|
32
|
+
|
33
|
+
Your environment file must by in `.rb` format and look like this,
|
34
|
+
|
35
|
+
require 'chef-berksfile-env'
|
36
|
+
|
37
|
+
# This must be define before we do load_berksfile
|
38
|
+
name "my_env"
|
39
|
+
|
40
|
+
# Load Berksfile locked dependencies as my environments version contraints
|
41
|
+
load_berksfile
|
42
|
+
|
43
|
+
...
|
44
|
+
|
45
|
+
Now our environment will only use the locked versions of the cookbooks generated by our Berksfile. Additionally
|
46
|
+
Berkshelf has also locked all transitive dependencies for us as well. Upgrading to the latest dependecies is now as simple as,
|
47
|
+
|
48
|
+
berks install
|
49
|
+
|
50
|
+
Our Berksfile also provides an easy way to ensure all the cookbooks and their versions that our environment requires
|
51
|
+
are uploaded to our chef-server,
|
52
|
+
|
53
|
+
berks upload
|
data/Rakefile
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'octokit'
|
3
|
+
|
4
|
+
VERSION_WITH_NAME_REGEX = /version\s*'\d+\.\d+\.\d+'/
|
5
|
+
VERSION_REGEX = /\d+\.\d+\.\d+/
|
6
|
+
|
7
|
+
REPO = "bbaugher/chef-berksfile-env"
|
8
|
+
|
9
|
+
task :release do
|
10
|
+
version = plugin_version
|
11
|
+
|
12
|
+
# Update change log
|
13
|
+
puts "Updating change log ..."
|
14
|
+
update_change_log version
|
15
|
+
puts "Change log updated!"
|
16
|
+
|
17
|
+
# Share the plugin
|
18
|
+
deploy
|
19
|
+
|
20
|
+
# Tag the release
|
21
|
+
puts "Tagging the #{version} release ..."
|
22
|
+
run_command "git tag -a #{version} -m 'Released #{version}'"
|
23
|
+
run_command "git push origin #{version}"
|
24
|
+
puts "Release tagged!"
|
25
|
+
|
26
|
+
# Bump version
|
27
|
+
versions = version.split "."
|
28
|
+
versions[1] = versions[1].to_i + 1
|
29
|
+
|
30
|
+
# Reset bug number if available
|
31
|
+
if versions.size == 3
|
32
|
+
versions[2] = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
new_version = versions.join "."
|
36
|
+
|
37
|
+
puts "Updating version from #{version} to #{new_version} ..."
|
38
|
+
update_plugin_version new_version
|
39
|
+
puts "Version updated!"
|
40
|
+
|
41
|
+
# Commit the updated VERSION file
|
42
|
+
puts "Commiting the new version ..."
|
43
|
+
run_command "git add VERSION"
|
44
|
+
run_command "git commit -m 'Released #{version} and bumped version to #{new_version}'"
|
45
|
+
run_command "git push origin HEAD"
|
46
|
+
puts "Version commited!"
|
47
|
+
end
|
48
|
+
|
49
|
+
task :build_change_log do
|
50
|
+
closed_milestones = Octokit.milestones REPO, {:state => "closed"}
|
51
|
+
|
52
|
+
version_to_milestone = Hash.new
|
53
|
+
versions = Array.new
|
54
|
+
|
55
|
+
closed_milestones.each do |milestone|
|
56
|
+
version = Gem::Version.new(milestone.title)
|
57
|
+
version_to_milestone.store version, milestone
|
58
|
+
versions.push version
|
59
|
+
end
|
60
|
+
|
61
|
+
versions = versions.sort.reverse
|
62
|
+
|
63
|
+
change_log = File.open('CHANGELOG.md', 'w')
|
64
|
+
|
65
|
+
begin
|
66
|
+
change_log.write "Change Log\n"
|
67
|
+
change_log.write "==========\n"
|
68
|
+
change_log.write "\n"
|
69
|
+
|
70
|
+
versions.each do |version|
|
71
|
+
milestone = version_to_milestone[version]
|
72
|
+
change_log.write generate_milestone_markdown(milestone)
|
73
|
+
change_log.write "\n"
|
74
|
+
end
|
75
|
+
ensure
|
76
|
+
change_log.close
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def plugin_version
|
81
|
+
IO.read("VERSION")
|
82
|
+
end
|
83
|
+
|
84
|
+
def build_gem
|
85
|
+
puts "Building the gem ..."
|
86
|
+
run_command "gem build chef-berksfile-env.gemspec"
|
87
|
+
puts "Gem built!"
|
88
|
+
end
|
89
|
+
|
90
|
+
def deploy
|
91
|
+
begin
|
92
|
+
build_gem
|
93
|
+
|
94
|
+
puts "Publishing the gem ..."
|
95
|
+
run_command "gem push chef-berksfile-env*.gem"
|
96
|
+
puts "Gem published!"
|
97
|
+
ensure
|
98
|
+
system "rm -f chef-berksfile-env*.gem"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def update_plugin_version version
|
103
|
+
File.open("VERSION", 'w') { |file| file.write(version) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def update_change_log version
|
107
|
+
change_log_lines = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).split("\n")
|
108
|
+
|
109
|
+
change_log = File.open('CHANGELOG.md', 'w')
|
110
|
+
|
111
|
+
begin
|
112
|
+
|
113
|
+
# Keep change log title
|
114
|
+
change_log.write change_log_lines.shift
|
115
|
+
change_log.write "\n"
|
116
|
+
change_log.write change_log_lines.shift
|
117
|
+
change_log.write "\n"
|
118
|
+
change_log.write "\n"
|
119
|
+
|
120
|
+
# Write new milestone info
|
121
|
+
change_log.write generate_milestone_markdown(milestone(version))
|
122
|
+
|
123
|
+
# Add previous change log info
|
124
|
+
change_log_lines.each do |line|
|
125
|
+
change_log.write line
|
126
|
+
change_log.write "\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
ensure
|
130
|
+
change_log.close
|
131
|
+
end
|
132
|
+
|
133
|
+
run_command "git add CHANGELOG.md"
|
134
|
+
run_command "git commit -m 'Added #{version} to change log'"
|
135
|
+
run_command "git push origin HEAD"
|
136
|
+
end
|
137
|
+
|
138
|
+
def generate_milestone_markdown milestone
|
139
|
+
strings = Array.new
|
140
|
+
|
141
|
+
title = "[#{milestone.title} - #{milestone.updated_at.strftime("%m-%d-%Y")}](https://github.com/#{REPO}/issues?milestone=#{milestone.number}&state=closed)"
|
142
|
+
|
143
|
+
strings.push "#{title}"
|
144
|
+
strings.push "-" * title.length
|
145
|
+
strings.push ""
|
146
|
+
|
147
|
+
issues = Octokit.issues REPO, {:milestone => milestone.number, :state => "closed"}
|
148
|
+
|
149
|
+
issues.each do |issue|
|
150
|
+
strings.push " * [#{issue_type issue}] [Issue-#{issue.number}](https://github.com/#{REPO}/issues/#{issue.number}) : #{issue.title}"
|
151
|
+
end
|
152
|
+
|
153
|
+
strings.push ""
|
154
|
+
|
155
|
+
strings.join "\n"
|
156
|
+
end
|
157
|
+
|
158
|
+
def milestone version
|
159
|
+
closedMilestones = Octokit.milestones REPO, {:state => "closed"}
|
160
|
+
|
161
|
+
closedMilestones.each do |milestone|
|
162
|
+
if milestone["title"] == version
|
163
|
+
return milestone
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
openMilestones = Octokit.milestones REPO
|
168
|
+
|
169
|
+
openMilestones.each do |milestone|
|
170
|
+
if milestone["title"] == version
|
171
|
+
return milestone
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
raise "Unable to find milestone with title [#{version}]"
|
176
|
+
end
|
177
|
+
|
178
|
+
def issue_type issue
|
179
|
+
labels = Array.new
|
180
|
+
issue.labels.each do |label|
|
181
|
+
labels.push label.name.capitalize
|
182
|
+
end
|
183
|
+
labels.join "/"
|
184
|
+
end
|
185
|
+
|
186
|
+
def run_command command
|
187
|
+
output = `#{command}`
|
188
|
+
unless $?.success?
|
189
|
+
raise "Command : [#{command}] failed.\nOutput : \n#{output}"
|
190
|
+
end
|
191
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'chef/environment'
|
2
|
+
require 'berkshelf'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
# Ruby metaprogamming, yay!
|
6
|
+
class Chef
|
7
|
+
class Environment
|
8
|
+
|
9
|
+
def load_berksfile(path=nil)
|
10
|
+
raise "You must define the environment name before doing load_berksfile" if path.nil? && name.empty?
|
11
|
+
|
12
|
+
berksfile_path = path.nil? ? "environments/#{name}/Berksfile" : path
|
13
|
+
Chef::Log.debug("Using Berksfile path [#{berksfile_path}]")
|
14
|
+
|
15
|
+
begin
|
16
|
+
berksfile = ::Berkshelf::Berksfile.new find_berksfile(berksfile_path)
|
17
|
+
|
18
|
+
berksfile.list.each do |dependency|
|
19
|
+
cookbook dependency.name, "= #{dependency.locked_version.to_s}"
|
20
|
+
end
|
21
|
+
rescue ::Berkshelf::LockfileNotFound => e
|
22
|
+
raise "Your Berkshelf file [#{path}] has not been locked. Run 'berks install' to lock it"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def find_berksfile berksfile_path
|
30
|
+
|
31
|
+
if Pathname.new(berksfile_path).absolute?
|
32
|
+
validate_berksfile_exists berksfile_path
|
33
|
+
return berksfile_path
|
34
|
+
end
|
35
|
+
|
36
|
+
execution_dir = Dir.pwd
|
37
|
+
|
38
|
+
berksfile_dirs = berksfile_path.split("/")
|
39
|
+
berksfile = berksfile_dirs.pop
|
40
|
+
|
41
|
+
dirs = berksfile_dirs.size
|
42
|
+
|
43
|
+
berksfile_dir = ''
|
44
|
+
|
45
|
+
for i in 0..(berksfile_dirs.size - 1)
|
46
|
+
berksfile_dir += berksfile_dirs[i]
|
47
|
+
|
48
|
+
if execution_dir.end_with? berksfile_dir
|
49
|
+
path = File.join(execution_dir, *berksfile_dirs[i+1,berksfile_dirs.size], berksfile)
|
50
|
+
Chef::Log.debug("Relative berksfile path merges with execution directory at [#{path}]")
|
51
|
+
|
52
|
+
validate_berksfile_exists path
|
53
|
+
|
54
|
+
return path
|
55
|
+
end
|
56
|
+
|
57
|
+
berksfile_dir += '/'
|
58
|
+
end
|
59
|
+
|
60
|
+
# We are pretty much guessing at this point, good luck
|
61
|
+
path = File.expand_path(File.join(Dir.pwd, berksfile_path))
|
62
|
+
Chef::Log.debug("Guessing Berksfile path to be [#{path}]")
|
63
|
+
|
64
|
+
validate_berksfile_exists path
|
65
|
+
|
66
|
+
path
|
67
|
+
end
|
68
|
+
|
69
|
+
def validate_berksfile_exists path
|
70
|
+
raise "Expected Berksfile at [#{path}] but does not exist" unless File.exists? path
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-berksfile-env
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bryan Baugher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: berkshelf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chef
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: octokit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: "Chef-Berksfile-Env\n==================\n\nA Chef plugin which allows
|
84
|
+
you to lock down your Chef Environment with a Berksfile.\n\nInstallation\n------------\n\n
|
85
|
+
\ /opt/chef/embedded/bin/gem install chef-berksfile-env\n\nUsage\n-----\n\nIn
|
86
|
+
your chef repo create a Berksfile next to your Chef environment file like this,\n\n
|
87
|
+
\ chef-repo/environments/[ENV_NAME]/Berksfile\n\nThis is the default location
|
88
|
+
that will used by the plugin. We have to put the berkshelf in its own\ndirectory
|
89
|
+
since [multiple berksfiles can't exist in the same directory](https://github.com/berkshelf/berkshelf/issues/1247).
|
90
|
+
\n\nThe berksfile should include any cookbooks that your nodes or roles explicitly
|
91
|
+
mention for that environment,\n\n source \"https://supermarket.getchef.com\"\n\n
|
92
|
+
\ cookbook \"java\"\n cookbook \"yum\", \"~> 2.0\"\n ...\n\nNext we need
|
93
|
+
to generate our Berksfile's lock file,\n\n berks install\n\nYour environment
|
94
|
+
file must by in `.rb` format and look like this,\n\n require 'chef-berksfile-env'\n
|
95
|
+
\ \n # This must be define before we do load_berksfile\n name \"my_env\"\n
|
96
|
+
\ \n # Load Berksfile locked dependencies as my environments version contraints\n
|
97
|
+
\ load_berksfile\n\n ...\n\nNow our environment will only use the locked versions
|
98
|
+
of the cookbooks generated by our Berksfile. Additionally\nBerkshelf has also locked
|
99
|
+
all transitive dependencies for us as well. Upgrading to the latest dependecies
|
100
|
+
is now as simple as,\n\n berks install\n\nOur Berksfile also provides an easy
|
101
|
+
way to ensure all the cookbooks and their versions that our environment requires
|
102
|
+
\nare uploaded to our chef-server,\n\n berks upload"
|
103
|
+
email:
|
104
|
+
- bryan.baugher@cerner.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- lib/chef-berksfile-env.rb
|
110
|
+
- Gemfile
|
111
|
+
- Rakefile
|
112
|
+
- README.md
|
113
|
+
- VERSION
|
114
|
+
homepage: http://github.com/bbaugher/chef-berksfile-env
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.0.14
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: A Chef plugin to lock down your Chef Environment with a Berksfile
|
138
|
+
test_files: []
|
139
|
+
has_rdoc:
|