berktacular 0.1.7 → 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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDFmMmEyZGYyYzFhNTYzYWM4YTAyMjNkMjZiODU1ZjZiMzEyMzg3MA==
5
- data.tar.gz: !binary |-
6
- ZDZhYWRhMDM3MmIxMzM3M2ZmYzE0NTVmNzgyMWQ4MjgyN2VlNTMzNQ==
2
+ SHA1:
3
+ metadata.gz: f6406cbc6a3da17b4bf06d75953d84b6ab648b08
4
+ data.tar.gz: f05fdf6ac3fc1087f94b0147280c254d083f4f0f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MmY5YmEwYzkzYzIwZjlhMjU4YzhkZTZmNzFhY2FhMWUwODc3Y2QyOGM1YzUy
10
- NWI1OWRjZTk4YjZkZDJkNGI1OGRiOTUwMzZmZDhiNGI2YTYzMGY4YWFiNGM5
11
- ZTFhYTMwMGNlNjhhMThjMjI0NDNiMjIxZWEzMjdkM2Q2OGE1YTI=
12
- data.tar.gz: !binary |-
13
- YmRkMzhhMDY0ZWQ3NTQ5Yzc1NDY2MjI1MmQxZmY1YjBmZmY0MDhjMGI0ZDU5
14
- MzJiYzBiMGQ4ZjYyYTNjNGI0YWIyM2ZjOThiOGFhODE3ZjZjYjUzM2JmMWQw
15
- YTUzNDg0ZDYwMjAwZmFjOWEwNDlmZDM4MzBjNGIwMjM4MWZmNzU=
6
+ metadata.gz: e4c097ae8d61574ea027f200ab651294b3f3045dce6e81434e6f7b8c55f16b5476ae6d0f15770c1b15afe06eca9592c2e2c16be0bc71f994dd4da71fe21a7600
7
+ data.tar.gz: 5b3c6047f2c51cd241423ea341586273b14e3b5f2940b14a678bc11bdd0c2a9e9f314533b48cb612cb5aee1ace1a27706752ecd1417c9e410f4a8505f098c67a
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/bin/berktacular CHANGED
@@ -19,6 +19,8 @@ berks_conf = nil
19
19
  knife_conf = nil
20
20
  workdir = nil
21
21
  verbose = false
22
+ source_list = []
23
+ versions_only = false
22
24
 
23
25
  options = OptionParser.new do |opts|
24
26
  opts.banner = "Read environment json file and spit out a berksfile"
@@ -66,9 +68,21 @@ options = OptionParser.new do |opts|
66
68
  workdir = w
67
69
  preserve = true
68
70
  end
71
+ opts.on("-s", "--source SOURCE", String,
72
+ "Add this source to the generated Berksfile in addition to the default source",
73
+ "(https://api.berkshelf.com). This may be e.g. an internal Berkshelf API server URL.",
74
+ "This option can be used multiple times. Custom sources are always included before the ",
75
+ "default source, unless the default source is explicitly specified using this option.") do |s|
76
+ source_list << s
77
+ end
69
78
  opts.on("-v", "--verbose", "Turn on verbose output" ) do
70
79
  verbose = true
71
80
  end
81
+ opts.on("--versions-only",
82
+ "Include only cookbook versions in the Berksfile (no protocol or git URL).",
83
+ "This can be used with --source to download cookbooks using an API server.") do
84
+ versions_only = true
85
+ end
72
86
  opts.on("--version", "Print the version and exit" ) do
73
87
  puts Berktacular::VERSION
74
88
  exit 0
@@ -97,6 +111,10 @@ unless env_file && File.exist?(env_file)
97
111
  end
98
112
 
99
113
  my_env = JSON.parse( File.read( env_file ) )
114
+ if versions_only
115
+ # Ignore cookbook locations. Only include versions in the generated Berksfile.
116
+ my_env.delete('cookbook_locations')
117
+ end
100
118
 
101
119
  unless github_token
102
120
  if File.exists? gtoken_path
@@ -129,9 +147,15 @@ puts "Using workdir: '#{workdir}'" if verbose
129
147
 
130
148
  # Create a new berksfile
131
149
  puts "Checking updates, this can take some time..." if check || upgrade
132
- b = Berktacular::Berksfile.new(my_env, upgrade: upgrade, github_token: github_token, verbose: verbose)
133
- b.check_updates if check
134
- puts "#{b}" if printit
150
+ b = Berktacular::Berksfile.new(
151
+ my_env,
152
+ upgrade: upgrade,
153
+ github_token: github_token,
154
+ verbose: verbose,
155
+ source_list: source_list
156
+ )
157
+ b.check_updates if check
158
+ puts "#{b}" if printit
135
159
  if berksfile
136
160
  FileUtils.mkdir_p( File.dirname(berksfile) )
137
161
  File.write(berksfile, b)
