berktacular 1.1.0 → 1.2.1
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 +4 -4
- data/VERSION +1 -1
- data/bin/berktacular +1 -7
- data/lib/berktacular/berksfile.rb +52 -11
- data/lib/berktacular/cookbook.rb +10 -9
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2b550dd28f7c682c8659d022921d89a65785053a
|
|
4
|
+
data.tar.gz: c1c53aeeb4858818ccddb394229c2f38d8d3caa8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 638e0ef1f4a61e6754482c2b371dc1167a4671d27e4c297867ef2f1674fa82381e49f3cf37e2c3bdca30b8ad02fc9bd85a166c98d88276808f23d803272eeceb
|
|
7
|
+
data.tar.gz: 548d71a31fd89eb2781657a40fe85f075e0b3a0faf4956cdad663f3212ce77e538a111a4fcdd5d80f1b785fba75f17c5d5f3052f74822de32c800b5b1f69daaa
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.1
|
|
1
|
+
1.2.1
|
data/bin/berktacular
CHANGED
|
@@ -118,12 +118,6 @@ unless env_file && File.exist?(env_file)
|
|
|
118
118
|
exit 2
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
my_env = JSON.parse( File.read( env_file ) )
|
|
122
|
-
if versions_only
|
|
123
|
-
# Ignore cookbook locations. Only include versions in the generated Berksfile.
|
|
124
|
-
my_env.delete('cookbook_locations')
|
|
125
|
-
end
|
|
126
|
-
|
|
127
121
|
unless github_token
|
|
128
122
|
if File.exists? gtoken_path
|
|
129
123
|
github_token = IO.read(gtoken_path).strip
|
|
@@ -162,7 +156,7 @@ puts "Using workdir: '#{workdir}'" if verbose
|
|
|
162
156
|
# Create a new berksfile
|
|
163
157
|
puts "Checking updates, this can take some time..." if check || upgrade
|
|
164
158
|
b = Berktacular::Berksfile.new(
|
|
165
|
-
|
|
159
|
+
env_file,
|
|
166
160
|
upgrade: upgrade,
|
|
167
161
|
github_token: github_token,
|
|
168
162
|
verbose: verbose,
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
require 'ostruct'
|
|
2
2
|
require 'json'
|
|
3
|
+
require 'solve'
|
|
4
|
+
|
|
5
|
+
# Taken from http://stackoverflow.com/a/25990044
|
|
6
|
+
class ::Hash
|
|
7
|
+
def deep_merge(second)
|
|
8
|
+
merger = proc { |key, v1, v2|
|
|
9
|
+
Hash === v1 && Hash === v2 ?
|
|
10
|
+
v1.merge(v2, &merger) :
|
|
11
|
+
[:undefined, nil, :nil].include?(v2) ? v1 : v2
|
|
12
|
+
}
|
|
13
|
+
self.merge(second, &merger)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
3
16
|
|
|
4
17
|
module Berktacular
|
|
5
18
|
|
|
@@ -25,19 +38,23 @@ module Berktacular
|
|
|
25
38
|
# @option opts [True,False] :verbose (False) be more verbose.
|
|
26
39
|
# @option opts [Array<String>] :source_list additional Berkshelf API sources to include in the
|
|
27
40
|
# generated Berksfile.
|
|
28
|
-
def initialize(
|
|
29
|
-
@env_hash = environment # Save the whole thing so we can emit an updated version if needed.
|
|
30
|
-
@name = environment['name'] || nil
|
|
31
|
-
@description = environment['description'] || nil
|
|
32
|
-
@cookbook_versions = environment['cookbook_versions'] || {}
|
|
33
|
-
@cookbook_locations = environment['cookbook_locations'] || {}
|
|
41
|
+
def initialize( env_path, opts = {})
|
|
34
42
|
@opts = {
|
|
35
|
-
:
|
|
36
|
-
:
|
|
37
|
-
:
|
|
38
|
-
:
|
|
39
|
-
:
|
|
43
|
+
upgrade: opts.has_key?(:upgrade) ? opts[:upgrade] : false,
|
|
44
|
+
github_token: opts.has_key?(:github_token) ? opts[:github_token] : nil,
|
|
45
|
+
verbose: opts.has_key?(:verbose) ? opts[:verbose] : false,
|
|
46
|
+
source_list: opts.has_key?(:source_list) ? opts[:source_list] : [],
|
|
47
|
+
multi_cookbook_dir: opts.has_key?(:multi_cookbook_dir) ? opts[:multi_cookbook_dir] : nil,
|
|
48
|
+
versions_only: opts.has_key?(:versions_only) ? opts[:versions_only] : false,
|
|
49
|
+
max_depth: opts.has_key?(:max_depth) ? opts[:max_depth] : 10
|
|
40
50
|
}
|
|
51
|
+
@counter = 0
|
|
52
|
+
@env_hash = expand_env_file(env_path)
|
|
53
|
+
|
|
54
|
+
@name = @env_hash['name'] || nil
|
|
55
|
+
@description = @env_hash['description'] || nil
|
|
56
|
+
@cookbook_versions = @env_hash['cookbook_versions'] || {}
|
|
57
|
+
@cookbook_locations = @env_hash['cookbook_locations'] || {}
|
|
41
58
|
@installed = {}
|
|
42
59
|
# only connect once, pass the client to each cookbook. and only if needed
|
|
43
60
|
connect_to_git if @opts[:upgrade]
|
|
@@ -225,6 +242,30 @@ module Berktacular
|
|
|
225
242
|
)
|
|
226
243
|
end
|
|
227
244
|
|
|
245
|
+
# recursively expand env_file @opts[:max_depth] times.
|
|
246
|
+
# @return [Hash] of merged env_file
|
|
247
|
+
def expand_env_file(env_file)
|
|
248
|
+
raise "Exceeded max depth!" if @counter > @opts[:max_depth]
|
|
249
|
+
@counter += 1
|
|
250
|
+
env = {}
|
|
251
|
+
if File.exists?(env_file)
|
|
252
|
+
env = JSON.parse( File.read(env_file) )
|
|
253
|
+
else
|
|
254
|
+
raise "Environment file '#{env_file}' does not exist!"
|
|
255
|
+
end
|
|
256
|
+
if env.has_key?("parent")
|
|
257
|
+
parent = env["parent"]
|
|
258
|
+
if !File.exists?(parent)
|
|
259
|
+
parent = File.join(
|
|
260
|
+
File.dirname(env_file),
|
|
261
|
+
parent
|
|
262
|
+
)
|
|
263
|
+
end
|
|
264
|
+
env = expand_env_file( parent ).deep_merge( env )
|
|
265
|
+
end
|
|
266
|
+
env
|
|
267
|
+
end
|
|
268
|
+
|
|
228
269
|
def metadata_from_json(json_str)
|
|
229
270
|
OpenStruct.new(JSON.parse(json_str))
|
|
230
271
|
end
|
data/lib/berktacular/cookbook.rb
CHANGED
|
@@ -32,7 +32,8 @@ module Berktacular
|
|
|
32
32
|
@version_solved = Semverse::Version.new(@version_number)
|
|
33
33
|
@auto_upgrade = config && config['auto_upgrade'] || false
|
|
34
34
|
@versions = config && config['versions'] || {}
|
|
35
|
-
@
|
|
35
|
+
@location = config ? config.reject{ |k,v| k == 'auto_upgrade' || k == 'versions' } : nil
|
|
36
|
+
@version_only = opts.has_key?(:versions_only) ? opts[:versions_only] : false
|
|
36
37
|
@upgrade = opts.has_key?(:upgrade) ? opts[:upgrade] : false
|
|
37
38
|
@git_client = opts.has_key?(:git_client) ? opts[:git_client].dup : nil
|
|
38
39
|
@verbose = opts.has_key?(:verbose) ? opts[:verbose] : false
|
|
@@ -58,15 +59,15 @@ module Berktacular
|
|
|
58
59
|
# param upgrade [True,False] ('@upgrade') whether or not to force the lastest version when @auto_update is enabled
|
|
59
60
|
# @return [String] a Berksfile line for this cookbook
|
|
60
61
|
def line(upgrade = @upgrade)
|
|
61
|
-
"cookbook \"#{@name}\", #{generate_conf_line(upgrade, @
|
|
62
|
+
"cookbook \"#{@name}\", #{generate_conf_line(upgrade, @location )}"
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
# @return [Array] a list of available cookbook version newer then we started with, with most recent first
|
|
65
66
|
def check_updates
|
|
66
67
|
tag_re = Regexp.new(
|
|
67
|
-
"^#{ (@
|
|
68
|
+
"^#{ (@location || {})['tag'] || '%{version}' }$" % { version: "(#{VERSION_RE.source})" }
|
|
68
69
|
)
|
|
69
|
-
@candidates ||= if @
|
|
70
|
+
@candidates ||= if @location && @location['github']
|
|
70
71
|
get_tags_from_github
|
|
71
72
|
else
|
|
72
73
|
[]
|
|
@@ -92,7 +93,7 @@ module Berktacular
|
|
|
92
93
|
def generate_conf_line(upgrade, config)
|
|
93
94
|
ver = (upgrade && @candidates && @candidates.first) || @version_number
|
|
94
95
|
line = []
|
|
95
|
-
if config
|
|
96
|
+
if config && ! @version_only
|
|
96
97
|
# Allow using coobkooks residing in subdirectories of a "multi-cookbook directory"
|
|
97
98
|
# (this can be e.g. the Chef repository) if the version matches.
|
|
98
99
|
if config.has_key?('rel') && @multi_cookbook_dir
|
|
@@ -117,10 +118,10 @@ module Berktacular
|
|
|
117
118
|
if @versions.has_key?(ver)
|
|
118
119
|
line << "ref: \"#{@versions[ver]['ref']}\""
|
|
119
120
|
else
|
|
120
|
-
if !@
|
|
121
|
+
if !@location.has_key?('tag')
|
|
121
122
|
line << "tag: \"#{ver}\""
|
|
122
123
|
else
|
|
123
|
-
line << "tag: \"#{@
|
|
124
|
+
line << "tag: \"#{@location['tag']}\""
|
|
124
125
|
end
|
|
125
126
|
end
|
|
126
127
|
else
|
|
@@ -132,9 +133,9 @@ module Berktacular
|
|
|
132
133
|
# return [Array] a list of tags from the github repository of this cookbook.
|
|
133
134
|
def get_tags_from_github
|
|
134
135
|
@@tags_cache ||= {}
|
|
135
|
-
repo_path = @
|
|
136
|
+
repo_path = @location['github']
|
|
136
137
|
return @@tags_cache[repo_path] if @@tags_cache[repo_path]
|
|
137
|
-
tags = @git_client.tags(@
|
|
138
|
+
tags = @git_client.tags(@location['github']).map { |obj| obj.name }
|
|
138
139
|
@@tags_cache[repo_path] = tags
|
|
139
140
|
tags
|
|
140
141
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: berktacular
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeff Harvey-Smith
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-10-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: solve
|
|
@@ -90,14 +90,14 @@ dependencies:
|
|
|
90
90
|
name: berkshelf
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
|
93
|
-
- - "
|
|
93
|
+
- - ">="
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '3.1'
|
|
96
96
|
type: :runtime
|
|
97
97
|
prerelease: false
|
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
|
100
|
-
- - "
|
|
100
|
+
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '3.1'
|
|
103
103
|
- !ruby/object:Gem::Dependency
|
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
165
165
|
version: '0'
|
|
166
166
|
requirements: []
|
|
167
167
|
rubyforge_project:
|
|
168
|
-
rubygems_version: 2.
|
|
168
|
+
rubygems_version: 2.4.8
|
|
169
169
|
signing_key:
|
|
170
170
|
specification_version: 4
|
|
171
171
|
summary: Parse chef env files, generates a Berksfile and verifies it.
|