[DRE-commits] [librarian-puppet] 38/153: If no Puppetfile is present default to use the metadata.json or Modulefile
Stig Sandbeck Mathisen
ssm at debian.org
Wed Jun 1 20:30:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
ssm pushed a commit to branch master
in repository librarian-puppet.
commit b179e82a9bfaa9aaa7307cea9d902b23c9db3396
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date: Sun Mar 30 10:59:59 2014 +0200
If no Puppetfile is present default to use the metadata.json or Modulefile
---
README.md | 15 ++++++----
features/install.feature | 4 +--
features/install/forge.feature | 29 +++++++++++++++++++
features/update.feature | 53 ++++++++++++++++++++++++++++++++++
lib/librarian/puppet/action.rb | 1 +
lib/librarian/puppet/action/install.rb | 24 +++++++++++++++
lib/librarian/puppet/cli.rb | 14 +++++----
lib/librarian/puppet/dsl.rb | 34 ++++++++++++++++++++--
lib/librarian/puppet/extension.rb | 16 ----------
9 files changed, 158 insertions(+), 32 deletions(-)
diff --git a/README.md b/README.md
index c46733d..3d2819d 100644
--- a/README.md
+++ b/README.md
@@ -37,17 +37,20 @@ See the [Changelog](Changelog.md) for more details.
## The Puppetfile
-Every Puppet repository that uses Librarian-puppet will have a file named
-`Puppetfile` in the root directory of that repository. The full specification
-for which modules your puppet infrastructure repository depends goes in here.
+Every Puppet repository that uses Librarian-puppet may have a file named
+`Puppetfile`, `metadata.json` or `Modulefile` in the root directory of that repository.
+The full specification
+for which modules your puppet infrastructure repository depends goes in here.
-### Simple Puppetfile
+### Simple usage
-This Puppetfile will download all the dependencies listed in your Modulefile from the Puppet Forge
+If no Puppetfile is present, `librarian-puppet` will download all the dependencies
+listed in your `metadata.json` or `Modulefile` from the Puppet Forge,
+as if the Puppetfile contained
forge "https://forgeapi.puppetlabs.com"
- modulefile
+ metadata
### Example Puppetfile
diff --git a/features/install.feature b/features/install.feature
index 3fbbf84..21997ea 100644
--- a/features/install.feature
+++ b/features/install.feature
@@ -2,10 +2,10 @@ Feature: cli/install
In order to be worth anything
Puppet librarian needs to install modules properly
- Scenario: Running install with no Puppetfile
+ Scenario: Running install with no Puppetfile nor metadata.json
Given there is no Puppetfile
When I run `librarian-puppet install`
- Then the output should contain "Could not find Puppetfile"
+ Then the output should match /^Metadata file does not exist: .*metadata.json$/
And the exit status should be 1
Scenario: Install a module dependency from git and forge should be deterministic
diff --git a/features/install/forge.feature b/features/install/forge.feature
index 8cc2098..1f953d8 100644
--- a/features/install/forge.feature
+++ b/features/install/forge.feature
@@ -13,6 +13,35 @@ Feature: cli/install/forge
And the file "modules/ntp/metadata.json" should match /"name": "puppetlabs-ntp"/
And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
+ Scenario: Running install with no Puppetfile and metadata.json
+ Given there is no Puppetfile
+ And a file named "metadata.json" with:
+ """
+ {
+ "name": "random name",
+ "dependencies": [
+ {
+ "name": "puppetlabs/stdlib",
+ "version_requirement": "4.1.0"
+ }
+ ]
+ }
+ """
+ When I run `librarian-puppet install`
+ Then the exit status should be 0
+ And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
+
+ Scenario: Running install with no Puppetfile and Modulefile
+ Given there is no Puppetfile
+ And a file named "Modulefile" with:
+ """
+ name "random name"
+ dependency "puppetlabs/stdlib", "4.1.0"
+ """
+ When I run `librarian-puppet install`
+ Then the exit status should be 0
+ And the file "modules/stdlib/metadata.json" should match /"name": "puppetlabs-stdlib"/
+
Scenario: Installing an exact version of a module
Given a file named "Puppetfile" with:
"""
diff --git a/features/update.feature b/features/update.feature
index 74a48a0..5dcbf85 100644
--- a/features/update.feature
+++ b/features/update.feature
@@ -1,6 +1,59 @@
Feature: cli/update
Puppet librarian needs to update modules properly
+ Scenario: Updating a module with no Puppetfile and with metadata.json
+ Given a file named "metadata.json" with:
+ """
+ {
+ "name": "random name",
+ "dependencies": [
+ {
+ "name": "puppetlabs/stdlib",
+ "version_requirement": "3.1.x"
+ }
+ ]
+ }
+ """
+ And a file named "Puppetfile.lock" with:
+ """
+ FORGE
+ remote: http://forge.puppetlabs.com
+ specs:
+ puppetlabs/stdlib (3.1.0)
+
+ DEPENDENCIES
+ puppetlabs/stdlib (~> 3.0)
+ """
+ When I run `librarian-puppet update puppetlabs/stdlib`
+ Then the exit status should be 0
+ And the file "Puppetfile" should not exist
+ And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
+ And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
+ And the file "modules/stdlib/Modulefile" should match /version *'3\.1\.1'/
+
+ Scenario: Updating a module with no Puppetfile and with Modulefile
+ Given a file named "Modulefile" with:
+ """
+ name "random name"
+ dependency "puppetlabs/stdlib", "3.1.x"
+ """
+ And a file named "Puppetfile.lock" with:
+ """
+ FORGE
+ remote: http://forge.puppetlabs.com
+ specs:
+ puppetlabs/stdlib (3.1.0)
+
+ DEPENDENCIES
+ puppetlabs/stdlib (~> 3.0)
+ """
+ When I run `librarian-puppet update puppetlabs/stdlib`
+ Then the exit status should be 0
+ And the file "Puppetfile" should not exist
+ And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
+ And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
+ And the file "modules/stdlib/Modulefile" should match /version *'3\.1\.1'/
+
Scenario: Updating a module
Given a file named "Puppetfile" with:
"""
diff --git a/lib/librarian/puppet/action.rb b/lib/librarian/puppet/action.rb
new file mode 100644
index 0000000..e726e6c
--- /dev/null
+++ b/lib/librarian/puppet/action.rb
@@ -0,0 +1 @@
+require "librarian/puppet/action/install"
diff --git a/lib/librarian/puppet/action/install.rb b/lib/librarian/puppet/action/install.rb
new file mode 100644
index 0000000..1bae2a3
--- /dev/null
+++ b/lib/librarian/puppet/action/install.rb
@@ -0,0 +1,24 @@
+module Librarian
+ module Puppet
+ module Action
+ class Install < Librarian::Action::Install
+
+ private
+
+ def create_install_path
+ install_path.rmtree if install_path.exist? && destructive?
+ install_path.mkpath
+ end
+
+ def destructive?
+ environment.config_db.local['destructive'] == 'true'
+ end
+
+ def check_specfile
+ # don't fail if Puppetfile doesn't exist as we'll use the Modulefile or metadata.json
+ end
+
+ end
+ end
+ end
+end
diff --git a/lib/librarian/puppet/cli.rb b/lib/librarian/puppet/cli.rb
index 3ae2987..913a76b 100644
--- a/lib/librarian/puppet/cli.rb
+++ b/lib/librarian/puppet/cli.rb
@@ -2,6 +2,7 @@ require 'librarian/helpers'
require 'librarian/cli'
require 'librarian/puppet'
+require 'librarian/puppet/action'
module Librarian
module Puppet
@@ -47,11 +48,6 @@ module Librarian
option "use-v1-api", :type => :boolean, :default => true
def install
- unless File.exist?('Puppetfile')
- say "Could not find Puppetfile in #{Dir.pwd}", :red
- exit 1
- end
-
ensure!
clean! if options["clean"]
unless options["destructive"].nil?
@@ -89,6 +85,14 @@ module Librarian
def version
say "librarian-puppet v#{Librarian::Puppet::VERSION}"
end
+
+ private
+
+ # override the actions to use our own
+
+ def install!(options = { })
+ Action::Install.new(environment, options).run
+ end
end
end
end
diff --git a/lib/librarian/puppet/dsl.rb b/lib/librarian/puppet/dsl.rb
index 3f84c10..373c4ab 100644
--- a/lib/librarian/puppet/dsl.rb
+++ b/lib/librarian/puppet/dsl.rb
@@ -17,6 +17,14 @@ module Librarian
def run(specfile = nil, sources = [])
specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
+ if specfile.kind_of?(Pathname) and !File.exists?(specfile)
+ debug { "Specfile not found, using defaults: #{specfile}" }
+ specfile = Proc.new do
+ forge "https://forgeapi.puppetlabs.com"
+ metadata
+ end
+ end
+
Target.new(self).tap do |target|
target.precache_sources(sources)
debug_named_source_cache("Pre-Cached Sources", target)
@@ -30,17 +38,20 @@ module Librarian
end
class Receiver < Librarian::Dsl::Receiver
- attr_reader :specfile
+ attr_reader :specfile, :working_path
# save the specfile and call librarian
def run(specfile = nil)
+ @working_path = specfile.kind_of?(Pathname) ? specfile.parent : Pathname.new(Dir.pwd)
@specfile = specfile
super
end
# implement the 'modulefile' syntax for Puppetfile
def modulefile
- File.read(Pathname.new(specfile).parent.join('Modulefile')).lines.each do |line|
+ f = modulefile_path
+ raise Error, "Modulefile file does not exist: #{f}" unless File.exists?(f)
+ File.read(f).lines.each do |line|
regexp = /\s*dependency\s+('|")([^'"]+)\1\s*(?:,\s*('|")([^'"]+)\3)?/
regexp =~ line && mod($2, $4)
end
@@ -48,11 +59,28 @@ module Librarian
# implement the 'metadata' syntax for Puppetfile
def metadata
- dependencyList = JSON.parse(File.read(Pathname.new(specfile).parent.join('metadata.json')))['dependencies']
+ f = working_path.join('metadata.json')
+ unless File.exists?(f)
+ msg = "Metadata file does not exist: #{f}"
+ # try modulefile, in case we don't have a Puppetfile and we are using the default template
+ if File.exists?(modulefile_path)
+ modulefile
+ return
+ else
+ raise Error, msg
+ end
+ end
+ dependencyList = JSON.parse(File.read(f))['dependencies']
dependencyList.each do |d|
mod(d['name'], d['version_requirement'])
end
end
+
+ private
+
+ def modulefile_path
+ working_path.join('Modulefile')
+ end
end
end
end
diff --git a/lib/librarian/puppet/extension.rb b/lib/librarian/puppet/extension.rb
index bda6d21..af1134b 100644
--- a/lib/librarian/puppet/extension.rb
+++ b/lib/librarian/puppet/extension.rb
@@ -80,22 +80,6 @@ module Librarian
end
end
- module Action
- class Install < Base
-
- private
-
- def create_install_path
- install_path.rmtree if install_path.exist? && destructive?
- install_path.mkpath
- end
-
- def destructive?
- environment.config_db.local['destructive'] == 'true'
- end
- end
- end
-
class ManifestSet
include Librarian::Puppet::Util
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git
More information about the Pkg-ruby-extras-commits
mailing list