@@ -1,3 +1,6 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+
1
4
  module Berktacular
2
5
 
3
6
  # This class represents a Berksfile
@@ -20,6 +23,8 @@ module Berktacular
20
23
  # @option opts [String] :github_token (nil) the github token to use.
21
24
  # @option opts [True,False] :upgrade (False) whether or not to check for upgraded cookbooks.
22
25
  # @option opts [True,False] :verbose (False) be more verbose.
26
+ # @option opts [Array<String>] :source_list additional Berkshelf API sources to include in the
27
+ # generated Berksfile.
23
28
  def initialize( environment, opts = {})
24
29
  @env_hash = environment # Save the whole thing so we can emit an updated version if needed.
25
30
  @name = environment['name'] || nil
@@ -29,11 +34,13 @@ module Berktacular
29
34
  @opts = {
30
35
  :upgrade => opts.has_key?(:upgrade) ? opts[:upgrade] : false,
31
36
  :github_token => opts.has_key?(:github_token) ? opts[:github_token] : nil,
32
- :verbose => opts.has_key?(:verbose) ? opts[:verbose] : false
37
+ :verbose => opts.has_key?(:verbose) ? opts[:verbose] : false,
38
+ :source_list => opts.has_key?(:source_list) ? opts[:source_list] : []
33
39
  }
34
40
  @installed = {}
35
41
  # only connect once, pass the client to each cookbook. and only if needed
36
42
  connect_to_git if @opts[:upgrade]
43
+ @opts[:source_list] = (@opts[:source_list] + ["https://api.berkshelf.com"]).uniq
37
44
  end
38
45
 
39
46
  # @return [Hash] representation of the env_file.
@@ -71,7 +78,7 @@ module Berktacular
71
78
  cookbooks = File.join(workdir, "cookbooks")
72
79
  FileUtils.rm(lck) if File.exists? lck
73
80
  File.write(berksfile, self)
74
- Berktacular.run_command("berks install --berksfile #{berksfile} --path #{cookbooks}")
81
+ Berktacular.run_command("berks vendor --berksfile #{berksfile} #{cookbooks}")
75
82
  @installed[workdir] = {berksfile: berksfile, lck: lck, cookbooks: cookbooks}
76
83
  end
77
84
  workdir
@@ -87,10 +94,14 @@ module Berktacular
87
94
  dependencies = {}
88
95
  Dir["#{@installed[workdir][:cookbooks]}/*"].each do |cookbook_dir|
89
96
  next unless File.directory?(cookbook_dir)
90
- metadata_path = File.join(cookbook_dir, 'metadata.rb')
91
- metadata = Ridley::Chef::Cookbook::Metadata.from_file(metadata_path)
92
- cookbook_name = metadata.name
93
- name_from_path = File.basename(cookbook_dir)
97
+ metadata_candidates = ['rb', 'json'].map {|ext| File.join(cookbook_dir, "metadata.#{ext}") }
98
+ metadata_path = metadata_candidates.find {|f| File.exists?(f) }
99
+ raise "Metadata file not found: #{metadata_candidates}" if metadata_path.nil?
100
+ metadata =
101
+ metadata_path =~ /\.json$/ ? metadata_from_json(IO.read(metadata_path)) :
102
+ Ridley::Chef::Cookbook::Metadata.from_file(metadata_path)
103
+ cookbook_name = metadata.name
104
+ name_from_path = File.basename(cookbook_dir)
94
105
  unless cookbook_name == name_from_path
95
106
  if cookbook_name.empty?
96
107
  puts "Cookbook #{name_from_path} has no name specified in metadata.rb"
@@ -112,14 +123,24 @@ module Berktacular
112
123
  @missing_deps[name] = "#{name}-#{versions[name]} depends on #{dep_name} which was not installed!"
113
124
  warn @missing_deps[name]
114
125
  errors = true
115
- elsif !Solve::Constraint.new(constraint).satisfies?(actual_version)
116
- @missing_deps[name] = "#{name}-#{versions[name]} depends on #{dep_name} #{constraint} but #{dep_name} is #{actual_version}!"
117
- warn @missing_deps[name]
118
- errors = true
126
+ elsif constraint != [] # some cookbooks have '[]' as a dependency in their json metadata
127
+ constraint_obj = begin
128
+ Semverse::Constraint.new(constraint)
129
+ rescue Semverse::InvalidConstraintFormat => ex
130
+ warn "Could not parse version constraint '#{constraint}' " +
131
+ "for dependency '#{dep_name}' of cookbook '#{name}'"
132
+ raise ex
133
+ end
134
+
135
+ unless constraint_obj.satisfies?(actual_version)
136
+ @missing_deps[name] = "#{name}-#{versions[name]} depends on #{dep_name} #{constraint} but #{dep_name} is #{actual_version}!"
137
+ warn @missing_deps[name]
138
+ errors = true
139
+ end
119
140
  end
