puppet_module_packaging 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6dec8ec8f4760db5449a19c12c970c2fdcc1597
4
- data.tar.gz: b6faeb96ae78ad45de6745118b7a90ca2f5e4db5
3
+ metadata.gz: dd5dba623fbe049e9833d313d879c7e1406c14f5
4
+ data.tar.gz: 103b9a8a5357e19a8210d1982d84f27ef6a2c0c0
5
5
  SHA512:
6
- metadata.gz: 3b6af7a8e1960a0d060d3adec5d1974b7de4552b8521f86debe09b8d71c497c030ade1c7f0be84ee3f998b5865e5016909df6baa77bfa12b7cbb29bac00faf72
7
- data.tar.gz: d804b951fcb7304b9f9a3453645518e76d77a8d40f7bd4bdb937ce04fce13f890e278dc292f6a5cf52d1c14f8d326d98df604302a71ac1d7ef61f8e58f41d594
6
+ metadata.gz: 118a93d9fc1f1cc2647fc84fb7003985f7e20d338ffb631629d9a3479023646e92aba26f508710b9f28f2bdc38f3675daaab26547ea7d5d24fdca0778046f280
7
+ data.tar.gz: 718a9760b856f780f6171b1acf1c45ca04f349d7253fa212c83720d89d1b8b34863af83ae309058693f83533aa56d07aa3b98964b4a3886633a7b51b402623a8
data/.travis.yml CHANGED
@@ -5,8 +5,6 @@ rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
7
  - 2.1
8
- - jruby-19mode
9
- - rbx
10
8
 
11
9
  cache: apt
12
10
 
data/Changelog.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ * Introduce :recursive option, which performs recursive dependency packaging if
6
+ enabled.
7
+
3
8
  ## 0.1.1
4
9
 
5
10
  * Fix a bug in the Modulefile parser that prevented correct dependency
data/README.md CHANGED
@@ -60,6 +60,24 @@ optional and are mapped into package fields with equivalent meaning.
60
60
  **NOTE**: The module will be installed under `/usr/share/puppet/modules`, not
61
61
  into `/etc/puppet`!
62
62
 
63
+ ### Recursive packaging
64
+
65
+ The library can also take care of packaging the whole dependency tree of a
66
+ module as well, so that you don't need to manually track and package
67
+ dependencies. To enable this feature, just specify the `:recursive` option when
68
+ declaring the tasks:
69
+
70
+ require 'puppet_module/pkg/rake_task'
71
+
72
+ PuppetModule::Pkg::Tasks.new :recursive => true
73
+
74
+ This way, the library will take care of downloading the module's dependencies,
75
+ installing their relevant assets into a separate folder and packaging them into
76
+ individual packages.
77
+
78
+ Note that, as of now, **only dependencies downloadable from Puppet Forge are
79
+ supported**.
80
+
63
81
  ## Compatibility
64
82
 
65
83
  OS compatibility resembles the one of FPM; in particular:
@@ -1,12 +1,11 @@
1
1
  require 'puppet_module/pkg/tasks/rake_tasks'
2
-
3
2
  require 'puppet_module/pkg/tasks/modulefile'
4
3
 
5
4
  module PuppetModule
6
5
  module Pkg
7
6
  class Tasks
8
- def initialize
9
- RakeTasks.new(Modulefile.parse("Modulefile"))
7
+ def initialize(options = {})
8
+ RakeTasks.new(Modulefile.parse("Modulefile"), options)
10
9
  end
11
10
  end
12
11
  end
@@ -1,3 +1,5 @@
1
+ require 'puppet_module/pkg/tasks/packager'
2
+
1
3
  class Class
2
4
  def type(sym)
3
5
  self.class_eval <<-EOS
@@ -20,8 +22,9 @@ module PuppetModule
20
22
  module Pkg
21
23
  class Tasks
22
24
  class Build
23
- def initialize(system)
25
+ def initialize(system, mod_finder)
24
26
  @sys = system
27
+ @mod_finder = mod_finder
25
28
  end
26
29
 
27
30
  def invoke(mod, opts)
@@ -29,7 +32,12 @@ module PuppetModule
29
32
  self.build_opts = opts
30
33
 
31
34
  @sys.mkdir opts.pkg_dir
32
- @sys.sh("fpm #{fpm_opts} #{installed_files}")
35
+ @packager = Packager.new(@sys)
36
+ @packager.package(mod, opts.install_dir, opts.pkg_dir, type, filename)
37
+
38
+ @mod_finder.find_in(opts.dep_install_path).each do |dep|
39
+ @packager.package(dep, File.join(opts.dep_build_path, dep.name), opts.pkg_dir, type, filename_for(dep.name, dep.author))
40
+ end
33
41
  end
