omnibus 3.1.1 → 3.2.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -0
  3. data/Gemfile +0 -7
  4. data/README.md +108 -36
  5. data/Rakefile +1 -5
  6. data/docs/omnibus-build-cache.md +5 -5
  7. data/features/commands/_deprecated.feature +21 -3
  8. data/features/step_definitions/generator_steps.rb +7 -7
  9. data/lib/omnibus.rb +232 -171
  10. data/lib/omnibus/build_version.rb +2 -2
  11. data/lib/omnibus/builder.rb +38 -19
  12. data/lib/omnibus/cleaner.rb +5 -5
  13. data/lib/omnibus/cleanroom.rb +141 -0
  14. data/lib/omnibus/cli.rb +6 -9
  15. data/lib/omnibus/cli/base.rb +2 -1
  16. data/lib/omnibus/cli/cache.rb +15 -21
  17. data/lib/omnibus/cli/deprecated.rb +40 -4
  18. data/lib/omnibus/cli/publish.rb +61 -0
  19. data/lib/omnibus/config.rb +350 -189
  20. data/lib/omnibus/digestable.rb +131 -0
  21. data/lib/omnibus/exceptions.rb +163 -83
  22. data/lib/omnibus/fetcher.rb +1 -1
  23. data/lib/omnibus/fetchers/net_fetcher.rb +19 -13
  24. data/lib/omnibus/fetchers/path_fetcher.rb +8 -1
  25. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +16 -7
  26. data/lib/omnibus/generator.rb +2 -2
  27. data/lib/omnibus/generator_files/Gemfile.erb +4 -1
  28. data/lib/omnibus/generator_files/README.md.erb +10 -0
  29. data/lib/omnibus/generator_files/{omnibus.rb.example.erb → omnibus.rb.erb} +20 -11
  30. data/lib/omnibus/generator_files/package_scripts/makeselfinst.erb +1 -1
  31. data/lib/omnibus/generator_files/project.rb.erb +2 -2
  32. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +3 -3
  33. data/lib/omnibus/git_cache.rb +192 -0
  34. data/lib/omnibus/health_check.rb +171 -116
  35. data/lib/omnibus/library.rb +4 -2
  36. data/lib/omnibus/logger.rb +60 -1
  37. data/lib/omnibus/null_argumentable.rb +51 -0
  38. data/lib/omnibus/ohai.rb +29 -8
  39. data/lib/omnibus/package.rb +240 -0
  40. data/lib/omnibus/packagers/base.rb +21 -42
  41. data/lib/omnibus/packagers/mac_dmg.rb +5 -5
  42. data/lib/omnibus/packagers/mac_pkg.rb +20 -19
  43. data/lib/omnibus/packagers/windows_msi.rb +7 -7
  44. data/lib/omnibus/project.rb +969 -486
  45. data/lib/omnibus/publisher.rb +76 -0
  46. data/lib/omnibus/publishers/artifactory_publisher.rb +168 -0
  47. data/lib/omnibus/publishers/null_publisher.rb +23 -0
  48. data/lib/omnibus/publishers/s3_publisher.rb +99 -0
  49. data/lib/omnibus/s3_cache.rb +150 -63
  50. data/lib/omnibus/software.rb +749 -321
  51. data/lib/omnibus/{sugar.rb → sugarable.rb} +11 -6
  52. data/lib/omnibus/version.rb +1 -1
  53. data/omnibus.gemspec +8 -8
  54. data/spec/data/complicated/config/projects/angrychef.rb +1 -1
  55. data/spec/data/complicated/config/projects/chef-windows.rb +1 -1
  56. data/spec/data/complicated/config/projects/chef.rb +1 -1
  57. data/spec/data/complicated/config/projects/chefdk-windows.rb +1 -1
  58. data/spec/data/complicated/config/projects/chefdk.rb +1 -1
  59. data/spec/data/complicated/config/software/cacerts.rb +1 -1
  60. data/spec/data/complicated/config/software/chef-client-msi.rb +1 -1
  61. data/spec/data/complicated/config/software/libgcc.rb +1 -1
  62. data/spec/data/complicated/config/software/libiconv.rb +0 -11
  63. data/spec/data/complicated/config/software/libpng.rb +2 -2
  64. data/spec/data/complicated/config/software/openssl.rb +1 -1
  65. data/spec/data/complicated/config/software/ruby.rb +1 -1
  66. data/spec/data/complicated/config/software/runit.rb +4 -4
  67. data/spec/data/projects/chefdk.rb +1 -1
  68. data/spec/data/projects/sample.rb +1 -1
  69. data/spec/data/software/erchef.rb +3 -1
  70. data/spec/functional/packagers/mac_spec.rb +25 -24
  71. data/spec/functional/packagers/windows_spec.rb +21 -20
  72. data/spec/spec_helper.rb +43 -4
  73. data/spec/unit/build_version_spec.rb +14 -16
  74. data/spec/unit/cleanroom_spec.rb +63 -0
  75. data/spec/unit/config_spec.rb +36 -30
  76. data/spec/unit/digestable_spec.rb +38 -0
  77. data/spec/unit/fetchers/net_fetcher_spec.rb +98 -87
  78. data/spec/unit/{install_path_cache_spec.rb → git_cache_spec.rb} +67 -56
  79. data/spec/unit/health_check_spec.rb +73 -0
  80. data/spec/unit/library_spec.rb +166 -159
  81. data/spec/unit/ohai_spec.rb +19 -0
  82. data/spec/unit/omnibus_spec.rb +43 -41
  83. data/spec/unit/package_spec.rb +178 -0
  84. data/spec/unit/packagers/base_spec.rb +17 -47
  85. data/spec/unit/packagers/mac_pkg_spec.rb +104 -126
  86. data/spec/unit/project_spec.rb +176 -25
  87. data/spec/unit/publisher_spec.rb +49 -0
  88. data/spec/unit/publishers/artifactory_publisher_spec.rb +80 -0
  89. data/spec/unit/publishers/s3_publisher_spec.rb +120 -0
  90. data/spec/unit/s3_cacher_spec.rb +84 -19
  91. data/spec/unit/software_spec.rb +397 -170
  92. data/spec/unit/sugarable_spec.rb +43 -0
  93. metadata +62 -50
  94. data/Guardfile +0 -10
  95. data/lib/omnibus/artifact.rb +0 -165
  96. data/lib/omnibus/cli/release.rb +0 -40
  97. data/lib/omnibus/generator_files/Vagrantfile.erb +0 -75
  98. data/lib/omnibus/install_path_cache.rb +0 -105
  99. data/lib/omnibus/overrides.rb +0 -88
  100. data/lib/omnibus/package_release.rb +0 -154
  101. data/lib/omnibus/software_s3_urls.rb +0 -50
  102. data/spec/unit/artifact_spec.rb +0 -91
  103. data/spec/unit/overrides_spec.rb +0 -102
  104. data/spec/unit/package_release_spec.rb +0 -180
  105. data/spec/unit/sugar_spec.rb +0 -17