120
141
  end
121
142
  end
122
- !errors
143
+ !errors
123
144
  end
124
145
 
125
146
  # @param berks_conf [String] path to the berkshelf config file to use.
@@ -151,7 +172,7 @@ module Berktacular
151
172
 
152
173
  # @param [IO] where to write the data.
153
174
  def print_berksfile( io = STDOUT )
154
- io.puts to_s
175
+ io.puts to_s
155
176
  end
156
177
 
157
178
  # @return [String] the berksfile as a String object
@@ -162,7 +183,10 @@ module Berktacular
162
183
  str << "# This file is auto-generated, changes will be overwritten\n"
163
184
  str << "# Modify the .json environment file and regenerate this Berksfile to make changes.\n\n"
164
185
 
165
- str << "site :opscode\n\n"
186
+ @opts[:source_list].each do |source_url|
187
+ str << "source '#{source_url}'\n"
188
+ end
189
+ str << "\n"
166
190
  cookbooks.each { |l| str << l.to_s << "\n" }
167
191
  str
168
192
  end
@@ -170,7 +194,7 @@ module Berktacular
170
194
  # @return [Array] a list of Cookbook objects for this environment.
171
195
  def cookbooks
172
196
  @cookbooks ||= @cookbook_versions.sort.map do |book, version|
173
- Cookbook.new(book, version, @cookbook_locations[book], @opts )
197
+ Cookbook.new(book, version, @cookbook_locations[book], @opts )
174
198
  end
175
199
  end
176
200
 
@@ -197,5 +221,9 @@ module Berktacular
197
221
  @opts[:git_client] ||= Octokit::Client.new(access_token: @opts[:github_token])
198
222
  end
199
223
 
224
+ def metadata_from_json(json_str)
225
+ OpenStruct.new(JSON.parse(json_str))
226
+ end
227
+
200
228
  end
201
229
  end
@@ -1,3 +1,5 @@
1
+ require 'semverse'
2
+
1
3
  module Berktacular
2
4
 
3
5
  # This class represents a cookbook entry form a Berksfile
@@ -26,7 +28,7 @@ module Berktacular
26
28
  @name = name || raise( "Missing cookbook name" )
27
29
  @version_spec = version_spec || raise( "Missing cookbook version" )
28
30
  @version_number = VERSION_RE.match( version_spec )[0]
29
- @version_solved = Solve::Version.new(@version_number)
31
+ @version_solved = Semverse::Version.new(@version_number)
30
32
  @auto_upgrade = config && config['auto_upgrade'] || false
31
33
  @versions = config && config['versions'] || {}
32
34
  @config = config ? config.reject{ |k,v| k == 'auto_upgrade' || k == 'versions' } : nil
@@ -69,8 +71,8 @@ module Berktacular
69
71
  next unless m
70
72
  v = m[0]
71
73
  begin
72
- t = Solve::Version.new(v)
73
- rescue Solve::Errors::InvalidVersionFormat
74
+ t = Semverse::Version.new(v)
75
+ rescue Semverse::InvalidVersionFormat
74
76
  next
75
77
  end
76
78
  next unless t > @version_solved
@@ -79,7 +81,7 @@ module Berktacular
79
81
  end
80
82
 
81
83
  private
82
-
84
+
83
85
  # @param upgrade [True,False] use updated cookbook version if @auto_update is also true.
84
86
  # @param config [Hash] the cookbook_locations hash associated with this cookbook.
85
87
  # @return [String] the config line for this cookbook, everything after the cookbook name.
@@ -88,7 +90,7 @@ module Berktacular
88
90
  line = []
89
91
  if config
90
92
  if config.has_key?('github')
91
- line << "github: \"#{config['github']}\""
93
+ line << "git: \"git@github.com:#{config['github']}.git\""
92
94
  line << "rel: \"#{config['rel']}\"" if config.has_key?('rel')
93
95
  line << 'protocol: :ssh'
94
96
  end
@@ -106,7 +108,7 @@ module Berktacular
106
108
  end
107
109
  line.join(", ").gsub('%{version}', ver)
108
110
  end
109
-
111
+
110
112
  # return [Array] a list of tags from the github repository of this cookbook.
111
113
  def get_tags_from_github
112
114
  @git_client.repo(@config['github']).rels[:tags].get.data.map { |obj| obj.name }
@@ -1,4 +1,4 @@
1
1
  module Berktacular
2
2
  # the gem version.
3
- VERSION = '0.1.7'
3
+ VERSION = IO.read(File.expand_path('../../../VERSION', __FILE__)).strip
4
4
  end