34
42
 
35
43
  def type
@@ -45,85 +53,8 @@ module PuppetModule
45
53
  attr_accessor :modinfo
46
54
  attr_accessor :build_opts
47
55
 
48
- def fpm_opts
49
- [ src_fmt,
50
- dest_fmt,
51
- name,
52
- version,
53
- arch,
54
- maintainer,
55
- url,
56
- description,
57
- license,
58
- dependencies,
59
- chdir,
60
- output ].join " "
61
- end
62
-
63
- def pkg_name
64
- "puppet-mod-#{modinfo.author}-#{modinfo.name}"
65
- end
66
-
67
- def name
68
- "-n #{pkg_name}"
69
- end
70
-
71
- def version
72
- "-v #{modinfo.version}"
73
- end
74
-
75
- def arch
76
- "-a all"
77
- end
78
-
79
- def maintainer
80
- optionally('-m', modinfo.author_full)
81
- end
82
-
83
- def url
84
- optionally('--url', modinfo.project_page)
85
- end
86
-
87
- def description
88
- optionally('--description', modinfo.summary)
89
- end
90
-
91
- def license
92
- optionally('--license', modinfo.license)
93
- end
94
-
95
- def dependencies
96
- return "" unless modinfo.dependencies
97
-
98
- modinfo.dependencies.map do |dep|
99
- dep[:versions].map do |version_constraint|
100
- "-d 'puppet-mod-#{dep[:author]}-#{dep[:name]} #{version_constraint}'"
101
- end
102
- end
103
- end
104
-
105
- def src_fmt
106
- "-s dir"
107
- end
108
-
109
- def chdir
110
- "-C #{build_opts.install_dir}"
111
- end
112
-
113
- def installed_files
114
- "."
115
- end
116
-
117
- def output
118
- "-p #{build_opts.pkg_dir}/#{filename}"
119
- end
120
-
121
- def dest_fmt
122
- "-t #{type}"
123
- end
124
-
125
- def optionally(switch, field)
126
- field ? "#{switch} '#{field}'" : ""
56
+ def pkg_name(mod = modinfo.name, author = modinfo.author)
57
+ "puppet-mod-#{author}-#{mod}"
127
58
  end
128
59
  end
129
60
  end
@@ -7,6 +7,10 @@ module PuppetModule
7
7
  type :deb
8
8
 
9
9
  filename '#{pkg_name}_VERSION_ARCH.deb'
10
+
11
+ def filename_for(mod, author)
12
+ "#{pkg_name(mod, author)}_VERSION_ARCH.deb"
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -7,17 +7,19 @@ module PuppetModule
7
7
  end
8
8
 
9
9
  def invoke(mod, opts)
10
- @mod_name = mod.name
10
+ @mod = mod
11
11
  @out_dir = opts.install_dir
12
12
 
13
13
  @sys.mkdir install_path
14
14
  @sys.cp assets_to_install, install_path
15
+
16
+ install_deps if opts.recursive
15
17
  end
16
18
 
17
19
  private
18
20
 
19
21
  def install_path
20
- File.join(@out_dir, dest_path, @mod_name)
22
+ File.join(@out_dir, dest_path, @mod.name)
21
23
  end
22
24
 
23
25
  def dest_path
@@ -27,6 +29,19 @@ module PuppetModule
27
29
  def assets_to_install
28
30
  ['Modulefile','manifests','templates','lib','files']
29
31
  end
32
+
33
+ def install_deps
34
+ # TODO: Refactor!!! Too many hardcoded paths
35
+ @mod.dependencies.each do |dep|
36
+ @sys.sh("puppet module install -i tmp/deps_inst -v '#{dep[:versions].join(' ')}' #{dep[:author]}/#{dep[:name]}")
37
+ end
38
+
39
+ @sys.ls('tmp/deps_inst').each do |dep|
40
+ @sys.mkdir "tmp/deps_build/#{dep}#{dest_path}/#{dep}"
41
+ @sys.cp assets_to_install.map { |a| "tmp/deps_inst/#{dep}/#{a}" },
42
+ "tmp/deps_build/#{dep}#{dest_path}/#{dep}"
43
+ end
44
+ end
30
45
  end
31
46
  end
32
47
  end
