chef-ladder 1.0.0
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.
- data/bin/ladder +3 -0
- data/lib/chef/ladder.rb +83 -0
- data/lib/chef/ladder/cookbooks.rb +57 -0
- data/lib/chef/ladder/main.rb +41 -0
- metadata +98 -0
data/bin/ladder
ADDED
data/lib/chef/ladder.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'chef/cookbook_loader'
|
4
|
+
require 'chef/cookbook_uploader'
|
5
|
+
require 'escort'
|
6
|
+
|
7
|
+
module Ladder
|
8
|
+
class Sources < Hash
|
9
|
+
def self.from_file(filename)
|
10
|
+
config = Sources.new
|
11
|
+
config.instance_eval(File.read(filename), filename)
|
12
|
+
return config
|
13
|
+
end
|
14
|
+
|
15
|
+
def cookbook(name, options)
|
16
|
+
self[name] = Ladder::Cookbooks::Cookbook.create(name, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Command < Escort::ActionCommand::Base
|
21
|
+
def execute
|
22
|
+
# Load Chef configuration
|
23
|
+
@@chef_config ||= Chef::Config.from_file(global_options[:knife])
|
24
|
+
|
25
|
+
# Load Ladderfile configuration
|
26
|
+
@sources = Ladder::Sources.from_file(global_options[:config])
|
27
|
+
end
|
28
|
+
|
29
|
+
# A list of Ladder::Cookbook objects
|
30
|
+
# If the arguments list is empty, all cookbooks are used
|
31
|
+
def selected_cookbooks
|
32
|
+
names = arguments.empty? ? @sources.keys : arguments
|
33
|
+
names.map { |name| @sources[name] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Fetch < Command
|
38
|
+
def execute
|
39
|
+
super
|
40
|
+
puts "Fetching cookbooks:"
|
41
|
+
ensure_directory(global_options[:directory])
|
42
|
+
for cookbook in selected_cookbooks
|
43
|
+
puts " - #{cookbook.name} from #{cookbook.source}"
|
44
|
+
cookbook.fetch(global_options[:directory])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Creates a directory if it does not exist
|
51
|
+
def ensure_directory(path)
|
52
|
+
Dir.mkdir(path) unless File.exists?(path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Upload < Command
|
57
|
+
def execute
|
58
|
+
super
|
59
|
+
puts "Uploading cookbooks:"
|
60
|
+
for cookbook in selected_cookbooks
|
61
|
+
chef_cookbook = load_cookbook(cookbook)
|
62
|
+
puts " + #{chef_cookbook.metadata.name} version #{chef_cookbook.version}"
|
63
|
+
upload_cookbook(chef_cookbook)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_cookbook(cookbook)
|
68
|
+
@loader ||= Chef::CookbookLoader.new(global_options[:directory])
|
69
|
+
chef_cookbook = @loader.load_cookbook(cookbook.name)
|
70
|
+
if chef_cookbook.nil?
|
71
|
+
raise "Could not load cookbook '#{cookbook.name}'"
|
72
|
+
else
|
73
|
+
return chef_cookbook
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def upload_cookbook(cookbooks)
|
78
|
+
Chef::CookbookUploader.new(cookbooks, global_options[:directory]).upload_cookbooks
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
require 'chef/ladder/cookbooks'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'git'
|
2
|
+
|
3
|
+
module Ladder::Cookbooks
|
4
|
+
class Cookbook
|
5
|
+
def self.create(name, options)
|
6
|
+
if options.has_key? :path
|
7
|
+
return LocalCookbook.new(name, options[:path])
|
8
|
+
elsif options.has_key? :git
|
9
|
+
return GitCookbook.new(name, options[:git])
|
10
|
+
elsif options.has_key? :github
|
11
|
+
return GithubCookbook.new(name, options[:github])
|
12
|
+
else
|
13
|
+
raise "No valid source defined for cookbook '#{name}'"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(name, source)
|
18
|
+
@name = name
|
19
|
+
@source = source
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :name
|
23
|
+
attr_reader :source
|
24
|
+
end
|
25
|
+
|
26
|
+
class GitCookbook < Cookbook
|
27
|
+
def fetch(directory)
|
28
|
+
path = File.join(directory, @name)
|
29
|
+
|
30
|
+
if Dir.exists?(path)
|
31
|
+
Git.open(path).pull()
|
32
|
+
else
|
33
|
+
Git.clone(@source, path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class GithubCookbook < GitCookbook
|
39
|
+
def initialize(name, source)
|
40
|
+
@name = name
|
41
|
+
@source = "git@github.com:#{source}.git"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class LocalCookbook < Cookbook
|
46
|
+
def initialize(name, source)
|
47
|
+
@name = name
|
48
|
+
@source = File.absolute_path(source)
|
49
|
+
end
|
50
|
+
|
51
|
+
def fetch(directory)
|
52
|
+
dest = File.join(directory, @name)
|
53
|
+
FileUtils.remove(dest, :force => true)
|
54
|
+
FileUtils.symlink(@source, dest, :force => true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'chef/ladder'
|
2
|
+
require 'escort'
|
3
|
+
|
4
|
+
Escort::App.create do |app|
|
5
|
+
app.version '1.0.0'
|
6
|
+
app.summary 'Fetch those hard to reach cookbooks'
|
7
|
+
|
8
|
+
app.options do |opts|
|
9
|
+
opts.opt :config, "Ladder configuration file", :short => '-c', :long => '--config', :type => :string, :default => './Ladderfile'
|
10
|
+
opts.opt :directory, "Ladder cookbooks directory", :short => '-d', :long => '--directory', :type => :string, :default => File.join(Dir.home, '.ladder')
|
11
|
+
opts.opt :knife, "Knife configuration file", :short => '-k', :long => '--knife-config', :type => :string, :default => File.join(Dir.home, '.chef', 'knife.rb')
|
12
|
+
end
|
13
|
+
|
14
|
+
app.command :fetch do |command|
|
15
|
+
command.summary "Fetch cookbooks"
|
16
|
+
command.description "Fetch cookbooks"
|
17
|
+
|
18
|
+
command.action do |options, arguments|
|
19
|
+
Ladder::Fetch.new(options, arguments).execute
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
app.command :upload do |command|
|
24
|
+
command.summary "Upload cookbooks"
|
25
|
+
command.description "Upload cookbooks"
|
26
|
+
|
27
|
+
command.action do |options, arguments|
|
28
|
+
Ladder::Upload.new(options, arguments).execute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
app.command :update do |command|
|
33
|
+
command.summary "Fetch and upload cookbooks"
|
34
|
+
command.description "Fetch and upload cookbooks"
|
35
|
+
|
36
|
+
command.action do |options, arguments|
|
37
|
+
Ladder::Fetch.new(options, arguments).execute
|
38
|
+
Ladder::Upload.new(options, arguments).execute
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-ladder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Clements
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: escort
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: chef
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: git
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.6
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.6
|
62
|
+
description: Fetches and uploads external cookbooks from git
|
63
|
+
email: sam@borntyping.co.uk
|
64
|
+
executables:
|
65
|
+
- ladder
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/chef/ladder.rb
|
70
|
+
- lib/chef/ladder/cookbooks.rb
|
71
|
+
- lib/chef/ladder/main.rb
|
72
|
+
- bin/ladder
|
73
|
+
homepage: https://github.com/borntyping/chef-ladder
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.24
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Helps fetch those hard to reach cookbooks
|
98
|
+
test_files: []
|