metadata CHANGED
@@ -1,117 +1,133 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berktacular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 1.0.0
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: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solve
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: 0.8.2
19
+ version: '1.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '0.8'
30
- - - ! '>='
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 0.8.2
26
+ version: '1.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: ridley
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ~>
31
+ - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '1.5'
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: 1.5.3
33
+ version: '4.0'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ~>
48
- - !ruby/object:Gem::Version
49
- version: '1.5'
50
- - - ! '>='
38
+ - - "~>"
51
39
  - !ruby/object:Gem::Version
52
- version: 1.5.3
40
+ version: '4.0'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: faraday
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
- - - ~>
45
+ - - "~>"
58
46
  - !ruby/object:Gem::Version
59
- version: 0.8.9
47
+ version: '0.9'
60
48
  type: :runtime
61
49
  prerelease: false
62
50
  version_requirements: !ruby/object:Gem::Requirement
63
51
  requirements:
64
- - - ~>
52
+ - - "~>"
65
53
  - !ruby/object:Gem::Version
66
- version: 0.8.9
54
+ version: '0.9'
67
55
  - !ruby/object:Gem::Dependency
68
56
  name: octokit
69
57
  requirement: !ruby/object:Gem::Requirement
70
58
  requirements:
71
- - - ~>
59
+ - - "~>"
72
60
  - !ruby/object:Gem::Version
73
61
  version: '3.0'
74
- - - ! '>='
62
+ - - ">="
75
63
  - !ruby/object:Gem::Version
76
64
  version: 3.0.0
77
65
  type: :runtime
78
66
  prerelease: false
79
67
  version_requirements: !ruby/object:Gem::Requirement
80
68
  requirements:
81
- - - ~>
69
+ - - "~>"
82
70
  - !ruby/object:Gem::Version
83
71
  version: '3.0'
84
- - - ! '>='
72
+ - - ">="
85
73
  - !ruby/object:Gem::Version
86
74
  version: 3.0.0
87
75
  - !ruby/object:Gem::Dependency
88
76
  name: hashie
89
77
  requirement: !ruby/object:Gem::Requirement
90
78
  requirements:
91
- - - <
79
+ - - "~>"
92
80
  - !ruby/object:Gem::Version
93
- version: 3.0.0
81
+ version: '2.1'
94
82
  type: :runtime
95
83
  prerelease: false
96
84
  version_requirements: !ruby/object:Gem::Requirement
97
85
  requirements:
98
- - - <
86
+ - - "~>"
99
87
  - !ruby/object:Gem::Version
100
- version: 3.0.0
88
+ version: '2.1'
101
89
  - !ruby/object:Gem::Dependency
102
90
  name: berkshelf
103
91
  requirement: !ruby/object:Gem::Requirement
104
92
  requirements:
105
- - - <
93
+ - - "~>"
106
94
  - !ruby/object:Gem::Version
107
- version: 3.0.0
95
+ version: '3.1'
108
96
  type: :runtime
109
97
  prerelease: false
110
98
  version_requirements: !ruby/object:Gem::Requirement
111
99
  requirements:
112
- - - <
100
+ - - "~>"
113
101
  - !ruby/object:Gem::Version
114
- version: 3.0.0
102
+ version: '3.1'
103
+ - !ruby/object:Gem::Dependency
104
+ name: yard
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.8'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.8'
117
+ - !ruby/object:Gem::Dependency
118
+ name: minitest
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '5.3'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '5.3'
115
131
  description: Generates a Berksfile from JSON style Chef environment files. Also support
116
132
  extension to environment file with 'cookbook_locations'. Verifies the Berksfile
117
133
  is consistent (all dependencies met) and will upload updated cookbooks and env files
@@ -126,8 +142,9 @@ files:
126
142
  - bin/berktacular
127
143
  - lib/berktacular.rb
128
144
  - lib/berktacular/berksfile.rb
129
- - lib/berktacular/cookbook.rb
130
145
  - lib/berktacular/version.rb
146
+ - lib/berktacular/cookbook.rb
147
+ - VERSION
131
148
  homepage: https://rubygems.org/gems/berktacular
132
149
  licenses:
133
150
  - Apache License, Version 2.0
@@ -138,17 +155,17 @@ require_paths:
138
155
  - lib
139
156
  required_ruby_version: !ruby/object:Gem::Requirement
140
157
  requirements:
141
- - - ! '>='
158
+ - - ">="
142
159
  - !ruby/object:Gem::Version
143
160
  version: '1.9'
144
161
  required_rubygems_version: !ruby/object:Gem::Requirement
145
162
  requirements:
146
- - - ! '>='
163
+ - - ">="
147
164
  - !ruby/object:Gem::Version
148
165
  version: '0'
149
166
  requirements: []
150
167
  rubyforge_project:
151
- rubygems_version: 2.2.2
168
+ rubygems_version: 2.0.14
152
169
  signing_key:
153
170
  specification_version: 4
154
171
  summary: Parse chef env files, generates a Berksfile and verifies it.