@@ -1,7 +1,30 @@
1
+ #
2
+ # Copyright 2014 Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
1
17
  require 'logger'
2
18
 
3
19
  module Omnibus
4
20
  class Logger < ::Logger
21
+ #
22
+ # The amount of padding on the left column.
23
+ #
24
+ # @return [Fixnum]
25
+ #
26
+ LEFT = 40
27
+
5
28
  def initialize(logdev = $stdout, *)
6
29
  super
7
30
  @level = Logger::WARN
@@ -44,6 +67,24 @@ module Omnibus
44
67
  @live_streams[level.to_sym] ||= LiveStream.new(self, level)
45
68
  end
46
69
 
70
+ #
71
+ # The string representation of this object.
72
+ #
73
+ # @return [String]
74
+ #
75
+ def to_s
76
+ "#<#{self.class.name}>"
77
+ end
78
+
79
+ #
80
+ # The detailed string representation of this object.
81
+ #
82
+ # @return [String]
83
+ #
84
+ def inspect
85
+ "#<#{self.class.name} level: #{@level}>"
86
+ end
87
+
47
88
  private
48
89
 
49
90
  def format_message(severity, _datetime, progname, msg)
@@ -53,7 +94,7 @@ module Omnibus
53
94
  "#{severity[0]} | "
54
95
  end
55
96
 