@@ -0,0 +1,24 @@
1
+ module PuppetModule
2
+ module Pkg
3
+ class Tasks
4
+ class ModuleFinder
5
+ def initialize(system, parser = Modulefile)
6
+ @sys = system
7
+ @parser = parser
8
+ end
9
+
10
+ def find_in(path)
11
+ @sys.ls(path).map do |mod|
12
+ @parser.parse(File.join(path, mod, "Modulefile"))
13
+ end
14
+ end
15
+
16
+ class Disabled < ModuleFinder
17
+ def find_in(path)
18
+ []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -26,7 +26,7 @@ module PuppetModule
26
26
  private
27
27
 
28
28
  def name(s)
29
- @metadata.author, @metadata.name = s.split '-'
29
+ @metadata.author, @metadata.name = s.split %r{[-/]}
30
30
  end
31
31
 
32
32
  def version(s)
@@ -0,0 +1,107 @@
1
+ module PuppetModule
2
+ module Pkg
3
+ class Tasks
4
+ class Packager
5
+ def initialize(system)
6
+ @sys = system
7
+ end
8
+
9
+ def package(mod, install_dir, pkg_dir, type, filename)
10
+ self.modinfo = mod
11
+ @install_dir = install_dir
12
+ @pkg_dir = pkg_dir
13
+
14
+ @type = type
15
+ @filename = filename
16
+ @sys.sh("fpm #{fpm_opts} #{installed_files}")
17
+ end
18
+
19
+ private
20
+
21
+ attr_accessor :modinfo
22
+
23
+ def fpm_opts
24
+ [ src_fmt,
25
+ dest_fmt,
26
+ name,
27
+ version,
28
+ arch,
29
+ maintainer,
30
+ url,
31
+ description,
32
+ license,
33
+ dependencies,
34
+ chdir,
35
+ output ].join " "
36
+ end
37
+
38
+ def pkg_name
39
+ "puppet-mod-#{modinfo.author}-#{modinfo.name}"
40
+ end
41
+
42
+ def name
43
+ "-n #{pkg_name}"
44
+ end
45
+
46
+ def version
47
+ "-v #{modinfo.version}"
48
+ end
49
+
50
+ def arch
51
+ "-a all"
52
+ end
53
+
54
+ def maintainer
55
+ optionally('-m', modinfo.author_full)
56
+ end
57
+
58
+ def url
59
+ optionally('--url', modinfo.project_page)
60
+ end
61
+
62
+ def description
63
+ optionally('--description', modinfo.summary)
64
+ end
65
+
66
+ def license
67
+ optionally('--license', modinfo.license)
68
+ end
69
+
70
+ def dependencies
71
+ return "" unless modinfo.dependencies
72
+
73
+ modinfo.dependencies.map do |dep|
74
+ dep[:versions].map do |version_constraint|
75
+ "-d 'puppet-mod-#{dep[:author]}-#{dep[:name]} #{version_constraint}'"
76
+ end
77
+ end
78
+ end
79
+
80
+ def src_fmt
81
+ "-s dir"
82
+ end
83
+
84
+ def chdir
85
+ "-C #{@install_dir}"
86
+ end
87
+
88
+ def installed_files
89
+ "."
90
+ end
91
+
92
+ def output
93
+ "-p #{@pkg_dir}/#{@filename}"
94
+ end
95
+
96
+ def dest_fmt
97
+ "-t #{@type}"
98
+ end
99
+
100
+ def optionally(switch, field)
101
+ field ? "#{switch} '#{field}'" : ""
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+
@@ -1,6 +1,7 @@
1
1
  require 'rake/tasklib'
2
2
 
3
3
  require 'puppet_module/pkg/tasks/system'
4
+ require 'puppet_module/pkg/tasks/module_finder'
4
5
  require 'puppet_module/pkg/tasks/deb'
5
6
  require 'puppet_module/pkg/tasks/rpm'
6
7
  require 'puppet_module/pkg/tasks/install'
@@ -10,11 +11,16 @@ module PuppetModule
10
11
  module Pkg
11
12
  class Tasks
12
13
  class RakeTasks < Rake::TaskLib
13
- def initialize(mod_info)
14
+ def initialize(mod_info, custom_opts)
14
15
  sys = System.new
