omnibus 4.0.0.beta.1 → 4.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/docs/Building on RHEL.md +1 -0
  4. data/lib/omnibus/builder.rb +48 -1
  5. data/lib/omnibus/config.rb +13 -0
  6. data/lib/omnibus/digestable.rb +2 -2
  7. data/lib/omnibus/exceptions.rb +21 -0
  8. data/lib/omnibus/fetchers/git_fetcher.rb +75 -9
  9. data/lib/omnibus/fetchers/net_fetcher.rb +5 -3
  10. data/lib/omnibus/generator.rb +0 -13
  11. data/{resources/bff/postinstall.sh → lib/omnibus/generator_files/package_scripts/makeselfinst.erb} +0 -0
  12. data/lib/omnibus/packagers/base.rb +25 -1
  13. data/lib/omnibus/packagers/bff.rb +99 -12
  14. data/lib/omnibus/packagers/deb.rb +10 -8
  15. data/lib/omnibus/packagers/makeself.rb +24 -16
  16. data/lib/omnibus/packagers/msi.rb +6 -5
  17. data/lib/omnibus/packagers/pkg.rb +59 -10
  18. data/lib/omnibus/packagers/rpm.rb +42 -25
  19. data/lib/omnibus/packagers/solaris.rb +5 -5
  20. data/lib/omnibus/project.rb +54 -5
  21. data/lib/omnibus/software.rb +37 -39
  22. data/lib/omnibus/version.rb +1 -1
  23. data/omnibus.gemspec +1 -0
  24. data/resources/bff/gen.template.erb +3 -2
  25. data/resources/rpm/signing.erb +1 -1
  26. data/spec/functional/builder_spec.rb +75 -3
  27. data/spec/functional/fetchers/git_fetcher_spec.rb +31 -2
  28. data/spec/support/examples.rb +8 -2
  29. data/spec/support/git_helpers.rb +8 -0
  30. data/spec/unit/builder_spec.rb +6 -0
  31. data/spec/unit/config_spec.rb +1 -0
  32. data/spec/unit/generator_spec.rb +0 -12
  33. data/spec/unit/packagers/base_spec.rb +16 -0
  34. data/spec/unit/packagers/bff_spec.rb +58 -5
  35. data/spec/unit/packagers/deb_spec.rb +15 -3
  36. data/spec/unit/packagers/makeself_spec.rb +56 -9
  37. data/spec/unit/packagers/pkg_spec.rb +57 -4
  38. data/spec/unit/packagers/rpm_spec.rb +38 -23
  39. data/spec/unit/project_spec.rb +16 -5
  40. data/spec/unit/software_spec.rb +0 -1
  41. metadata +18 -6
  42. data/resources/bff/unpostinstall.sh +0 -0
  43. data/resources/makeself/post_extract.sh.erb +0 -27
@@ -37,14 +37,14 @@ module Omnibus
37
37
 
38
38
  Dir.chdir(staging_dir) do
39
39
  shellout! "pkgmk -o -r #{install_dirname} -d /tmp/pkgmk -f /tmp/pkgmk/Prototype"
40
- shellout! "pkgchk -vd /tmp/pkgmk #{project.name}"
41
- shellout! "pkgtrans /tmp/pkgmk /var/cache/omnibus/pkg/#{package_name} #{project.name}"
40
+ shellout! "pkgchk -vd /tmp/pkgmk #{project.package_name}"
41
+ shellout! "pkgtrans /tmp/pkgmk /var/cache/omnibus/pkg/#{package_name} #{project.package_name}"
42
42
  end
43
43
  end
44
44
 
45
45
  # @see Base#package_name
46
46
  def package_name
47
- "#{project.name}-#{pkgmk_version}.#{Ohai['kernel']['machine']}.solaris"
47
+ "#{project.package_name}-#{pkgmk_version}.#{Ohai['kernel']['machine']}.solaris"
48
48
  end
49
49
 
50
50
  def pkgmk_version
@@ -92,8 +92,8 @@ module Omnibus
92
92
  TZ=PST
