librarian-puppet 1.2.0 → 1.3.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: 9e38c81fc33fcc4e0223be2ce7f705a93f3f0896
4
- data.tar.gz: e48f55419ffc8e6fd2df107c08111c35f0c679fa
3
+ metadata.gz: aea15d42f3f537214c5256248b821f12558b266f
4
+ data.tar.gz: d0f110467f43c2f090bb8697988731f0020e32b2
5
5
  SHA512:
6
- metadata.gz: e9f5ade15b27c5a35eb7ada03313f1da390cc5854d1abfe184041640192bcfcd2e6601b4bdf2cfe21ae65eda5bd912a6bf0286c1c1bd1414e5c364b9b673359d
7
- data.tar.gz: 2054b93a68ce5f4a9e64c7bf02a057ce274250737528f97ccaa39c4058dad3828c7c7e59bebea6dc8d3d0dd82a75dbcd0640cf6c3d19201a12031e3bb12003f7
6
+ metadata.gz: 9b0df8f65615913ab73d48d03a8d29fc1753cf26009a96aaf821e49368d8fbbab1b51dd89c513f98644764dcda6bb84c826bb0b4e2bf3132f42964ce3de1aeb8
7
+ data.tar.gz: 03ffefa4e42cabf289f754b24763d98a44f671f8198f89f27a39758703615e1c090259f9a1426c15d03bb1f2d3e30523b7c32562739c142abb336ba887689164
data/README.md CHANGED
@@ -37,17 +37,20 @@ See the [Changelog](Changelog.md) for more details.
37
37
 
38
38
  ## The Puppetfile
39
39
 
40
- Every Puppet repository that uses Librarian-puppet will have a file named
41
- `Puppetfile` in the root directory of that repository. The full specification
42
- for which modules your puppet infrastructure repository depends goes in here.
40
+ Every Puppet repository that uses Librarian-puppet may have a file named
41
+ `Puppetfile`, `metadata.json` or `Modulefile` in the root directory of that repository.
42
+ The full specification
43
+ for which modules your puppet infrastructure repository depends goes in here.
43
44
 
44
- ### Simple Puppetfile
45
+ ### Simple usage
45
46
 
46
- This Puppetfile will download all the dependencies listed in your Modulefile from the Puppet Forge
47
+ If no Puppetfile is present, `librarian-puppet` will download all the dependencies
48
+ listed in your `metadata.json` or `Modulefile` from the Puppet Forge,
49
+ as if the Puppetfile contained
47
50
 
48
51
  forge "https://forgeapi.puppetlabs.com"
49
52
 
50
- modulefile
53
+ metadata
51
54
 
52
55
 
53
56
  ### Example Puppetfile
@@ -0,0 +1 @@
1
+ require "librarian/puppet/action/install"
@@ -0,0 +1,24 @@
1
+ module Librarian
2
+ module Puppet
3
+ module Action
4
+ class Install < Librarian::Action::Install
5
+
6
+ private
7
+
8
+ def create_install_path
9
+ install_path.rmtree if install_path.exist? && destructive?
10
+ install_path.mkpath
11
+ end
12
+
13
+ def destructive?
14
+ environment.config_db.local['destructive'] == 'true'
15
+ end
16
+
17
+ def check_specfile
18
+ # don't fail if Puppetfile doesn't exist as we'll use the Modulefile or metadata.json
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,7 @@ require 'librarian/helpers'
2
2
 
3
3
  require 'librarian/cli'
4
4
  require 'librarian/puppet'
5
+ require 'librarian/puppet/action'
5
6
 
6
7
  module Librarian
7
8
  module Puppet
@@ -47,11 +48,6 @@ module Librarian
47
48
  option "use-v1-api", :type => :boolean, :default => true
48
49
  def install
49
50
 
50
- unless File.exist?('Puppetfile')
51
- say "Could not find Puppetfile in #{Dir.pwd}", :red
52
- exit 1
53
- end
54
-
55
51
  ensure!
56
52
  clean! if options["clean"]
57
53
  unless options["destructive"].nil?
@@ -89,6 +85,14 @@ module Librarian
89
85
  def version
90
86
  say "librarian-puppet v#{Librarian::Puppet::VERSION}"
91
87
  end
88
+
89
+ private
90
+
91
+ # override the actions to use our own
92
+
93
+ def install!(options = { })
94
+ Action::Install.new(environment, options).run
95
+ end
92
96
  end
93
97
  end
94
98
  end
@@ -17,6 +17,14 @@ module Librarian
17
17
  def run(specfile = nil, sources = [])
18
18
  specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
19
19
 