15
- options = OpenStruct.new(
16
- :install_dir => 'build',
17
- :pkg_dir => 'pkg')
16
+ options = OpenStruct.new({
17
+ :install_dir => 'build',
18
+ :pkg_dir => 'pkg',
19
+ :dep_install_path => 'tmp/deps_inst',
20
+ :dep_build_path => 'tmp/deps_build',
21
+ :recursive => false
22
+ }.merge(custom_opts))
23
+ mod_finder = (options.recursive ? ModuleFinder : ModuleFinder::Disabled).new sys
18
24
 
19
25
  desc "Install the module in a local temp dir"
20
26
  task :install => :clean do
@@ -28,12 +34,12 @@ module PuppetModule
28
34
 
29
35
  desc "Wraps the module into a Debian package"
30
36
  task :deb => :install do
31
- Deb.new(sys).invoke(mod_info, options)
37
+ Deb.new(sys, mod_finder).invoke(mod_info, options)
32
38
  end
33
39
 
34
40
  desc "Wraps the module into a RPM package"
35
41
  task :rpm => :install do
36
- RPM.new(sys).invoke(mod_info, options)
42
+ RPM.new(sys, mod_finder).invoke(mod_info, options)
37
43
  end
38
44
  end
39
45
  end
@@ -7,6 +7,10 @@ module PuppetModule
7
7
  type :rpm
8
8
 
9
9
  filename '#{pkg_name}-VERSION.ARCH.rpm'
10
+
11
+ def filename_for(mod, author)
12
+ "#{pkg_name(mod, author)}-VERSION_ARCH.rpm"
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -15,7 +15,12 @@ module PuppetModule
15
15
  end
16
16
 
17
17
  def sh(cmd)
18
- `#{cmd}`
18
+ # TODO: This should be supported through an external logger!
19
+ puts `#{cmd}`
20
+ end
21
+
22
+ def ls(path)
23
+ Dir.new(path).entries.reject { |d| d =~ /^\.*$/ }
19
24
  end
20
25
 
21
26
  private
@@ -1,5 +1,5 @@
1
1
  module PuppetModule
2
2
  module Pkg
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_runtime_dependency "fpm", "~> 0.4"
29
+ spec.add_runtime_dependency "puppet", "~> 3.4"
29
30
 
30
31
  spec.add_development_dependency "bundler", "~> 1.3"
31
32
  spec.add_development_dependency "rake"
@@ -5,15 +5,31 @@ describe 'deb task' do
5
5
  do_into_tmp_module('testmod', t)
6
6
  end
7
7
 
8
- describe 'by default' do
9
- let(:pkg) { 'pkg/puppet-mod-testdev-testmod_0.0.1_all.deb' }
8
+ let(:pkg) { 'pkg/puppet-mod-testdev-testmod_0.0.1_all.deb' }
10
9
 
10
+ describe 'by default' do
11
11
  it 'build a package into the `pkg` folder' do
12
12
  `rake deb`
13
13
 
14
14
  assert file?(pkg), "expected package #{pkg} to exist"
15
15
  end
16
16
  end
17
+
18
+ describe 'when asked to build packages for dependencies as well' do
19
+ let(:dep_pkgs) {[
20
+ 'pkg/puppet-mod-puppetlabs-apache_*_all.deb',
21
+ 'pkg/puppet-mod-puppetlabs-stdlib_*_all.deb',
22
+ 'pkg/puppet-mod-puppetlabs-concat_*_all.deb',
23
+ ]}
24
+
25
+ it 'recursively builds packages for each dependency' do
26
+ `rake -f Rakefile.recursive deb`
27
+
28
+ dep_pkgs.each do |dep_pkg|
29
+ refute Dir.glob(dep_pkg).empty?, "expected package #{dep_pkg} to exist"
30
+ end
31
+ end
32
+ end
17
33
  end
18
34
 
19
35
  describe 'rpm task' do
@@ -7,7 +7,6 @@ summary 'A silly module, only useful for testing'
7
7
  description 'A long description of this silly module'
8
8
  project_page 'https://example.com/testmod/home'
9
9
 
10
- dependency 'user_1/mod_1', '= 1.2.3'
11
- dependency 'user_2/mod_2', '>= 1.0.0 <3.2'
10
+ dependency 'puppetlabs/apache', '1.0.1'
12
11
 
13
12
  unsupported_field 'I don`t know what I am for'
