librarian-puppet 0.9.1 → 0.9.2.pre

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.
Files changed (52) hide show
  1. data/lib/librarian/puppet.rb +6 -1
  2. data/lib/librarian/puppet/cli.rb +21 -0
  3. data/lib/librarian/puppet/environment.rb +1 -0
  4. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  5. data/lib/librarian/puppet/source/forge.rb +0 -8
  6. data/lib/librarian/puppet/source/git.rb +29 -0
  7. data/lib/librarian/puppet/source/local.rb +1 -0
  8. data/lib/librarian/puppet/version.rb +5 -0
  9. data/vendor/librarian/CHANGELOG.md +17 -0
  10. data/vendor/librarian/Gemfile +2 -0
  11. data/vendor/librarian/README.md +99 -14
  12. data/vendor/librarian/features/chef/cli/init.feature +1 -0
  13. data/vendor/librarian/features/chef/cli/show.feature +13 -1
  14. data/vendor/librarian/lib/librarian/action/base.rb +6 -4
  15. data/vendor/librarian/lib/librarian/chef/cli.rb +21 -0
  16. data/vendor/librarian/lib/librarian/chef/environment.rb +9 -1
  17. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +14 -2
  18. data/vendor/librarian/lib/librarian/chef/source/git.rb +13 -0
  19. data/vendor/librarian/lib/librarian/chef/source/local.rb +8 -2
  20. data/vendor/librarian/lib/librarian/chef/source/site.rb +18 -6
  21. data/vendor/librarian/lib/librarian/cli.rb +54 -24
  22. data/vendor/librarian/lib/librarian/config.rb +7 -0
  23. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  24. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  25. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  26. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  27. data/vendor/librarian/lib/librarian/dependency.rb +1 -5
  28. data/vendor/librarian/lib/librarian/dsl.rb +6 -3
  29. data/vendor/librarian/lib/librarian/dsl/target.rb +0 -4
  30. data/vendor/librarian/lib/librarian/environment.rb +30 -25
  31. data/vendor/librarian/lib/librarian/lockfile.rb +0 -4
  32. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +0 -4
  33. data/vendor/librarian/lib/librarian/lockfile/parser.rb +4 -8
  34. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  35. data/vendor/librarian/lib/librarian/manifest.rb +1 -9
  36. data/vendor/librarian/lib/librarian/resolver.rb +6 -1
  37. data/vendor/librarian/lib/librarian/resolver/implementation.rb +1 -5
  38. data/vendor/librarian/lib/librarian/source/git/repository.rb +10 -6
  39. data/vendor/librarian/lib/librarian/source/local.rb +12 -2
  40. data/vendor/librarian/lib/librarian/spec_change_set.rb +6 -3
  41. data/vendor/librarian/lib/librarian/specfile.rb +0 -4
  42. data/vendor/librarian/lib/librarian/version.rb +1 -1
  43. data/vendor/librarian/librarian.gemspec +1 -0
  44. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +149 -0
  45. data/vendor/librarian/spec/unit/config/database_spec.rb +319 -0
  46. data/vendor/librarian/spec/unit/dependency_spec.rb +6 -0
  47. data/vendor/librarian/spec/unit/manifest_spec.rb +6 -0
  48. metadata +107 -66
  49. data/librarian-puppet.gemspec +0 -130
  50. data/vendor/librarian/.rspec +0 -1
  51. data/vendor/librarian/.travis.yml +0 -6
  52. data/vendor/librarian/lib/librarian/helpers/debug.rb +0 -35
@@ -1,7 +1,12 @@
1
+ require 'librarian'
2
+ require 'puppet'
3
+
1
4
  require 'librarian/puppet/extension'
5
+ require 'librarian/puppet/version'
6
+
7
+ require 'librarian/action/install'
2
8
 
3
9
  module Librarian
4
10
  module Puppet
5
- VERSION = "0.9.1"
6
11
  end
7
12
  end
@@ -35,6 +35,27 @@ module Librarian
35
35
  end
36
36
  end
37
37
 