93
93
  PATH=/sbin:/usr/sbin:/usr/bin:/usr/sadm/install/bin
94
94
  BASEDIR=#{install_dirname}
95
- PKG=#{project.name}
96
- NAME=#{project.name}
95
+ PKG=#{project.package_name}
96
+ NAME=#{project.package_name}
97
97
  ARCH=#{`uname -p`.chomp}
98
98
  VERSION=#{pkgmk_version}
99
99
  CATEGORY=application
@@ -120,6 +120,27 @@ module Omnibus
120
120
  end
121
121
  expose :friendly_name
122
122
 
123
+ #
124
+ # Set or retrieve the package name of the project. Defaults to the package
125
+ # name defaults to the project name.
126
+ #
127
+ # @example
128
+ # package_name 'com.chef.project'
129
+ #
130
+ # @param [String] val
131
+ # the package name to set
132
+ #
133
+ # @return [String]
134
+ #
135
+ def package_name(val = NULL)
136
+ if null?(val)
137
+ @package_name || name
138
+ else
139
+ @package_name = val
140
+ end
141
+ end
142
+ expose :package_name
143
+
123
144
  #
124
145
  # **[Required]** Set or retrieve the path at which the project should be
125
146
  # installed by the generated package.
@@ -170,6 +191,21 @@ module Omnibus
170
191
  end
171
192
  expose :default_root
172
193
 
194
+ #
195
+ # Path to the +/files+ directory in the omnibus project. This directory can
196
+ # contain arbritary files used by the project.
197
+ #
198
+ # @example
199
+ # patch = File.join(files_path, 'rubygems', 'patch.rb')
200
+ #
201
+ # @return [String]
202
+ # path to the files directory
203
+ #
204
+ def files_path
205
+ File.expand_path("#{Config.project_root}/files")
206
+ end
207
+ expose :files_path
208
+
173
209
  #
174
210
  # **[Required]** Set or retrieve the the package maintainer.
175
211
  #
@@ -830,10 +866,23 @@ module Omnibus
830
866
  # install path cache, or software definitions to invalidate the cache for
831
867
  # this project.
832
868
  #
869
+ # @param [Software] software
870
+ # the software that dirtied the cache
871
+ #
833
872
  # @return [true, false]
834
873
  #
835
- def dirty!
836
- @dirty = true
874
+ def dirty!(software)
875
+ raise ProjectAlreadyDirty.new(self) if culprit
876
+ @culprit = software
877
+ end
878
+
879
+ #
880
+ # The software definition which dirtied this project.
881
+ #
882
+ # @return [Software, nil]
883
+ #
884
+ def culprit
885
+ @culprit
837
886
  end
838
887
 
839
888
  #
@@ -842,7 +891,7 @@ module Omnibus
842
891
  # @return [true, false]
843
892
  #
844
893
  def dirty?
845
- !!@dirty
894
+ !!culprit
846
895
  end
847
896
 
848
897
  #
@@ -907,8 +956,8 @@ module Omnibus
907
956
 
908
957
  # Copy the generated package and metadata back into the workspace
909
958
  package_path = File.join(Config.package_dir, packager.package_name)
910
- FileUtils.cp(package_path, destination)
911
- FileUtils.cp("#{package_path}.metadata.json", destination)
959
+ FileUtils.cp(package_path, destination, preserve: true)
960
+ FileUtils.cp("#{package_path}.metadata.json", destination, preserve: true)
912
961
  end
913
962
 
914
963
  #
@@ -160,19 +160,6 @@ module Omnibus
160
160
  end
161
161
  expose :description
162
162
 
163
- #
164
- # Always build the given software definition.
165
- #
166
- # @param [true, false] val
167
- #
168
- # @return [true, false]
169
- #
170
- def always_build(val)
171
- @always_build = val
172
- @always_build
173
- end
174
- expose :always_build
175
-
176
163
  #
177
164
  # Add a software dependency to this software.
178
165
  #