@@ -0,0 +1,2 @@
1
+ name 'olddev/oldmod'
2
+ version 'deprecated_version'
@@ -0,0 +1,13 @@
1
+ name 'testdev-testmod'
2
+ version '0.0.1'
3
+ source 'https://example.com/git/testmod'
4
+ author 'Test Developer <test@example.com>'
5
+ license 'Apache License, Version 2.0'
6
+ summary 'A silly module, only useful for testing'
7
+ description 'A long description of this silly module'
8
+ project_page 'https://example.com/testmod/home'
9
+
10
+ dependency 'user_1/mod_1', '= 1.2.3'
11
+ dependency 'user_2/mod_2', '>= 1.0.0 <3.2'
12
+
13
+ unsupported_field 'I don`t know what I am for'
@@ -0,0 +1,3 @@
1
+ require 'puppet_module/pkg/tasks'
2
+
3
+ PuppetModule::Pkg::Tasks.new :recursive => true
@@ -16,7 +16,7 @@ describe PuppetModule::Pkg::Tasks::Modulefile do
16
16
  let(:parser) { PuppetModule::Pkg::Tasks::Modulefile }
17
17
 
18
18
  it 'reads a Modulefile and maps its fields to an object value' do
19
- metadata = parser.parse 'Modulefile'
19
+ metadata = parser.parse 'Modulefile.ok'
20
20
 
21
21
  metadata.name.must_equal 'testmod'
22
22
  metadata.author.must_equal 'testdev'
@@ -49,4 +49,11 @@ describe PuppetModule::Pkg::Tasks::Modulefile do
49
49
  metadata = parser.parse 'Modulefile'
50
50
  metadata.unsupported_field.must_be_nil
51
51
  end
52
+
53
+ it 'also supports name in the old `author/name` format' do
54
+ metadata = parser.parse 'Modulefile.deprecated'
55
+ metadata.name.must_equal 'oldmod'
56
+ metadata.author.must_equal 'olddev'
57
+ metadata.version.must_equal 'deprecated_version'
58
+ end
52
59
  end
@@ -59,11 +59,27 @@ describe PuppetModule::Pkg::Tasks::System do
59
59
  end
60
60
  end
61
61
 
62
- describe 'exec' do
62
+ describe 'sh' do
63
63
  it 'executes given command in system`s shell' do
64
64
  fs.sh 'touch test_file'
65
65
 
66
66
  assert file?('test_file'), "expected file test_file to have been created, but it was not"
67
67
  end
68
68
  end
69
+
70
+ describe 'ls' do
71
+ it 'returns an array with the entries of a specific folder' do
72
+ mkdir 'a_dir/a'
73
+ mkdir 'a_dir/b'
74
+ mkdir 'a_dir/c'
75
+ mkdir 'a_dir/c/d'
76
+
77
+ listing = fs.ls 'a_dir'
78
+
79
+ listing.length.must_equal 3
80
+ listing.must_include 'a'
81
+ listing.must_include 'b'
82
+ listing.must_include 'c'
83
+ end
84
+ end
69
85
  end
@@ -4,6 +4,8 @@ describe 'packaging tasks' do
4
4
  let(:deb_task) { PuppetModule::Pkg::Tasks::Deb }
5
5
  let(:rpm_task) { PuppetModule::Pkg::Tasks::RPM }
6
6
  let(:sys) { stub_everything }
7
+ let(:mod_finder) { stub_everything }
8
+
7
9
  let(:minimal_mod) { OpenStruct.new(
8
10
  :name => 'my_mod',
9
11
  :author => 'a_dev',
@@ -23,15 +25,21 @@ describe 'packaging tasks' do
23
25
  { :author => 'user_2', :name => 'mod_2', :versions => ['> 2.0', '<= 3.0'] },
24
26
  ])
25
27
  }
28
+
26
29
  let(:opts) { OpenStruct.new(
27
30
  :pkg_dir => 'pkg',
28
- :install_dir => 'some/where')
31
+ :install_dir => 'some/where',
32
+ :recursive => false)
29
33
  }
30
34
 
35
+ before do
36
+ mod_finder.stubs(:find_in).returns([])
37
+ end
38
+
31
39
  it 'creates the output folder' do
32
40
  sys.expects(:mkdir).with(regexp_matches(/#{opts.pkg_dir}/))
33
41
 
34
- deb_task.new(sys).invoke(mod, opts)
42
+ deb_task.new(sys, mod_finder).invoke(mod, opts)
35
43
  end
36
44
 
37
45
  it 'builds a package using all available module info' do
@@ -51,7 +59,7 @@ describe 'packaging tasks' do
51
59
  regexp_matches(/-C #{opts.install_dir}/),
52
60
  regexp_matches(/\.$/)))
53
61
 
54
- deb_task.new(sys).invoke(mod, opts)
62
+ deb_task.new(sys, mod_finder).invoke(mod, opts)
55
63
  end
56
64
 
57
65
  it 'doesn`t complain if optional module info are missing' do
@@ -62,7 +70,7 @@ describe 'packaging tasks' do
62
70
  regexp_matches(/--license /)
63
71
  )))