56
- "#{left.rjust(30)}#{msg}\n"
97
+ "#{left.rjust(LEFT)}#{msg}\n"
57
98
  end
58
99
 
59
100
  #
@@ -84,6 +125,24 @@ module Omnibus
84
125
  log_lines(data)
85
126
  end
86
127
 
128
+ #
129
+ # The string representation of this object.
130
+ #
131
+ # @return [String]
132
+ #
133
+ def to_s
134
+ "#<#{self.class.name}>"
135
+ end
136
+
137
+ #
138
+ # The detailed string representation of this object.
139
+ #
140
+ # @return [String]
141
+ #
142
+ def inspect
143
+ "#<#{self.class.name} level: #{@level}>"
144
+ end
145
+
87
146
  private
88
147
 
89
148
  #
@@ -0,0 +1,51 @@
1
+ #
2
+ # Copyright 2014 Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Omnibus
18
+ module NullArgumentable
19
+ #
20
+ # The "empty" null object.
21
+ #
22
+ # @return [Object]
23
+ #
24
+ NULL = Object.new.freeze
25
+
26
+ #
27
+ # Called when the module is included.
28
+ #
29
+ # @param [Object] base
30
+ #
31
+ def self.included(base)
32
+ base.extend(ClassMethods)
33
+ end
34
+
35
+ module ClassMethods
36
+ #
37
+ # Check if the given object is null.
38
+ #
39
+ # @return [true, false]
40
+ #
41
+ def null?(object)
42
+ object.equal?(NULL)
43
+ end
44
+ end
45
+
46
+ # @see (NullArgumentable.null?)
47
+ def null?(object)
48
+ self.class.null?(object)
49
+ end
50
+ end
51
+ end
@@ -16,8 +16,36 @@
16
16
 
17
17
  require 'ohai'
18
18
 
19
+ class Mash
20
+ #
21
+ # @todo Remove in the next major release
22
+ #
23
+ # Ohai 7 removed the ability to access Ohai attributes via dot notation. This
24
+ # temporary monkey patch provides the ability for users to still use the old
25
+ # dot notation, while printing out a deprecation error.
26
+ #
27
+ def method_missing(m, *args, &block)
28
+ if key?(m)
29
+ Omnibus.logger.deprecated('Ohai') do
30
+ "Ohai.#{m}. Please use Ohai['#{m}'] instead."
31
+ end
32
+
33
+ fetch(m)
34
+ else
35
+ super
36
+ end
37
+ end
38
+ end
39
+
19
40
  module Omnibus
20
41
  class Ohai
42
+ PLUGINS = [
43
+ 'cpu',
44
+ 'kernel',
45
+ 'os',
46
+ 'platform',
47
+ ].freeze
48
+
21
49
  class << self
22
50
  def method_missing(m, *args, &block)
23
51
  ohai.send(m, *args, &block)
@@ -26,14 +54,7 @@ module Omnibus
26
54
  private
27
55
 
28
56
  def ohai
29
- return @ohai if @ohai
30
-
31
- @ohai = ::Ohai::System.new
32
- @ohai.require_plugin('os')
33
- @ohai.require_plugin('platform')
34
- @ohai.require_plugin('linux/cpu') if @ohai.os == 'linux'
35
- @ohai.require_plugin('kernel')
36
- @ohai
57
+ @ohai ||= ::Ohai::System.new.tap { |o| o.all_plugins(PLUGINS) }.data
37
58
  end
38
59
  end
39
60
  end