@@ -717,20 +704,32 @@ module Omnibus
717
704
  end
718
705
  end
719
706
 
720
- # Actually build the software package
707
+ #
708
+ # Build the software package. If git caching is turned on (see
709
+ # {Config#use_git_caching}), the build is restored according to the
710
+ # documented restoration procedure in the git cache. If the build cannot
711
+ # be restored (if the tag does not exist), the actual build steps are
712
+ # executed.
713
+ #
714
+ # @return [true]
715
+ #
721
716
  def build_me
722
- # Build if we need to
723
- if always_build?
724
- log.info(log_key) { "Forcing build because `always_build' was given" }
725
- execute_build
726
- else
727
- if GitCache.new(self).restore
717
+ if Config.use_git_caching
718
+ if project.dirty?
719
+ log.info(log_key) do
720
+ "Building because `#{project.culprit.name}' dirtied the cache"
721
+ end
722
+ execute_build
723
+ elsif git_cache.restore
728
724
  log.info(log_key) { "Restored from cache" }
729
- true
730
725
  else
731
- log.info(log_key) { "Could not restore from cache, building..." }
726
+ log.info(log_key) { "Could not restore from cache" }
732
727
  execute_build
728
+ project.dirty!(self)
733
729
  end
730
+ else
731
+ log.debug(log_key) { "Forcing build because git caching is off" }
732
+ execute_build
734
733
  end
735
734
 
736
735
  project.build_version_dsl.resolve(self)
@@ -792,22 +791,12 @@ module Omnibus
792
791
  private
793
792
 
794
793
  #
795
- # Determine if this software should always be built. A software should
796
- # always be built if git caching is disabled ({Config#use_git_caching}) or
797
- # if the parent project has dirtied the cache.
794
+ # The git caching implementation for this software.
798
795
  #
799
- # @return [true, false]
796
+ # @return [GitCache]
800
797
  #
801
- def always_build?
802
- unless Config.use_git_caching
803
- return true
804
- end
805
-
806
- if project.dirty?
807
- return true
808
- end
809
-
810
- !!@always_build
798
+ def git_cache
799
+ @git_cache ||= GitCache.new(self)
811
800
  end
812
801
 
813
802
  #
@@ -838,18 +827,27 @@ module Omnibus
838
827
  end
839
828
  end
840
829
 
830
+ #
831
+ # Actually build this software, executing the steps provided in the
832
+ # {#build} block and dirtying the cache.
833
+ #
834
+ # @return [void]
835
+ #
841
836
  def execute_build
842
837
  fetcher.clean
843
838
  builder.build
844
839
 
845
840
  if Config.use_git_caching
846
- GitCache.new(self).incremental
841
+ git_cache.incremental
847
842
  log.info(log_key) { 'Dirtied the cache' }
848
843
  end
849
-
850
- project.dirty!
851
844
  end
852
845
 
846
+ #
847
+ # The log key for this software, including its name.
848
+ #
849
+ # @return [String]
850
+ #
853
851
  def log_key
854
852
  @log_key ||= "#{super}: #{name}"
855
853
  end
@@ -15,5 +15,5 @@
15
15
  #
16
16
 
17
17
  module Omnibus
18
- VERSION = '4.0.0.beta.1'
18
+ VERSION = '4.0.0.rc.1'
19
19
  end
@@ -35,4 +35,5 @@ Gem::Specification.new do |gem|
35
35
  gem.add_development_dependency 'rspec', '~> 3.0'
36
36
  gem.add_development_dependency 'rspec-its'
37
37
  gem.add_development_dependency 'rake'
38
+ gem.add_development_dependency 'appbundler'
38
39
  end
@@ -6,8 +6,9 @@ Fileset
6
6
  Fileset VRMF: <%= version %>
7
7
  Fileset Description: <%= description %>
8
8
  USRLIBLPPFiles
9
- Configuration Script: <%= configuration_script %>
10
- Unconfiguration Script: <%= unconfiguration_script %>
9
+ <% scripts.each do |name, install_path| -%>
10
+ <%= name %>: <%= install_path %>
11
+ <% end -%>
11
12
  EOUSRLIBLPPFiles