20
+ if specfile.kind_of?(Pathname) and !File.exists?(specfile)
21
+ debug { "Specfile not found, using defaults: #{specfile}" }
22
+ specfile = Proc.new do
23
+ forge "https://forgeapi.puppetlabs.com"
24
+ metadata
25
+ end
26
+ end
27
+
20
28
  Target.new(self).tap do |target|
21
29
  target.precache_sources(sources)
22
30
  debug_named_source_cache("Pre-Cached Sources", target)
@@ -30,17 +38,20 @@ module Librarian
30
38
  end
31
39
 
32
40
  class Receiver < Librarian::Dsl::Receiver
33
- attr_reader :specfile
41
+ attr_reader :specfile, :working_path
34
42
 
35
43
  # save the specfile and call librarian
36
44
  def run(specfile = nil)
45
+ @working_path = specfile.kind_of?(Pathname) ? specfile.parent : Pathname.new(Dir.pwd)
37
46
  @specfile = specfile
38
47
  super
39
48
  end
40
49
 
41
50
  # implement the 'modulefile' syntax for Puppetfile
42
51
  def modulefile
43
- File.read(Pathname.new(specfile).parent.join('Modulefile')).lines.each do |line|
52
+ f = modulefile_path
53
+ raise Error, "Modulefile file does not exist: #{f}" unless File.exists?(f)
54
+ File.read(f).lines.each do |line|
44
55
  regexp = /\s*dependency\s+('|")([^'"]+)\1\s*(?:,\s*('|")([^'"]+)\3)?/
45
56
  regexp =~ line && mod($2, $4)
46
57
  end
@@ -48,11 +59,28 @@ module Librarian
48
59
 
49
60
  # implement the 'metadata' syntax for Puppetfile
50
61
  def metadata
51
- dependencyList = JSON.parse(File.read(Pathname.new(specfile).parent.join('metadata.json')))['dependencies']
62
+ f = working_path.join('metadata.json')
63
+ unless File.exists?(f)
64
+ msg = "Metadata file does not exist: #{f}"
65
+ # try modulefile, in case we don't have a Puppetfile and we are using the default template
66
+ if File.exists?(modulefile_path)
67
+ modulefile
68
+ return
69
+ else
70
+ raise Error, msg
71
+ end
72
+ end
73
+ dependencyList = JSON.parse(File.read(f))['dependencies']
52
74
  dependencyList.each do |d|
53
75
  mod(d['name'], d['version_requirement'])
54
76
  end
55
77
  end
78
+
79
+ private
80
+
81
+ def modulefile_path
82
+ working_path.join('Modulefile')
83
+ end
56
84
  end
57
85
  end
58
86
  end
@@ -13,6 +13,9 @@ module Librarian
13
13
  def initialize(name, requirement, source)
14
14
  assert_name_valid! name
15
15
 
16
+ # Issue #235 fail if forge source is not defined
17
+ raise Error, "forge entry is not defined in Puppetfile" if source.instance_of?(Array) && source.empty?
18
+
16
19
  # let's settle on provider-module syntax instead of provider/module
17
20
  self.name = normalize_name(name)
18
21
  self.requirement = Requirement.new(requirement)
@@ -80,22 +83,6 @@ module Librarian
80
83
  end
81
84
  end
82
85
 
83
- module Action
84
- class Install < Base
85
-
86
- private
87
-
88
- def create_install_path
89
- install_path.rmtree if install_path.exist? && destructive?
90
- install_path.mkpath
91
- end
92
-
93
- def destructive?
94
- environment.config_db.local['destructive'] == 'true'
95
- end
96
- end
97
- end
98
-
99
86
  class ManifestSet
100
87
  include Librarian::Puppet::Util
101
88
 
@@ -94,6 +94,7 @@ module Librarian
94
94
  metadata = ::Puppet::ModuleTool::Metadata.new
95
95
  begin
96
96
  ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
97
+ raise SyntaxError, "Missing version" unless metadata.version
97
98
  rescue ArgumentError, SyntaxError => error
98
99
  warn { "Unable to parse #{modulefile}, ignoring: #{error}" }
99
100
  if metadata.respond_to? :version=
@@ -1,5 +1,5 @@
1
1
  module Librarian
2
2
  module Puppet
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-01 00:00:00.000000000 Z
12
+ date: 2014-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: librarian
@@ -154,6 +154,8 @@ files:
154
154
  - README.md
155
155
  - bin/librarian-puppet
156
156
  - lib/librarian/puppet.rb
157
+ - lib/librarian/puppet/action.rb
158
+ - lib/librarian/puppet/action/install.rb
157
159
  - lib/librarian/puppet/cli.rb
158
160
  - lib/librarian/puppet/dsl.rb
159
161
  - lib/librarian/puppet/environment.rb