@@ -0,0 +1,240 @@
1
+ #
2
+ # Copyright 2014 Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'json'
18
+
19
+ module Omnibus
20
+ class Package
21
+ class Metadata
22
+ class << self
23
+ #
24
+ # Generate a +metadata.json+ from the given package and data hash.
25
+ #
26
+ # @param [Package] package
27
+ # the package for this metadata
28
+ # @param [Hash] data
29
+ # the hash of attributes to set in the metadata
30
+ #
31
+ # @return [String]
32
+ # the path where the metadata was saved on disk
33
+ #
34
+ def generate(package, data = {})
35
+ data = {
36
+ basename: package.name,
37
+ md5: package.md5,
38
+ sha1: package.sha1,
39
+ sha256: package.sha256,
40
+ sha512: package.sha512,
41
+ }.merge(data)
42
+
43
+ instance = new(package, data)
44
+ instance.save
45
+ instance.path
46
+ end
47
+
48
+ #
49
+ # Load the metadata from disk.
50
+ #
51
+ # @param [Package] package
52
+ # the package for this metadata
53
+ #
54
+ # @return [Metadata]
55
+ #
56
+ def for_package(package)
57
+ data = File.read(path_for(package))
58
+ hash = JSON.parse(data, symbolize_names: true)
59
+ new(package, hash)
60
+ rescue Errno::ENOENT
61
+ raise NoPackageMetadataFile.new(package.path)
62
+ end
63
+
64
+ #
65
+ # The metadata path that corresponds to the package.
66
+ #
67
+ # @param [Package] package
68
+ # the package for this metadata
69
+ #
70
+ # @return [String]
71
+ #
72
+ def path_for(package)
73
+ "#{package.path}.metadata.json"
74
+ end
75
+ end
76
+
77
+ #
78
+ # Create a new metadata object for the given package and hash data.
79
+ #
80
+ # @param [Package] package
81
+ # the package for this metadata
82
+ # @param [Hash] data
83
+ # the hash of attributes to set in the metadata
84
+ #
85
+ def initialize(package, data = {})
86
+ @package = package
87
+ @data = data.dup.freeze
88
+ end
89
+
90
+ #
91
+ # Helper for accessing the information inside the metadata hash.
92
+ #
93
+ # @return [Object]
94
+ #
95
+ def [](key)
96
+ @data[key]
97
+ end
98
+
99
+ #
100
+ # The name of this metadata file.
101
+ #
102
+ # @return [String]
103
+ #
104
+ def name
105
+ @name ||= File.basename(path)
106
+ end
107
+
108
+ #
109
+ # @see (Metadata.path_for)
110
+ #
111
+ def path
112
+ @path ||= self.class.path_for(@package)
113
+ end
114
+
115
+ #
116
+ # Save the file to disk.
117
+ #
118
+ # @return [true]
119
+ #
120
+ def save
121
+ File.open(path, 'w+') do |f|
122
+ f.write(to_json)
123
+ end
124
+
125
+ true
126
+ end
127
+
128
+ #
129
+ # The JSON representation of this metadata.
130
+ #
131
+ # @return [String]
132
+ #
133
+ def to_json
134
+ JSON.pretty_generate(@data)
135
+ end
136
+ end
137
+
138
+ include Digestable
139
+
140
+ attr_reader :path
141
+
142
+ #
143
+ # Create a new package from the given path.
144
+ #
145
+ # @param [String] path
146
+ # the path to the package on disk
147
+ #
148
+ def initialize(path)
149
+ @path = File.expand_path(path)
150
+ end
151
+
152
+ #
153
+ # The shortname of this package (the basename of the file).
154
+ #
155
+ # @return [String]
156
+ #
157
+ def name
158
+ @name ||= File.basename(path)
159
+ end
160
+
161
+ #
162
+ # The MD5 checksum for this file.
163
+ #
164
+ # @return [String]
165
+ #
166
+ def md5
167
+ @md5 ||= digest(path, :md5)
168
+ end
169
+
170
+ #
171
+ # The SHA1 checksum for this file.
172
+ #
173
+ # @return [String]
174
+ #
175
+ def sha1
176
+ @sha1 ||= digest(path, :sha1)
177
+ end
178
+
179
+ #
180
+ # The SHA256 checksum for this file.
181
+ #
182
+ # @return [String]
183
+ #
184
+ def sha256
185
+ @sha256 ||= digest(path, :sha256)
186
+ end
187
+
188
+ #
189
+ # The SHA512 checksum for this file.
190
+ #
191
+ # @return [String]
192
+ #
193
+ def sha512
194
+ @sha512 ||= digest(path, :sha512)
195
+ end
196
+
197
+ #
198
+ # The actual contents of the package.
199
+ #
200
+ # @return [String]
201
+ #
202
+ def content
203
+ @content ||= IO.read(path)
204
+ rescue Errno::ENOENT
205
+ raise NoPackageFile.new(path)
206
+ end
207
+
208
+ #
209
+ # The parsed contents of the metadata.
210
+ #
211
+ # @raise [NoPackageMetadataFile] if the {metadata} does not exist
212
+ # @raise [JSON::ParserError] if the JSON is not valid
213
+ #
214
+ # @return [Hash<Symbol, String>]
215
+ #
216
+ def metadata
217
+ @metadata ||= Metadata.for_package(self)
218
+ end
219
+
220
+ #
221
+ # Validate the presence of the required components for the package.
222
+ #
223
+ # @raise [NoPackageFile] if the package is not present
224
+ # @raise [NoPackageMetadataFile] if the metadata file is not present
225
+ #
226
+ # @return [true]
227
+ #
228
+ def validate!
229
+ unless File.exist?(path)
230
+ raise NoPackageFile.new(path)
231
+ end
232
+
233
+ unless File.exist?(metadata.path)
234
+ raise NoPackageMetadataFile.new(metadata.path)
235
+ end
236
+
237
+ true
238
+ end
239
+ end
240
+ end
@@ -27,46 +27,6 @@ module Omnibus
27
27
  # The Omnibus::Project instance that we're packaging.