12
13
  Bosboot required: N
13
14
  License agreement acceptance required: N
@@ -29,7 +29,7 @@ PTY.spawn(rpm_cmd) do |r, w, pid|
29
29
  begin
30
30
  line = r.gets
31
31
  puts line
32
- if line =~ /failed/
32
+ if (line =~ /failed/) && !(line =~ /warning:/)
33
33
  STDERR.puts 'RPM signing failure'
34
34
  exit 1
35
35
  end
@@ -10,8 +10,8 @@ module Omnibus
10
10
  # a real Ruby just for functional tests.
11
11
  #
12
12
  def fake_embedded_bin(name)
13
- create_directory(bin_dir)
14
- create_link(Bundler.which(name), File.join(bin_dir, name))
13
+ create_directory(embedded_bin_dir)
14
+ create_link(Bundler.which(name), File.join(embedded_bin_dir, name))
15
15
  end
16
16
 
17
17
  subject { described_class.new(software) }
@@ -131,13 +131,85 @@ module Omnibus
131
131
 
132
132
  fake_embedded_bin('bundle')
133
133
 
134
- subject.bundle('install')
134
+ # Pass GEM_HOME and GEM_PATH to subprocess so our fake bin works
135
+ options = {}
136
+ options[:env] = {
137
+ 'GEM_HOME' => ENV['GEM_HOME'],
138
+ 'GEM_PATH' => ENV['GEM_PATH'],
139
+ }
140
+
141
+ subject.bundle('install', options)
135
142
  output = capture_logging { subject.build }
136
143
 
137
144
  expect(output).to include('bundle install')
138
145
  end
139
146
  end
140
147
 
148
+ describe '#appbundle' do
149
+ it 'executes the command as the embedded appbundler' do
150
+
151
+ source_dir = "#{Omnibus::Config.source_dir}/example"
152
+ embedded_app_dir = "#{software.install_dir}/embedded/apps/example"
153
+ bin_dir = "#{software.install_dir}/bin"
154
+
155
+ FileUtils.mkdir(source_dir)
156
+
157
+ gemspec = File.join(source_dir, 'example.gemspec')
158
+ File.open(gemspec, 'w') do |f|
159
+ f.write <<-EOH.gsub(/^ {12}/, '')
160
+ Gem::Specification.new do |gem|
161
+ gem.name = 'example'
162
+ gem.version = '1.0.0'
163
+ gem.author = 'Chef Software, Inc.'
164
+ gem.email = 'info@getchef.com'
165
+ gem.description = 'Installs a thing'
166
+ gem.summary = gem.description
167
+ end
168
+ EOH
169
+ end
170
+
171
+ gemfile = File.join(source_dir, 'Gemfile')
172
+ File.open(gemfile, 'w') do |f|
173
+ f.write <<-EOH.gsub(/^ {12}/, '')
174
+ gemspec
175
+ EOH
176
+ end
177
+
178
+ gemfile_lock = File.join(source_dir, 'Gemfile.lock')
179
+ File.open(gemfile_lock, 'w') do |f|
180
+ f.write <<-EOH.gsub(/^ {12}/, '')
181
+ PATH
182
+ remote: .
183
+ specs:
184
+ example (1.0.0)
185
+
186
+ GEM
187
+ specs:
188
+
189
+ PLATFORMS
190
+ ruby
191
+
192
+ DEPENDENCIES
193
+ example!
194
+ EOH
195
+ end
196
+
197
+ fake_embedded_bin('appbundler')
198
+
199
+ # Pass GEM_HOME and GEM_PATH to subprocess so our fake bin works
200
+ options = {}
201
+ options[:env] = {
202
+ 'GEM_HOME' => ENV['GEM_HOME'],
203
+ 'GEM_PATH' => ENV['GEM_PATH'],
204
+ }
205
+
206
+ subject.appbundle('example', options)
207
+ output = capture_logging { subject.build }
208
+
209
+ expect(output).to include("/opt/chefdk/embedded/bin/appbundler '#{embedded_app_dir}' '#{bin_dir}'")
210
+ end
211
+ end
212
+
141
213
  describe '#rake' do