64
72
 
65
- deb_task.new(sys).invoke(minimal_mod, opts)
73
+ deb_task.new(sys, mod_finder).invoke(minimal_mod, opts)
66
74
  end
67
75
 
68
76
  describe 'deb task' do
@@ -71,7 +79,7 @@ describe 'packaging tasks' do
71
79
  regexp_matches(/-t deb/),
72
80
  regexp_matches(/-p #{opts.pkg_dir}\/puppet-mod-#{mod.author}-#{mod.name}_VERSION_ARCH.deb/)))
73
81
 
74
- deb_task.new(sys).invoke(mod, opts)
82
+ deb_task.new(sys, mod_finder).invoke(mod, opts)
75
83
  end
76
84
  end
77
85
 
@@ -81,7 +89,52 @@ describe 'packaging tasks' do
81
89
  regexp_matches(/-t rpm/),
82
90
  regexp_matches(/-p #{opts.pkg_dir}\/puppet-mod-#{mod.author}-#{mod.name}-VERSION.ARCH.rpm/)))
83
91
 
84
- rpm_task.new(sys).invoke(mod, opts)
92
+ rpm_task.new(sys, mod_finder).invoke(mod, opts)
93
+ end
94
+ end
95
+
96
+ describe 'when recursively building packages for module`s dependencies' do
97
+ let(:opts) { OpenStruct.new(
98
+ :pkg_dir => 'module_pkg',
99
+ :install_dir => 'some/where/else',
100
+ :dep_build_path => 'some/tmp/folder',
101
+ :dep_install_path => 'another/tmp/folder',
102
+ :recursive => true)
103
+ }
104
+
105
+ let(:depmod_1) { OpenStruct.new(
106
+ :name => 'mod_1',
107
+ :author => 'dev_1',
108
+ :version => 'version_1',
109
+ )}
110
+
111
+ let(:depmod_2) { OpenStruct.new(
112
+ :name => 'mod_2',
113
+ :author => 'dev_2',
114
+ :version => 'version_2',
115
+ )}
116
+
117
+ it 'builds a package for each installed dependency' do
118
+ mod_finder.expects(:find_in).with(opts.dep_install_path)\
119
+ .returns([ depmod_1, depmod_2 ])
120
+
121
+ sys.expects(:sh)\
122
+ .with(all_of(
123
+ regexp_matches(/^fpm/),
124
+ regexp_matches(/-n puppet-mod-#{depmod_1.author}-#{depmod_1.name}/),
125
+ regexp_matches(/-v #{depmod_1.version}/),
126
+ regexp_matches(/-C #{opts.dep_build_path}\/#{depmod_1.name}/),
127
+ regexp_matches(/-p #{opts.pkg_dir}\/puppet-mod-#{depmod_1.author}-#{depmod_1.name}_VERSION_ARCH.deb/),
128
+ regexp_matches(/\.$/)))\
129
+ .with(all_of(
130
+ regexp_matches(/^fpm/),
131
+ regexp_matches(/-n puppet-mod-#{depmod_2.author}-#{depmod_2.name}/),
132
+ regexp_matches(/-v #{depmod_2.version}/),
133
+ regexp_matches(/-C #{opts.dep_build_path}\/#{depmod_2.name}/),
134
+ regexp_matches(/-p #{opts.pkg_dir}\/puppet-mod-#{depmod_2.author}-#{depmod_2.name}_VERSION_ARCH.deb/),
135
+ regexp_matches(/\.$/)))
136
+
137
+ deb_task.new(sys, mod_finder).invoke(minimal_mod, opts)
85
138
  end
86
139
  end
87
140
  end
@@ -3,11 +3,24 @@ require 'test_helper'
3
3
  describe PuppetModule::Pkg::Tasks::Install do
4
4
  let(:install_task) { PuppetModule::Pkg::Tasks::Install }
5
5
  let(:sys) { stub_everything }
6
- let(:mod) { OpenStruct.new(:name => 'my_mod')}
7
- let(:opts) { OpenStruct.new(:install_dir => 'build')}
6
+ let(:mod) { OpenStruct.new(
7
+ :name => 'my_mod',
8
+ :dependencies => [
9
+ { :author => 'user_1', :name => 'mod_1', :versions => ['< 1'] },
10
+ { :author => 'user_2', :name => 'mod_2', :versions => ['> 2.0', '<= 3.0'] },
11
+ ])
12
+ }
13
+ let(:opts) { OpenStruct.new(
14
+ :install_dir => 'build',
15
+ :recursive => false
16
+ )}
8
17
  let(:dest_path) { "usr/share/puppet/modules/#{mod.name}" }
9
18
  let(:install_path) { join(opts.install_dir, dest_path) }
10
19
 
20
+ before do
21
+ sys.stubs(:ls).returns(['mod_1', 'mod_2'])
22
+ end
23
+
11
24
  it 'creates the output folder' do
12
25
  sys.expects(:mkdir).with(regexp_matches(/#{opts.install_dir}/))
13
26
 
@@ -20,7 +33,7 @@ describe PuppetModule::Pkg::Tasks::Install do
20
33
  install_task.new(sys).invoke(mod, opts)
21
34
  end
22
35
 
23
- it 'installs all the relevant directories into the output folder' do
36
+ it 'installs all the relevant assets into the output folder' do
24
37
  sys.expects(:cp).with(
25
38
  includes(
26
39
  'Modulefile',
@@ -32,4 +45,59 @@ describe PuppetModule::Pkg::Tasks::Install do
32
45
 
33
46
  install_task.new(sys).invoke(mod, opts)
34
47
  end
48
+
49
+ it 'doesn`t install dependencies by default' do
50
+ sys.expects(:sh).at_most_once.with(Not(regexp_matches(/puppet module install/)))
51
+
52
+ install_task.new(sys).invoke(mod, opts)
53
+ end
54
+
55
+ describe 'when managing dependencies recursively' do
56
+ let(:opts) { OpenStruct.new(
57
+ :install_dir => 'build',
58
+ :recursive => true
59
+ )}
60
+
61
+ it 'asks puppet to install all the dependencies into a temp folder' do
62
+ sys.expects(:sh)\
63
+ .with(
64
+ regexp_matches(/puppet module install -i tmp\/deps_inst -v '< 1' user_1\/mod_1/))\
65
+ .with(
66
+ regexp_matches(/puppet module install -i tmp\/deps_inst -v '> 2.0 <= 3.0' user_2\/mod_2/))
67
+
68
+ install_task.new(sys).invoke(mod, opts)
69
+ end
70
+
71
+ it 'creates the build folder for each installed dependency' do
72
+ sys.expects(:ls).with('tmp/deps_inst').returns(['mod_1','mod_2','mod_3'])
73
+ sys.expects(:mkdir)\
74
+ .with(regexp_matches(%r{tmp/deps_build/mod_1/usr/share/puppet/modules/mod_1}))
75
+ .with(regexp_matches(%r{tmp/deps_build/mod_2/usr/share/puppet/modules/mod_2}))
76
+ .with(regexp_matches(%r{tmp/deps_build/mod_3/usr/share/puppet/modules/mod_3}))
77
+
78
+ install_task.new(sys).invoke(mod, opts)
79
+ end
80
+
81
+ it 'installs the relevant assets for each dependency into a separate directory' do
82
+ sys.expects(:cp)\
83
+ .with(
84
+ includes(
85
+ 'tmp/deps_inst/mod_1/Modulefile',
86
+ 'tmp/deps_inst/mod_1/manifests',
87
+ 'tmp/deps_inst/mod_1/templates',
88
+ 'tmp/deps_inst/mod_1/files',
89
+ 'tmp/deps_inst/mod_1/lib'),
90
+ 'tmp/deps_build/mod_1/usr/share/puppet/modules/mod_1')
91
+ .with(
92
+ includes(
93
+ 'tmp/deps_inst/mod_2/Modulefile',
94
+ 'tmp/deps_inst/mod_2/manifests',
95
+ 'tmp/deps_inst/mod_2/templates',
96
+ 'tmp/deps_inst/mod_2/files',
97
+ 'tmp/deps_inst/mod_2/lib'),
98
+ 'tmp/deps_build/mod_2/usr/share/puppet/modules/mod_2')
99
+
100
+ install_task.new(sys).invoke(mod, opts)
101
+ end
102
+ end
35
103
  end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ describe PuppetModule::Pkg::Tasks::ModuleFinder do
4
+ let(:sys) { mock }
5
+ let(:parser_class) { stub_everything }
6
+ let(:mod_finder) { PuppetModule::Pkg::Tasks::ModuleFinder.new sys, parser_class }
7
+
8
+ describe '#find_in' do
9
+ it 'parses the modulefile for each module found in the given directory' do
10
+ sys.expects(:ls).with('root/folder').returns(['mod_1', 'mod_2'])
11
+ parser_class.expects(:parse)\
12
+ .with('root/folder/mod_1/Modulefile')\
13
+ .with('root/folder/mod_2/Modulefile')\
14
+
15
+ mod_finder.find_in('root/folder')
16
+ end
17
+
18
+ it 'returns a list of parsed modulefiles' do
19
+ sys.stubs(:ls).with('root/folder').returns(['mod_3', 'mod_4'])
20
+ parser_class.stubs(:parse).returns(OpenStruct.new)
21
+
22
+ modules = mod_finder.find_in('root/folder')
23
+ modules.length.must_equal 2
24
+ modules.first.must_be_kind_of OpenStruct
25
+ end
26
+ end
27
+
28
+ describe PuppetModule::Pkg::Tasks::ModuleFinder::Disabled do
29
+ let(:mod_finder) { PuppetModule::Pkg::Tasks::ModuleFinder::Disabled.new nil, nil}
30
+
31
+ describe '#find_in' do
32
+ it 'returns an empty list of dependencies, no matter the arguments' do
33
+ mod_finder.find_in('one/two/three').must_equal []
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet_module_packaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Zanella
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - rubygems-stefanozanella.crt
12
- date: 2014-04-01 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fpm
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: puppet
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.4'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.4'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +160,9 @@ files:
146
160
  - lib/puppet_module/pkg/tasks/clean.rb
147
161
  - lib/puppet_module/pkg/tasks/deb.rb
148
162
  - lib/puppet_module/pkg/tasks/install.rb
163
+ - lib/puppet_module/pkg/tasks/module_finder.rb
149
164
  - lib/puppet_module/pkg/tasks/modulefile.rb
165
+ - lib/puppet_module/pkg/tasks/packager.rb
150
166
  - lib/puppet_module/pkg/tasks/rake_tasks.rb
151
167
  - lib/puppet_module/pkg/tasks/rpm.rb
152
168
  - lib/puppet_module/pkg/tasks/system.rb
@@ -159,10 +175,13 @@ files:
159
175
  - test/end_to_end/pkg_test.rb
160
176
  - test/end_to_end/tasks_test.rb
161
177
  - test/fixture/testmod/Modulefile
178
+ - test/fixture/testmod/Modulefile.deprecated
162
179
  - test/fixture/testmod/Modulefile.no_name_or_author
163
180
  - test/fixture/testmod/Modulefile.no_version
181
+ - test/fixture/testmod/Modulefile.ok
164
182
  - test/fixture/testmod/README.md
165
183
  - test/fixture/testmod/Rakefile
184
+ - test/fixture/testmod/Rakefile.recursive
166
185
  - test/fixture/testmod/files/example.dat
167
186
  - test/fixture/testmod/lib/utils.rb
168
187
  - test/fixture/testmod/manifests/defined_type.pp
@@ -181,6 +200,7 @@ files:
181
200
  - test/unit/build_test.rb
182
201
  - test/unit/clean_test.rb
183
202
  - test/unit/install_test.rb
203
+ - test/unit/module_finder_test.rb
184
204
  homepage: https://github.com/stefanozanella/puppet_module_packaging
185
205
  licenses:
186
206
  - MIT
@@ -212,10 +232,13 @@ test_files:
212
232
  - test/end_to_end/pkg_test.rb
213
233
  - test/end_to_end/tasks_test.rb
214
234
  - test/fixture/testmod/Modulefile
235
+ - test/fixture/testmod/Modulefile.deprecated
215
236
  - test/fixture/testmod/Modulefile.no_name_or_author
216
237
  - test/fixture/testmod/Modulefile.no_version
238
+ - test/fixture/testmod/Modulefile.ok
217
239
  - test/fixture/testmod/README.md
218
240
  - test/fixture/testmod/Rakefile
241
+ - test/fixture/testmod/Rakefile.recursive
219
242
  - test/fixture/testmod/files/example.dat
220
243
  - test/fixture/testmod/lib/utils.rb
221
244
  - test/fixture/testmod/manifests/defined_type.pp
@@ -234,3 +257,4 @@ test_files:
234
257
  - test/unit/build_test.rb
235
258
  - test/unit/clean_test.rb
236
259
  - test/unit/install_test.rb
260
+ - test/unit/module_finder_test.rb