producer-core 0.5.11 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -103
- data/lib/producer/core/action.rb +7 -1
- data/lib/producer/core/actions/file_writer.rb +3 -4
- data/lib/producer/core/actions/mkdir.rb +2 -3
- data/lib/producer/core/cli.rb +1 -5
- data/lib/producer/core/condition.rb +16 -14
- data/lib/producer/core/error_formatter.rb +2 -3
- data/lib/producer/core/errors.rb +1 -0
- data/lib/producer/core/remote/fs.rb +1 -1
- data/lib/producer/core/remote.rb +9 -4
- data/lib/producer/core/template/erb_renderer.rb +26 -0
- data/lib/producer/core/template/yaml_renderer.rb +13 -0
- data/lib/producer/core/template.rb +16 -28
- data/lib/producer/core/test.rb +4 -0
- data/lib/producer/core/testing/cucumber.rb +2 -1
- data/lib/producer/core/version.rb +1 -1
- data/lib/producer/core.rb +2 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a59bbda268d60668c1b0bff8dc1f37eefc3a834d
|
4
|
+
data.tar.gz: 830f6e8ba0a452024d905679e3536f359476767b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37113fab68f768445a648eb0c299aec71b07ec3f1be756195ce96dc711a62cb70759f29cbd9ae86f4fc7e1f4deccd4df5594e7ca585310656c7e279d1bd159fc
|
7
|
+
data.tar.gz: 30ffac8b310c4a41ed49c97611f8eacab87401a59e02d7a54d72dc51beb5eaaaedb1abbede07c79f4a6822674e29579e09e79924b52cd709261754302368b3df
|
data/README.md
CHANGED
@@ -227,109 +227,6 @@ design and usage of Domain Specific Languages in Ruby, and refactor
|
|
227
227
|
all my scripts as "recipes" in a common language.
|
228
228
|
|
229
229
|
|
230
|
-
Sample recipe
|
231
|
-
-------------
|
232
|
-
|
233
|
-
Based on the previous template example (FreeBSD jails.conf
|
234
|
-
template):
|
235
|
-
|
236
|
-
```ruby
|
237
|
-
require 'producer/stdlib'
|
238
|
-
|
239
|
-
JAILS_ROOT = '/var/jails'.freeze
|
240
|
-
ZROOT = 'tank/jails'.freeze
|
241
|
-
INTERFACE = 're0'.freeze
|
242
|
-
SETS = {
|
243
|
-
base: '2b028a894d25711ad496762622a52d74b1e32ee04693ad1cf056e3ddcdc23975',
|
244
|
-
src: 'f919287a5ef51d4f133f27c99c54f2e8054f408d3dd53bc60f4e233cc75ec03d'
|
245
|
-
}.freeze
|
246
|
-
JAILS = [
|
247
|
-
{
|
248
|
-
name: 'freebsd-10r1',
|
249
|
-
src: true,
|
250
|
-
addr4: '10.0.0.1'
|
251
|
-
},
|
252
|
-
{
|
253
|
-
name: 'freebsd-10r1-gcc',
|
254
|
-
src: true,
|
255
|
-
addr4: '10.0.0.2'
|
256
|
-
}
|
257
|
-
].freeze
|
258
|
-
|
259
|
-
task :freebsd_archives_fetch do
|
260
|
-
SETS.keys.each { |set| condition { no_file? "/tmp/#{set}.txz"} }
|
261
|
-
|
262
|
-
SETS.each do |set, sum|
|
263
|
-
sh <<-eoh
|
264
|
-
cd /tmp && \
|
265
|
-
fetch ftp://ftp.freebsd.org:/pub/FreeBSD/releases/amd64/10.1-RELEASE/#{set}.txz && \
|
266
|
-
sha256 -c #{sum} #{set}.txz
|
267
|
-
eoh
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
task :jails_fs_create do
|
272
|
-
condition { no_sh "zfs list #{ZROOT}" }
|
273
|
-
sh "zfs create -o mountpoint=#{JAILS_ROOT} -o compress=lz4 #{ZROOT}"
|
274
|
-
end
|
275
|
-
|
276
|
-
JAILS.each do |jail|
|
277
|
-
root = "#{JAILS_ROOT}/#{jail[:name]}"
|
278
|
-
fs = "#{ZROOT}/#{jail[:name]}"
|
279
|
-
|
280
|
-
task :jail_initialize do
|
281
|
-
condition { no_sh "zfs list #{fs}@install" }
|
282
|
-
|
283
|
-
task :jail_fs_create do
|
284
|
-
condition { no_sh "zfs list #{fs}" }
|
285
|
-
|
286
|
-
sh "zfs create #{fs}"
|
287
|
-
|
288
|
-
SETS.keys.each do |set|
|
289
|
-
next if set == 'src' && !jail[:src]
|
290
|
-
sh "tar -JxC #{root}/ -f /tmp/#{set}.txz"
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
task :rc_conf do
|
295
|
-
file_write_once "#{root}/etc/rc.conf", <<-eoh
|
296
|
-
hostname=#{jail[:name]}
|
297
|
-
# ...
|
298
|
-
eoh
|
299
|
-
end
|
300
|
-
|
301
|
-
task :root_passwd do
|
302
|
-
sh "chroot #{root} pw user mod root -w random"
|
303
|
-
end
|
304
|
-
|
305
|
-
task :mail_aliases do
|
306
|
-
condition { no_file? "#{root}/etc/mail/aliases.db" }
|
307
|
-
|
308
|
-
sh "chroot #{root} make -C /etc/mail aliases"
|
309
|
-
end
|
310
|
-
|
311
|
-
freebsd_update_patch_interactive "#{root}/usr/sbin/freebsd-update"
|
312
|
-
|
313
|
-
task :jail_snapshot_install do
|
314
|
-
sh "zfs snapshot #{fs}@install"
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
task :jail_update do
|
319
|
-
condition { no_sh "zfs list #{fs}@update" }
|
320
|
-
|
321
|
-
sh "chroot #{root} freebsd-update fetch install"
|
322
|
-
sh "zfs snapshot #{fs}@update"
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
task :jails_conf do
|
327
|
-
conf = template 'freebsd/jail.conf', if: INTERFACE, jails: JAILS
|
328
|
-
file_write_once '/etc/jail.conf', conf
|
329
|
-
end
|
330
|
-
```
|
331
|
-
|
332
|
-
|
333
230
|
Similar or related code and tools
|
334
231
|
---------------------------------
|
335
232
|
|
data/lib/producer/core/action.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Producer
|
2
2
|
module Core
|
3
3
|
class Action
|
4
|
-
INSPECT_ARGUMENTS_SUM_LEN = 68
|
4
|
+
INSPECT_ARGUMENTS_SUM_LEN = 68
|
5
5
|
|
6
6
|
extend Forwardable
|
7
7
|
def_delegators :@env, :input, :output, :error_output, :remote
|
@@ -34,6 +34,12 @@ module Producer
|
|
34
34
|
return if arguments.compact.size == size
|
35
35
|
fail ArgumentError, '`%s\' action requires %d arguments' % [name, size]
|
36
36
|
end
|
37
|
+
|
38
|
+
def convert_options conversions
|
39
|
+
conversions.each do |original, convertion|
|
40
|
+
options[convertion] = options.delete original if options.key? original
|
41
|
+
end
|
42
|
+
end
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
@@ -4,9 +4,8 @@ module Producer
|
|
4
4
|
class FileWriter < Action
|
5
5
|
def setup
|
6
6
|
check_arguments_size! arguments_size
|
7
|
-
@path, @content
|
8
|
-
|
9
|
-
@options[:owner] = @options.delete :user if options.key? :user
|
7
|
+
@path, @content = arguments
|
8
|
+
convert_options mode: :permissions, user: :owner
|
10
9
|
end
|
11
10
|
|
12
11
|
def name
|
@@ -15,7 +14,7 @@ module Producer
|
|
15
14
|
|
16
15
|
def apply
|
17
16
|
fs.file_write @path, @content
|
18
|
-
fs.setstat @path,
|
17
|
+
fs.setstat @path, options unless options.empty?
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
@@ -5,8 +5,7 @@ module Producer
|
|
5
5
|
def setup
|
6
6
|
check_arguments_size! 1
|
7
7
|
@path = Pathname.new(arguments.first)
|
8
|
-
|
9
|
-
@options[:owner] = @options.delete :user if @options.key? :user
|
8
|
+
convert_options mode: :permissions, user: :owner
|
10
9
|
end
|
11
10
|
|
12
11
|
def name
|
@@ -17,7 +16,7 @@ module Producer
|
|
17
16
|
@path.descend do |path|
|
18
17
|
next if fs.dir? path
|
19
18
|
fs.mkdir path.to_s
|
20
|
-
fs.setstat path.to_s,
|
19
|
+
fs.setstat path.to_s, options unless options.empty?
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
data/lib/producer/core/cli.rb
CHANGED
@@ -25,11 +25,7 @@ module Producer
|
|
25
25
|
stderr.puts e.message
|
26
26
|
exit EX_USAGE
|
27
27
|
rescue StandardError => e
|
28
|
-
|
29
|
-
debug: cli.env.debug?,
|
30
|
-
force_cause: [RecipeEvaluationError]
|
31
|
-
)
|
32
|
-
stderr.puts ef.format e
|
28
|
+
stderr.puts ErrorFormatter.new(debug: cli.env.debug?).format e
|
33
29
|
exit EX_SOFTWARE
|
34
30
|
end
|
35
31
|
end
|
@@ -3,20 +3,8 @@ module Producer
|
|
3
3
|
class Condition
|
4
4
|
class << self
|
5
5
|
def define_test keyword, test
|
6
|
-
|
7
|
-
|
8
|
-
"no_#{keyword}" => true
|
9
|
-
}.each do |kw, negated|
|
10
|
-
define_method(kw) do |*args|
|
11
|
-
if test.respond_to? :call
|
12
|
-
args = [test, *args]
|
13
|
-
klass = Tests::ConditionTest
|
14
|
-
else
|
15
|
-
klass = test
|
16
|
-
end
|
17
|
-
@tests << klass.new(@env, *args, negated: negated)
|
18
|
-
end
|
19
|
-
end
|
6
|
+
declare_test_method keyword, test
|
7
|
+
declare_test_method "no_#{keyword}", test, negated: true
|
20
8
|
end
|
21
9
|
|
22
10
|
def evaluate env, *args, &block
|
@@ -26,6 +14,20 @@ module Producer
|
|
26
14
|
o.instance_eval { @return_value = return_value }
|
27
15
|
end
|
28
16
|
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def declare_test_method keyword, test, negated: false
|
21
|
+
define_method keyword do |*args|
|
22
|
+
if test.respond_to? :call
|
23
|
+
args.unshift test
|
24
|
+
klass = Tests::ConditionTest
|
25
|
+
else
|
26
|
+
klass = test
|
27
|
+
end
|
28
|
+
@tests << klass.new(@env, *args, negated: negated)
|
29
|
+
end
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
extend Forwardable
|
data/lib/producer/core/errors.rb
CHANGED
data/lib/producer/core/remote.rb
CHANGED
@@ -10,10 +10,7 @@ module Producer
|
|
10
10
|
|
11
11
|
def session
|
12
12
|
@session ||= begin
|
13
|
-
|
14
|
-
fail RemoteInvalidError,
|
15
|
-
"remote target is invalid: `#{@hostname.inspect}'"
|
16
|
-
end
|
13
|
+
check_hostname!
|
17
14
|
Net::SSH.start(@hostname, user_name)
|
18
15
|
end
|
19
16
|
end
|
@@ -57,6 +54,14 @@ module Producer
|
|
57
54
|
def cleanup
|
58
55
|
session.close if @session
|
59
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def check_hostname!
|
61
|
+
return if @hostname
|
62
|
+
fail RemoteInvalidError,
|
63
|
+
"remote target is invalid: `#{@hostname.inspect}'"
|
64
|
+
end
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Producer
|
2
|
+
module Core
|
3
|
+
class Template
|
4
|
+
class ERBRenderer
|
5
|
+
class << self
|
6
|
+
def render file_path, variables = {}
|
7
|
+
tpl = ERB.new(File.read(file_path), nil, '-')
|
8
|
+
tpl.filename = file_path.to_s
|
9
|
+
tpl.result build_erb_binding variables
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def build_erb_binding variables
|
15
|
+
Object.new.instance_eval do |o|
|
16
|
+
variables.each do |k, v|
|
17
|
+
o.instance_variable_set "@#{k}", v
|
18
|
+
end
|
19
|
+
binding
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -2,50 +2,38 @@ module Producer
|
|
2
2
|
module Core
|
3
3
|
class Template
|
4
4
|
SEARCH_PATH = 'templates'.freeze
|
5
|
+
RENDERERS = {
|
6
|
+
ERBRenderer => %i[erb],
|
7
|
+
YAMLRenderer => %i[yaml]
|
8
|
+
}.freeze
|
5
9
|
|
6
|
-
def initialize path, search_path: SEARCH_PATH
|
10
|
+
def initialize path, search_path: SEARCH_PATH, renderers: RENDERERS
|
7
11
|
@path = Pathname.new(path)
|
8
12
|
@search_path = Pathname.new(search_path)
|
13
|
+
@renderers = renderers
|
9
14
|
end
|
10
15
|
|
11
16
|
def render variables = {}
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
candidates.each do |c|
|
18
|
+
r, * = @renderers.find { |_, v| v.include? c.extname[1..-1].to_sym }
|
19
|
+
return r.render c, variables if r
|
15
20
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
21
|
|
20
|
-
|
21
|
-
tpl = ERB.new(File.read(file_path), nil, '-')
|
22
|
-
tpl.filename = file_path.to_s
|
23
|
-
tpl.result build_erb_binding variables
|
22
|
+
fail TemplateMissingError, "template `#{@path}' not found"
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
YAML.load(File.read(file_path))
|
28
|
-
end
|
25
|
+
protected
|
29
26
|
|
30
|
-
def
|
27
|
+
def candidates
|
31
28
|
if @path.to_s =~ /\A\.\//
|
32
|
-
|
29
|
+
glob_candidates_by_prefix @path
|
33
30
|
else
|
34
|
-
|
31
|
+
glob_candidates_by_prefix @search_path + @path
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
Pathname.glob(
|
40
|
-
end
|
41
|
-
|
42
|
-
def build_erb_binding variables
|
43
|
-
Object.new.instance_eval do |o|
|
44
|
-
variables.each do |k, v|
|
45
|
-
o.instance_variable_set "@#{k}", v
|
46
|
-
end
|
47
|
-
binding
|
48
|
-
end
|
35
|
+
def glob_candidates_by_prefix path_prefix
|
36
|
+
Pathname.glob(path_prefix.to_s + ?*)
|
49
37
|
end
|
50
38
|
end
|
51
39
|
end
|
data/lib/producer/core/test.rb
CHANGED
@@ -29,6 +29,7 @@ end
|
|
29
29
|
# Enable cucumber-sshd "fast" mode (persists sshd across scenarios), and
|
30
30
|
# register hooks for @sshd tagged scenarios.
|
31
31
|
Before do
|
32
|
-
@_sshd_fast
|
32
|
+
@_sshd_fast = true
|
33
|
+
@_sshd_wait_ready = true if ENV.key? 'TRAVIS'
|
33
34
|
end
|
34
35
|
require 'cucumber/sshd/cucumber'
|
data/lib/producer/core.rb
CHANGED
@@ -45,6 +45,8 @@ require 'producer/core/remote'
|
|
45
45
|
require 'producer/core/remote/environment'
|
46
46
|
require 'producer/core/remote/fs'
|
47
47
|
require 'producer/core/task'
|
48
|
+
require 'producer/core/template/erb_renderer'
|
49
|
+
require 'producer/core/template/yaml_renderer'
|
48
50
|
require 'producer/core/template'
|
49
51
|
require 'producer/core/version'
|
50
52
|
require 'producer/core/worker'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: producer-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thibault Jouan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -45,6 +45,9 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.8'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0.9'
|
48
51
|
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,6 +55,9 @@ dependencies:
|
|
52
55
|
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '0.8'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0.9'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: cucumber
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,6 +155,8 @@ files:
|
|
149
155
|
- lib/producer/core/remote/fs.rb
|
150
156
|
- lib/producer/core/task.rb
|
151
157
|
- lib/producer/core/template.rb
|
158
|
+
- lib/producer/core/template/erb_renderer.rb
|
159
|
+
- lib/producer/core/template/yaml_renderer.rb
|
152
160
|
- lib/producer/core/test.rb
|
153
161
|
- lib/producer/core/testing.rb
|
154
162
|
- lib/producer/core/testing/aruba_program_wrapper.rb
|
@@ -192,8 +200,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
200
|
version: '0'
|
193
201
|
requirements: []
|
194
202
|
rubyforge_project:
|
195
|
-
rubygems_version: 2.4.5
|
203
|
+
rubygems_version: 2.4.5.1
|
196
204
|
signing_key:
|
197
205
|
specification_version: 4
|
198
206
|
summary: Provisioning tool
|
199
207
|
test_files: []
|
208
|
+
has_rdoc:
|