142
214
  it 'executes the command as the embedded rake' do
143
215
  rakefile = File.join(tmp_path, 'Rakefile')
@@ -98,6 +98,16 @@ module Omnibus
98
98
  end
99
99
  end
100
100
 
101
+ context 'when the version is an annnotated tag' do
102
+ let(:version) { 'v1.2.4' }
103
+ let(:remote) { remote_git_repo('zlib', annotated_tags: [version]) }
104
+
105
+ it 'it defererences and parses the annotated tag' do
106
+ subject.fetch
107
+ expect(revision).to eq('efde208366abd0f91419d8a54b45e3f6e0540105')
108
+ end
109
+ end
110
+
101
111
  context 'when the version is a branch' do
102
112
  let(:version) { 'sethvargo/magic_ponies' }
103
113
  let(:remote) { remote_git_repo('zlib', branches: [version]) }
@@ -108,15 +118,34 @@ module Omnibus
108
118
  end
109
119
  end
110
120
 
111
- context 'when the version is a ref' do
121
+ context 'when the version is a full SHA-1' do
122
+ let(:version) { '45ded6d3b1a35d66ed866b2c3eb418426e6382b0' }
123
+ let(:remote) { remote_git_repo('zlib') }
124
+
125
+ it 'parses the full SHA-1' do
126
+ subject.fetch
127
+ expect(revision).to eq('45ded6d3b1a35d66ed866b2c3eb418426e6382b0')
128
+ end
129
+ end
130
+
131
+ context 'when the version is a abbreviated SHA-1' do
112
132
  let(:version) { '45ded6d' }
113
133
  let(:remote) { remote_git_repo('zlib') }
114
134
 
115
- it 'parses the ref' do
135
+ it 'parses the abbreviated SHA-1' do
116
136
  subject.fetch
117
137
  expect(revision).to eq('45ded6d3b1a35d66ed866b2c3eb418426e6382b0')
118
138
  end
119
139
  end
140
+
141
+ context 'when the version is a non-existent ref' do
142
+ let(:version) { 'fufufufufu' }
143
+ let(:remote) { remote_git_repo('zlib') }
144
+
145
+ it 'raise an exception' do
146
+ expect { subject.fetch }.to raise_error(UnresolvableGitReference)
147
+ end
148
+ end
120
149
  end
121
150
 
122
151
  describe '#version_for_cache' do
@@ -15,8 +15,9 @@ RSpec.shared_examples 'a software' do |name = 'chefdk'|
15
15
  let(:softwares_dir) { File.join(project_root, 'config', 'software', name) }
16
16
  let(:templates_dir) { File.join(project_root, 'config', 'templates', name) }
17
17
 
18
- let(:install_dir) { File.join(project_root, 'opt', name) }
19
- let(:bin_dir) { File.join(install_dir, 'embedded', 'bin') }
18
+ let(:install_dir) { File.join(project_root, 'opt', name) }
19
+ let(:bin_dir) { File.join(install_dir, 'bin') }
20
+ let(:embedded_bin_dir) { File.join(install_dir, 'embedded', 'bin') }
20
21
 
21
22
  let(:software) do
22
23
  double(Omnibus::Software,
@@ -52,5 +53,10 @@ RSpec.shared_examples 'a software' do |name = 'chefdk'|
52
53
 
53
54
  FileUtils.mkdir_p(install_dir)
54
55
  FileUtils.mkdir_p(bin_dir)
56
+ FileUtils.mkdir_p(embedded_bin_dir)
57
+
58
+ allow(software).to receive(:with_embedded_path).and_return(
59
+ "PATH" => "#{bin_dir}:#{embedded_bin_dir}:#{ENV['PATH']}"
60
+ )
55
61
  end
56
62
  end