38
+ desc "install", "Resolves and installs all of the dependencies you specify."
39
+ option "quiet", :type => :boolean, :default => false
40
+ option "verbose", :type => :boolean, :default => false
41
+ option "line-numbers", :type => :boolean, :default => false
42
+ option "clean", :type => :boolean, :default => false
43
+ option "strip-dot-git", :type => :boolean
44
+ option "path", :type => :string
45
+ def install
46
+ ensure!
47
+ clean! if options["clean"]
48
+ if options.include?("strip-dot-git")
49
+ strip_dot_git_val = options["strip-dot-git"] ? "1" : nil
50
+ environment.config_db.local["install.strip-dot-git"] = strip_dot_git_val
51
+ end
52
+ if options.include?("path")
53
+ environment.config_db.local["path"] = options["path"]
54
+ end
55
+ resolve!
56
+ install!
57
+ end
58
+
38
59
  def version
39
60
  say "librarian-puppet v#{Librarian::Puppet::VERSION}"
40
61
  end
@@ -1,6 +1,7 @@
1
1
  require "librarian/environment"
2
2
  require "librarian/puppet/dsl"
3
3
  require "librarian/puppet/source"
4
+ require "librarian/puppet/lockfile/parser"
4
5
 
5
6
  module Librarian
6
7
  module Puppet
@@ -0,0 +1,53 @@
1
+ require 'librarian/manifest'
2
+ require 'librarian/dependency'
3
+ require 'librarian/manifest_set'
4
+
5
+ module Librarian
6
+ class Lockfile
7
+ class Parser
8
+
9
+ def parse(string)
10
+ string = string.dup
11
+ source_type_names_map = Hash[dsl_class.source_types.map{|t| [t[1].lock_name, t[1]]}]
12
+ source_type_names = dsl_class.source_types.map{|t| t[1].lock_name}
13
+ lines = string.split(/(\r|\n|\r\n)+/).select{|l| l =~ /\S/}
14
+ sources = []
15
+ while source_type_names.include?(lines.first)
16
+ source = {}
17
+ source_type_name = lines.shift
18
+ source[:type] = source_type_names_map[source_type_name]
19
+ options = {}
20
+ while lines.first =~ /^ {2}([\w\-\/]+):\s+(.+)$/
21
+ lines.shift
22
+ options[$1.to_sym] = $2
23
+ end
24
+ source[:options] = options
25
+ lines.shift # specs
26
+ manifests = {}
27
+ while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash
28
+ lines.shift
29
+ name = $1
30
+ manifests[name] = {:version => $2, :dependencies => {}}
31
+ while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/
32
+ lines.shift
33
+ manifests[name][:dependencies][$1] = $2.split(/,\s*/)
34
+ end
35
+ end
36
+ source[:manifests] = manifests
37
+ sources << source
38
+ end
39
+ manifests = compile(sources)
40
+ manifests_index = Hash[manifests.map{|m| [m.name, m]}]
41
+ raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
42
+ dependencies = []
43
+ while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash
44
+ lines.shift
45
+ name, requirement = $1, $2.split(/,\s*/)
46
+ dependencies << Dependency.new(name, requirement, manifests_index[name].source)
47
+ end
48
+ Resolution.new(dependencies, manifests)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -1,16 +1,13 @@
1
1
  require 'uri'
2
2
  require 'net/http'
3
3
  require 'json'
4
- require 'librarian/helpers/debug'
5
4
 
6
5
  module Librarian
7
6
  module Puppet
8
7
  module Source
9
8
  class Forge
10
- include Helpers::Debug
11
9
  class Repo
12
10
 
13
- include Helpers::Debug
14
11
  attr_accessor :source, :name
15
12
  private :source=, :name=
16
13
 
@@ -43,12 +40,10 @@ module Librarian
43
40
  cache_version_unpacked! version
44
41
 
45
42
  if install_path.exist?
46
- debug { "Deleting #{relative_path_to(install_path)}" }
47
43
  install_path.rmtree
48
44
  end
49
45
 
50
46
  unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
51
- debug { "Copying #{relative_path_to(unpacked_path)} to #{relative_path_to(install_path)}" }
52
47
  FileUtils.cp_r(unpacked_path, install_path)
53
48
  end
54
49
 
@@ -75,7 +70,6 @@ module Librarian
75
70
  path.mkpath
