baptize 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/baptize/application.rb +22 -11
- data/lib/baptize/dsl.rb +6 -0
- data/lib/baptize/plugins/env.rb +46 -3
- data/lib/baptize/rake.rb +34 -6
- data/lib/baptize/registry.rb +49 -0
- data/lib/baptize/version.rb +1 -1
- data/lib/baptize.rb +2 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21ee15f5fa163ebaa24036c18ed5f7aed06e4ba5
|
4
|
+
data.tar.gz: b6606c765e138843fc0cce48d87a0c76f686db24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc396d66c705cfd836ddbb777e1cb0d577216075e0124635ec120f2ffc24ce622c787eea5047cb928957c02c72a2719bf90a0e56d48c3f4df59349f041825d39
|
7
|
+
data.tar.gz: 54ef22187f9def94e2b44b825de22f4507fa63384b5efb8876d2d729ef63c169e453859348a03999432c5ff01f92d32e13b92630eb355e3fc822c0e7b1593b36
|
data/lib/baptize/application.rb
CHANGED
@@ -12,8 +12,29 @@ module Baptize
|
|
12
12
|
"baptize"
|
13
13
|
end
|
14
14
|
|
15
|
+
def load_rakefile
|
16
|
+
super
|
17
|
+
standard_exception_handling do
|
18
|
+
in_namespace :packages do
|
19
|
+
Baptize::Registry.packages.values.each do |package|
|
20
|
+
@last_description = package.description
|
21
|
+
define_task(Rake::Task, package.name.to_s) do
|
22
|
+
puts "Invoke package: #{package.name}"
|
23
|
+
Baptize::Registry.policies.keys.each do |role|
|
24
|
+
on roles(role), in: :parallel do |host|
|
25
|
+
Baptize::Registry.execution_scope.set :current_host, host
|
26
|
+
Baptize::Registry.execution_scope.set :current_ssh_connection, ssh_connection
|
27
|
+
package.execute
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
15
36
|
def sort_options(options)
|
16
|
-
super.push(version, dry_run, roles
|
37
|
+
super.push(version, dry_run, roles)
|
17
38
|
end
|
18
39
|
|
19
40
|
def handle_options
|
@@ -87,15 +108,5 @@ module Baptize
|
|
87
108
|
]
|
88
109
|
end
|
89
110
|
|
90
|
-
def hostfilter
|
91
|
-
['--hosts HOSTS', '-z',
|
92
|
-
"Run SSH commands only on matching hosts",
|
93
|
-
lambda { |value|
|
94
|
-
raise "TODO: Port this"
|
95
|
-
Configuration.env.add_cmdline_filter(:host, value)
|
96
|
-
}
|
97
|
-
]
|
98
|
-
end
|
99
|
-
|
100
111
|
end
|
101
112
|
end
|
data/lib/baptize/dsl.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Baptize
|
2
2
|
|
3
3
|
module DSL
|
4
|
+
include Baptize::Plugins::Env
|
5
|
+
|
4
6
|
def package(package_name, &config_block)
|
5
7
|
Registry.define_package(package_name, &config_block)
|
6
8
|
end
|
@@ -8,6 +10,10 @@ module Baptize
|
|
8
10
|
def policy(role, *packages)
|
9
11
|
Registry.define_policy role, [packages].flatten
|
10
12
|
end
|
13
|
+
|
14
|
+
def server(role, host, options = {})
|
15
|
+
Registry.define_server(role, host, options)
|
16
|
+
end
|
11
17
|
end # module DSL
|
12
18
|
|
13
19
|
end # module Baptize
|
data/lib/baptize/plugins/env.rb
CHANGED
@@ -1,10 +1,35 @@
|
|
1
|
-
require 'capistrano/dsl/env'
|
2
|
-
|
3
1
|
module Baptize
|
4
2
|
module Plugins
|
5
3
|
module Env
|
6
4
|
|
7
|
-
|
5
|
+
def any?(key)
|
6
|
+
value = fetch(key)
|
7
|
+
if value && value.respond_to?(:any?)
|
8
|
+
value.any?
|
9
|
+
else
|
10
|
+
!fetch(key).nil?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def set(key, value=nil, &block)
|
15
|
+
config[key] = block || value
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_if_empty(key, value=nil, &block)
|
19
|
+
set(key, value, &block) unless config.has_key? key
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(key)
|
23
|
+
config.delete(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch(key, default=nil, &block)
|
27
|
+
value = fetch_for(key, default, &block)
|
28
|
+
while callable_without_parameters?(value)
|
29
|
+
value = set(key, value.call)
|
30
|
+
end
|
31
|
+
return value
|
32
|
+
end
|
8
33
|
|
9
34
|
def respond_to?(sym, include_priv = false)
|
10
35
|
super || any?(sym)
|
@@ -18,6 +43,24 @@ module Baptize
|
|
18
43
|
end
|
19
44
|
end
|
20
45
|
|
46
|
+
private
|
47
|
+
|
48
|
+
def config
|
49
|
+
@@config ||= Hash.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def fetch_for(key, default, &block)
|
53
|
+
if block_given?
|
54
|
+
config.fetch(key, &block)
|
55
|
+
else
|
56
|
+
config.fetch(key, default)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def callable_without_parameters?(x)
|
61
|
+
x.respond_to?(:call) && ( !x.respond_to?(:arity) || x.arity == 0)
|
62
|
+
end
|
63
|
+
|
21
64
|
end
|
22
65
|
|
23
66
|
end # module Plugins
|
data/lib/baptize/rake.rb
CHANGED
@@ -1,18 +1,46 @@
|
|
1
1
|
Rake::Task.define_task(:list) do
|
2
|
-
puts "
|
3
|
-
Baptize::Registry.packages.values
|
4
|
-
|
2
|
+
puts "# Packages"
|
3
|
+
packages = Baptize::Registry.packages.values
|
4
|
+
width = packages.map(&:name).map(&:length).max
|
5
|
+
packages.each do |p|
|
6
|
+
printf("%-#{width}s # %s\n",
|
7
|
+
p.name,
|
8
|
+
p.description)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::Task.define_task(:policies) do
|
13
|
+
puts "# Policies"
|
14
|
+
registry = Baptize::Registry
|
15
|
+
registry.policies.each do |role, packages|
|
16
|
+
puts "#{role}:"
|
17
|
+
packages.each do |package|
|
18
|
+
puts " #{package}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::Task.define_task(:servers) do
|
24
|
+
puts "# Servers"
|
25
|
+
registry = Baptize::Registry
|
26
|
+
registry.servers.values.each do |server|
|
27
|
+
puts server.inspect
|
5
28
|
end
|
6
29
|
end
|
7
30
|
|
8
31
|
Rake::Task.define_task(:apply) do
|
9
|
-
Baptize::Registry
|
10
|
-
|
11
|
-
|
32
|
+
registry = Baptize::Registry
|
33
|
+
registry.policies.keys.each do |role|
|
34
|
+
registry.for_role role, in: :parallel do |host|
|
35
|
+
registry.apply_policy role, host, self
|
12
36
|
end
|
13
37
|
end
|
14
38
|
end
|
15
39
|
|
16
40
|
Rake::Task.define_task(:default) do
|
17
41
|
Rake::Task['list'].invoke
|
42
|
+
puts
|
43
|
+
Rake::Task['policies'].invoke
|
44
|
+
puts
|
45
|
+
Rake::Task['servers'].invoke
|
18
46
|
end
|
data/lib/baptize/registry.rb
CHANGED
@@ -94,6 +94,55 @@ module Baptize
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
+
def self.servers
|
98
|
+
@servers ||= {}
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.define_server(role, host, options = {})
|
102
|
+
role = role.to_sym
|
103
|
+
servers[host] = options.merge(hostname: host)
|
104
|
+
servers[host][:roles] ||= []
|
105
|
+
servers[host][:roles] << role unless servers[host][:roles].include?(role)
|
106
|
+
servers[host]
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.servers_for_role(role)
|
110
|
+
role = role.to_sym
|
111
|
+
host_columns = [:password, :hostname, :port, :user, :key, :ssh_options]
|
112
|
+
servers.values
|
113
|
+
.select do |server|
|
114
|
+
server[:roles].include?(role)
|
115
|
+
end.map do |server|
|
116
|
+
server.select {|k,v| host_columns.include?(k) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.for_role(role, options={}, &block)
|
121
|
+
subset_copy = Marshal.dump(servers_for_role(role))
|
122
|
+
SSHKit::Coordinator.new(Marshal.load(subset_copy)).each(options, &block)
|
123
|
+
end
|
124
|
+
|
97
125
|
end # module Registry
|
98
126
|
|
99
127
|
end # module Baptize
|
128
|
+
|
129
|
+
=begin
|
130
|
+
|
131
|
+
def role(name, hosts, options={})
|
132
|
+
servers.add_role(name, hosts, options)
|
133
|
+
end
|
134
|
+
|
135
|
+
def roles(*names)
|
136
|
+
servers.roles_for(names.flatten)
|
137
|
+
end
|
138
|
+
|
139
|
+
def servers
|
140
|
+
@servers ||= Servers.new
|
141
|
+
end
|
142
|
+
|
143
|
+
def on(hosts, options={}, &block)
|
144
|
+
subset_copy = Marshal.dump(Configuration.env.filter(hosts))
|
145
|
+
SSHKit::Coordinator.new(Marshal.load(subset_copy)).each(options, &block)
|
146
|
+
end
|
147
|
+
|
148
|
+
=end
|
data/lib/baptize/version.rb
CHANGED
data/lib/baptize.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'sshkit'
|
3
|
-
require 'capistrano/application'
|
4
|
-
require 'capistrano/dsl'
|
5
|
-
require 'capistrano/dsl/env'
|
6
3
|
require 'baptize/version'
|
7
4
|
require 'baptize/registry'
|
8
5
|
require 'baptize/package_definition'
|
9
6
|
require 'baptize/execution_scope'
|
10
7
|
require 'baptize/verification_failure'
|
8
|
+
require 'baptize/plugins/env'
|
11
9
|
require 'baptize/plugins/helpers'
|
12
10
|
require 'baptize/plugins/verifications'
|
13
11
|
require 'baptize/plugins/execution'
|
@@ -15,13 +13,12 @@ require 'baptize/plugins/apt'
|
|
15
13
|
require 'baptize/dsl'
|
16
14
|
require 'baptize/application'
|
17
15
|
|
18
|
-
Baptize::Registry.plugins <<
|
16
|
+
Baptize::Registry.plugins << Baptize::Plugins::Env
|
19
17
|
Baptize::Registry.plugins << Baptize::Plugins::Helpers
|
20
18
|
Baptize::Registry.plugins << Baptize::Plugins::Verifications
|
21
19
|
Baptize::Registry.plugins << Baptize::Plugins::Execution
|
22
20
|
Baptize::Registry.plugins << Baptize::Plugins::Apt
|
23
21
|
|
24
|
-
extend Capistrano::DSL
|
25
22
|
extend Baptize::DSL
|
26
23
|
|
27
24
|
set_if_empty :logger, Proc.new { Baptize::Registry.logger }
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baptize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Troels Knak-Nielsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: sshkit
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: jeweler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|