28
28
  attr_reader :project
29
29
 
30
- # !@method name
31
- # @return (see Project#name)
32
- def_delegator :@project, :name
33
-
34
- # !@method friendly_name
35
- # @return (see Project#friendly_name)
36
- def_delegator :@project, :friendly_name
37
-
38
- # !@method maintainer
39
- # @return (see Project#maintainer)
40
- def_delegator :@project, :maintainer
41
-
42
- # !@method version
43
- # @return (see Project#build_version)
44
- def_delegator :@project, :build_version, :version
45
-
46
- # !@method iteration
47
- # @return (see Project#iteration)
48
- def_delegator :@project, :iteration, :iteration
49
-
50
- # !@method identifier
51
- # @return (see Project#mac_pkg_identifier)
52
- def_delegator :@project, :mac_pkg_identifier, :identifier
53
-
54
- # !@method install_path
55
- # @return (see Project#install_path)
56
- def_delegator :@project, :install_path, :install_path
57
-
58
- # !@method scripts
59
- # @return (see Project#package_scripts_path)
60
- def_delegator :@project, :package_scripts_path, :scripts
61
-
62
- # !@method files_path
63
- # @return (see Project#files_path)
64
- def_delegator :@project, :files_path
65
-
66
- # !@method package_dir
67
- # @return (see Project#package_dir)
68
- def_delegator :@project, :package_dir
69
-
70
30
  # The commands/steps to setup the file system.
71
31
  def self.setup(&block)
72
32
  if block_given?
@@ -110,6 +70,25 @@ module Omnibus
110
70
  @project = project
111
71
  end
112
72
 
73
+ # Hacky way to get around the fact that older versions of Omnibus used to
74
+ # delegate magical methods to this DSL.
75
+ #
76
+ # @deprecated Use +project+ methods instead
77
+ def method_missing(m, *args, &block)
78
+ if project.respond_to?(m)
79
+ log.deprecated("#{log_key}##{m}") { "#{m}. Please use project.#{m} instead." }
80
+ project.send(m, *args, &block)
81
+ else
82
+ super
83
+ end
84
+ end
85
+
86
+ # @deprecated
87
+ def version
88
+ log.deprecated("#{log_key}#version") { 'version. Please use project.build_version instead.' }
89
+ project.build_version
90
+ end
91
+
113
92
  #
114
93
  # Generation methods
115
94
  # ------------------------------
@@ -229,7 +208,7 @@ module Omnibus
229
208
  #
230
209
  # @return [String]
231
210
  def staging_dir
232
- File.expand_path("#{project.package_tmp}/#{underscore_name}")
211
+ File.expand_path("#{Config.package_tmp}/#{underscore_name}")
233
212
  end
234
213
 
235
214
  # The path to the directory where the packager resources are
@@ -258,7 +237,7 @@ module Omnibus
258
237
  base_path = if project.resources_path
259
238
  project.resources_path
260
239
  else
261
- files_path
240
+ project.files_path
262
241
  end
263
242
 
264
243
  File.expand_path(File.join(base_path, underscore_name, 'Resources'))