76
71
 
77
72
  output = `puppet module install -i #{path.to_s} --modulepath #{path.to_s} --ignore-dependencies #{name} 2>&1`
78
- debug { output }
79
73
  end
80
74
 
81
75
  private
@@ -157,8 +151,6 @@ module Librarian
157
151
  install_path = install_path(name)
158
152
  repo = repo(name)
159
153
 
160
- debug { "Installing #{manifest}" }
161
-
162
154
  repo.install_version! version, install_path
163
155
  end
164
156
 
@@ -14,6 +14,28 @@ module Librarian
14
14
  command = %W(rev-parse #{reference}^{commit} --quiet)
15
15
  run!(command, :chdir => true).strip
16
16
  end
17
+
18
+ def dependencies
19
+ return {} unless modulefile?
20
+
21
+ metadata = ::Puppet::ModuleTool::Metadata.new
22
+
23
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
24
+
25
+ metadata.dependencies.inject({}) do |h, dependency|
26
+ name = dependency.instance_variable_get(:@full_module_name)
27
+ version = dependency.instance_variable_get(:@version_requirement)
28
+ h.update(name => version)
29
+ end
30
+ end
31
+
32
+ def modulefile
33
+ File.join(path, 'Modulefile')
34
+ end
35
+
36
+ def modulefile?
37
+ File.exists?(modulefile)
38
+ end
17
39
  end
18
40
  end
19
41
  end
@@ -22,6 +44,13 @@ module Librarian
22
44
  module Source
23
45
  class Git < Librarian::Source::Git
24
46
  include Local
47
+
48
+ def fetch_dependencies(name, version, extra)
49
+ repository.dependencies.map do |k, v|
50
+ Dependency.new(k, v, nil)
51
+ end
52
+ end
53
+
25
54
  end
26
55
  end
27
56
  end
@@ -46,6 +46,7 @@ module Librarian
46
46
  def manifest?(name, path)
47
47
  return true if path.join('manifests').exist?
48
48
  return true if path.join('lib').join('puppet').exist?
49
+ return true if path.join('lib').join('facter').exist?
49
50
  false
50
51
  end
51
52
  end
@@ -0,0 +1,5 @@
1
+ module Librarian
2
+ module Puppet
3
+ VERSION = "0.9.2.pre"
4
+ end
5
+ end
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.24
4
+
5
+ * \#15. A remembered configuration system.
6
+
7
+ * \#16. Configure, and remember configuration for, chef install paths.
8
+
9
+ * \#38. Configure, and remember configuration for, stripping out `.git`
10
+ directories from git-sources chef dependencies.
11
+
12
+ * \#76. Support git annotated tags.
13
+
14
+ * \#80. Ignore directories in the `PATH` named `git` when looking for the `git`
15
+ bin.
16
+
17
+ * \#85. Provide a helpful message when running the `show` command without a
18
+ lockfile present.
19
+
3
20
  ## 0.0.23
4
21
 
5
22
  * \#41. Build gems with a built gemspec.
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in librarian.gemspec
4
4
  gemspec
5
+
6
+ gem "fakefs", :require => "fakefs/safe"
@@ -12,33 +12,49 @@ A bundler written with Librarian will expect you to provide a specfile listing
12
12
  your project's declared dependencies, including any version constraints and
13
13
  including the upstream sources for finding them. Librarian can resolve the spec,
14
14
  write a lockfile listing the full resolution, fetch the resolved dependencies,
15
- install them, and isolate them in your project. This is what Bundler does for
16
- projects that depend on Ruby gems.
15
+ install them, and isolate them in your project.
16
+
17
+ A bundler written with Librarian will be similar in kind to [Bundler](http://gembundler.com),
18
+ the bundler for Ruby gems that many modern Rails applications use.
17
19
 
18
20
  Librarian-Chef
19
21
  ---------------
20
22
 
23
+ Librarian-Chef is a tool that helps you manage the cookbooks that your chef-repo
24
+ depends on. Here are some more details.
25
+
21
26
  Librarian-Chef is a bundler for infrastructure repositories using Chef. You can
22
- use Librarian-Chef to resolve your infrastructure's cookbook dependencies,
23
- fetch them and install them into your infrastructure.
27
+ use Librarian-Chef to resolve your infrastructure's cookbook dependencies, fetch
28
+ them, and install them into your infrastructure repository.
29
+
30
+ Librarian-Chef can resolve and fetch third-party, publicly-released cookbooks,
31
+ and install them into your infrastructure repository. It can also source
32
+ cookbooks directly from their own source control repositories.
33
+
34
+ Librarian-Chef can also deal with cookbooks you may actively be working on
35
+ outside your infrastructure repository. For example, it can deal with cookbooks
36
+ directly from their own private source control repositories, whether they are
37
+ remote or local to your machine, and it can deal with cookbooks released to and
38
+ hosted on a private cookbooks server.
24
39
 
25
- Librarian-Chef is for resolving and fetching third-party, publicly-released
26
- cookbooks, and installing them into your infrastructure repository. It is not
27
- for dealing with the cookbooks you're actively working on within your
28
- infrastructure repository.
40
+ Librarian-Chef is not primarily intended for dealing with the cookbooks you are
41
+ actively working on *within* your infrastructure repository. In such a case, you
42
+ can still use Librarian-Chef, but it is likely unnecessary.
29
43
 
30
44
  Librarian-Chef *takes over* your `cookbooks/` directory and manages it for you
31
45
  based on your `Cheffile`. Your `Cheffile` becomes the authoritative source for
32
46
  the cookbooks your infrastructure repository depends on. You should not modify
33
47
  the contents of your `cookbooks/` directory when using Librarian-Chef. If you
34
- have custom cookbooks which are specific to your infrastructure repository,
35
- they should go in your `site-cookbooks/` directory.
48
+ have cookbooks which are, rather than being separate projects, inherently part
49
+ of your infrastructure repository, then they should go in a separate directory,
50
+ like your `site-cookbooks/` directory, and you do not need to use Librarian-Chef
51
+ to manage them.
36
52
 
37
53
  ### The Cheffile
38
54
 
39
55
  Every infrastruture repository that uses Librarian-Chef will have a file named
40
56
  `Cheffile` in the root directory of that repository. The full specification for
41
- which third-party, publicly-rleased cookbooks your infrastructure repository
57
+ which third-party, publicly-released cookbooks your infrastructure repository
42
58
  depends will go here.
43
59
 
44
60
  Here's an example `Cheffile`:
@@ -103,7 +119,7 @@ most recent version of the cookbook from that same branch.
103
119
 
104
120
  The Git source also supports a `:path =>` option. If we use the path option,
105
121
  Librarian-Chef will navigate down into the Git repository and only use the
106
- specified subdirectory. Many people have the havit of having a single repository
122
+ specified subdirectory. Many people have the habit of having a single repository
107
123
  with many cookbooks in it. If we need a cookbook from such a repository, we can
108
124
  use the `:path =>` option here to help Librarian-Chef drill down and find the
109
125
  cookbook subdirectory.
@@ -130,8 +146,8 @@ Prepare your infrastructure repository:
130
146
 
131
147
  $ cd ~/path/to/chef-repo
132
148
  $ git rm -r cookbooks
133
- $ echo cookbooks >> .gitignore
134
- $ echo tmp >> .gitignore
149
+ $ echo /cookbooks >> .gitignore
150
+ $ echo /tmp >> .gitignore
135
151
 
136
152
  Librarian-Chef takes over your `cookbooks/` directory, and will always reinstall
137
153
  the cookbooks listed the `Cheffile.lock` into your `cookbooks/` directory. Hence
@@ -240,6 +256,75 @@ Upload the cookbooks to your chef-server:
240
256
 
241
257
  $ knife cookbook upload --all
242
258
 
259
+ ### Configuration
260
+
261
+ Configuration comes from three sources with the following highest-to-lowest
262
+ precedence:
263
+
264
+ * The local config (`./.librarian/chef/config`)
265
+ * The environment
266
+ * The global config (`~/.librarian/chef/config`)
267
+
268
+ You can inspect the final configuration with:
269
+
270
+ $ librarian-chef config
271
+
272
+ You can find out where a particular key is set with:
273
+
274
+ $ librarian-chef config KEY
275
+
276
+ You can set a key at the global level with:
277
+
278
+ $ librarian-chef config KEY VALUE --global
279
+
280
+ And remove it with:
281
+
282
+ $ librarian-chef config KEY --global --delete
283
+
284
+ You can set a key at the local level with:
285
+
286
+ $ librarian-chef config KEY VALUE --local
287
+
288
+ And remove it with:
289
+
290
+ $ librarian-chef config KEY --local --delete
291
+
292
+ You cannot set or delete environment-level config keys with the CLI.
293
+
294
+ Configuration set at either the global or local level will affect subsequent
295
+ invocations of `librarian-chef`. Configurations set at the environment level are
296
+ not saved and will not affect subsequent invocations of `librarian-chef`.
297
+
298
+ You can pass a config at the environment level by taking the original config key
299
+ and transforming it: replace hyphens (`-`) with underscores (`_`) and periods
300
+ (`.`) with doubled underscores (`__`), uppercase, and finally prefix with
301
+ `LIBRARIAN_CHEF_`. For example, to pass a config in the environment for the key
302
+ `part-one.part-two`, set the environment variable
303
+ `LIBRARIAN_CHEF_PART_ONE__PART_TWO`.
304
+
305
+ Configuration affects how various commands operate.
306
+
307
+ * The `path` config sets the cookbooks directory to install to. If a relative
308
+ path, it is relative to the directory containing the `Cheffile`. The
309
+ equivalent environment variable is `LIBRARIAN_CHEF_PATH`.
310
+
311
+ * The `install.strip-dot-git` config causes the `.git/` directory to be stripped
312
+ out when installing cookbooks from a git source. This must be set to exactly
313
+ "1" to cause this behavior. The equivalent environment variable is
314
+ `LIBRARIAN_CHEF_INSTALL__STRIP_DOT_GIT`.
315
+
316
+ Configuration can be set by passing specific options to other commands.
317
+
318
+ * The `path` config can be set at the local level by passing the `--path` option
319
+ to the `install` command. It can be unset at the local level by passing the
320
+ `--no-path` option to the `install` command. Note that if this is set at the
321
+ environment or global level then, even if `--no-path` is given as an option,
322
+ the environment or global config will be used.
323
+
324
+ * The `install.strip-dot-git` config can be set at the local level by passing
325
+ the `--strip-dot-git` option to the `install` command. It can be unset at the
326
+ local level by passing the `--no-strip-dot-git` option.
327
+
243
328
  ### Knife Integration
244
329
 
245
330
  You can integrate your `knife.rb` with Librarian-Chef.
@@ -4,6 +4,7 @@ Feature: cli/init
4
4
 
5
5
  Scenario: Initing a directory
6
6
  When I run `librarian-chef init`
7
+ Then the exit status should be 0
7
8
  Then a file named "Cheffile" should exist
8
9
 
9
10
 
@@ -21,7 +21,19 @@ Feature: cli/show
21
21
  path 'cookbook-sources'
22
22
  cookbook 'main'
23
23
  """
24
- Given I run `librarian-chef install`
24
+ Given I run `librarian-chef install --quiet`
25
+
26
+
27
+
28
+ Scenario: Showing al without a lockfile
29
+ Given I remove the file "Cheffile.lock"
30
+ When I run `librarian-chef show`
31
+ Then the exit status should be 1
32
+ Then the output should contain exactly:
33
+ """
34
+ Be sure to install first!
35
+
36
+ """
25
37
 
26
38
 
27
39
 
@@ -1,11 +1,7 @@
1
- require "librarian/helpers/debug"
2
-
3
1
  module Librarian
4
2
  module Action
5
3
  class Base
6
4
 
7
- include Helpers::Debug
8
-
9
5
  attr_accessor :environment
10
6
  private :environment=
11
7
 
@@ -17,6 +13,12 @@ module Librarian
17
13
  self.options = options
18
14
  end
19
15
 
16
+ private
17
+
18
+ def debug(*args, &block)
19
+ environment.logger.debug(*args, &block)
20
+ end
21
+
20
22
  end
21
23
  end
22
24
  end