iron_worker_ng 0.10.2 → 0.10.3

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 (37) hide show
  1. data/bin/iron_worker +130 -323
  2. data/lib/iron_worker_ng/cli.rb +275 -0
  3. data/lib/iron_worker_ng/client.rb +32 -20
  4. data/lib/iron_worker_ng/code/base.rb +45 -37
  5. data/lib/iron_worker_ng/code/builder.rb +4 -3
  6. data/lib/iron_worker_ng/code/container/base.rb +31 -0
  7. data/lib/iron_worker_ng/code/container/dir.rb +31 -0
  8. data/lib/iron_worker_ng/code/container/zip.rb +30 -0
  9. data/lib/iron_worker_ng/code/runtime/binary.rb +1 -3
  10. data/lib/iron_worker_ng/code/runtime/go.rb +1 -3
  11. data/lib/iron_worker_ng/code/runtime/java.rb +2 -3
  12. data/lib/iron_worker_ng/code/runtime/mono.rb +1 -3
  13. data/lib/iron_worker_ng/code/runtime/node.rb +1 -3
  14. data/lib/iron_worker_ng/code/runtime/perl.rb +1 -3
  15. data/lib/iron_worker_ng/code/runtime/php.rb +1 -3
  16. data/lib/iron_worker_ng/code/runtime/python.rb +1 -3
  17. data/lib/iron_worker_ng/code/runtime/ruby.rb +11 -9
  18. data/lib/iron_worker_ng/feature/base.rb +14 -20
  19. data/lib/iron_worker_ng/feature/common/merge_dir.rb +14 -5
  20. data/lib/iron_worker_ng/feature/common/merge_exec.rb +79 -0
  21. data/lib/iron_worker_ng/feature/common/merge_file.rb +13 -4
  22. data/lib/iron_worker_ng/feature/java/merge_jar.rb +12 -0
  23. data/lib/iron_worker_ng/feature/ruby/merge_gem.rb +11 -55
  24. data/lib/iron_worker_ng/feature/ruby/merge_gem_dependency.rb +76 -0
  25. data/lib/iron_worker_ng/fetcher.rb +39 -18
  26. data/lib/iron_worker_ng/version.rb +1 -1
  27. metadata +45 -17
  28. data/lib/iron_worker_ng/code/dir_container.rb +0 -33
  29. data/lib/iron_worker_ng/feature/binary/merge_exec.rb +0 -51
  30. data/lib/iron_worker_ng/feature/go/merge_exec.rb +0 -51
  31. data/lib/iron_worker_ng/feature/java/merge_exec.rb +0 -57
  32. data/lib/iron_worker_ng/feature/mono/merge_exec.rb +0 -51
  33. data/lib/iron_worker_ng/feature/node/merge_exec.rb +0 -51
  34. data/lib/iron_worker_ng/feature/perl/merge_exec.rb +0 -51
  35. data/lib/iron_worker_ng/feature/php/merge_exec.rb +0 -51
  36. data/lib/iron_worker_ng/feature/python/merge_exec.rb +0 -51
  37. data/lib/iron_worker_ng/feature/ruby/merge_exec.rb +0 -53
@@ -14,7 +14,7 @@ module IronWorkerNG
14
14
  end
15
15
 
16
16
  def bundle(container)
17
- @exec = IronWorkerNG::Feature::Ruby::MergeExec::Feature.new(self, '__builder__.rb', nil)
17
+ @exec = IronWorkerNG::Feature::Common::MergeExec::Feature.new(self, '__builder__.rb', {})
18
18
 
19
19
  super(container)
20
20
 
@@ -29,12 +29,13 @@ BUILDER_SH
29
29
  builder.write <<BUILDER_RUBY
30
30
  # #{IronWorkerNG.full_version}
31
31
 
32
- require 'iron_worker_ng'
33
32
  require 'json'
34
33
 
34
+ require 'iron_worker_ng'
35
+
35
36
  exit 1 unless system('cd __build__ && sh ../__builder__.sh && cd ..')
36
37
 
37
- Dir.chdir('__build__')
38
+ ::Dir.chdir('__build__')
38
39
 
39
40
  code = IronWorkerNG::Code::Base.new
40
41
  code.inside_builder = true
@@ -0,0 +1,31 @@
1
+ require 'tmpdir'
2
+ require 'pathname'
3
+
4
+ module IronWorkerNG
5
+ module Code
6
+ module Container
7
+ class Base
8
+ attr_reader :name
9
+
10
+ def initialize
11
+ @name = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'container')
12
+ end
13
+
14
+ def clear_dest(dest)
15
+ dest = Pathname.new(dest).cleanpath.to_s unless dest.empty?
16
+
17
+ dest
18
+ end
19
+
20
+ def add(dest, src, commit = false)
21
+ end
22
+
23
+ def get_output_stream(dest, &block)
24
+ end
25
+
26
+ def close
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'fileutils'
2
+
3
+ module IronWorkerNG
4
+ module Code
5
+ module Container
6
+ class Dir < IronWorkerNG::Code::Container::Base
7
+ def full_dest(dest)
8
+ @name + '/' + clear_dest(dest)
9
+ end
10
+
11
+ def add(dest, src, commit = false)
12
+ FileUtils.mkdir_p(File.dirname(full_dest(dest)))
13
+
14
+ if File.directory?(src)
15
+ FileUtils.mkdir(full_dest(dest))
16
+ else
17
+ FileUtils.cp(src, full_dest(dest))
18
+ end
19
+ end
20
+
21
+ def get_output_stream(dest, &block)
22
+ FileUtils.mkdir_p(File.dirname(full_dest(dest)))
23
+
24
+ file = File.open(full_dest(dest), 'wb')
25
+ block.call(file)
26
+ file.close
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ require 'zip/zip'
2
+
3
+ module IronWorkerNG
4
+ module Code
5
+ module Container
6
+ class Zip < IronWorkerNG::Code::Container::Base
7
+ def initialize
8
+ super
9
+
10
+ @name = @name + '.zip'
11
+ @zip = ::Zip::ZipFile.open(@name, ::Zip::ZipFile::CREATE)
12
+ end
13
+
14
+ def add(dest, src, commit = false)
15
+ @zip.add(clear_dest(dest), src)
16
+
17
+ @zip.commit if commit
18
+ end
19
+
20
+ def get_output_stream(dest, &block)
21
+ @zip.get_output_stream(clear_dest(dest), &block)
22
+ end
23
+
24
+ def close
25
+ @zip.close
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/binary/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Binary
7
- include IronWorkerNG::Feature::Binary::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/go/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Go
7
- include IronWorkerNG::Feature::Go::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,12 +1,11 @@
1
1
  require_relative '../../feature/java/merge_jar'
2
- require_relative '../../feature/java/merge_exec'
3
2
 
4
3
  module IronWorkerNG
5
4
  module Code
6
5
  module Runtime
7
6
  module Java
7
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
8
  include IronWorkerNG::Feature::Java::MergeJar::InstanceMethods
9
- include IronWorkerNG::Feature::Java::MergeExec::InstanceMethods
10
9
 
11
10
  def runtime_run_code(local = false)
12
11
  classpath_array = []
@@ -22,7 +21,7 @@ module IronWorkerNG
22
21
  IronCore::Logger.info 'IronWorkerNG', "Collected '#{classpath}' classpath"
23
22
 
24
23
  <<RUN_CODE
25
- java -cp #{classpath} #{@exec.klass.nil? ? "-jar #{File.basename(@exec.path)}" : @exec.klass} "$@"
24
+ java -cp #{classpath} #{@exec.arg(:class, 0).nil? ? "-jar #{File.basename(@exec.path)}" : @exec.arg(:class, 0)} "$@"
26
25
  RUN_CODE
27
26
  end
28
27
  end
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/mono/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Mono
7
- include IronWorkerNG::Feature::Mono::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/node/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Node
7
- include IronWorkerNG::Feature::Node::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/perl/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Perl
7
- include IronWorkerNG::Feature::Perl::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/php/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module PHP
7
- include IronWorkerNG::Feature::PHP::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_bundle(container)
10
8
  container.get_output_stream(@dest_dir + '__runner__.php') do |runner|
@@ -1,10 +1,8 @@
1
- require_relative '../../feature/python/merge_exec'
2
-
3
1
  module IronWorkerNG
4
2
  module Code
5
3
  module Runtime
6
4
  module Python
7
- include IronWorkerNG::Feature::Python::MergeExec::InstanceMethods
5
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
8
6
 
9
7
  def runtime_run_code(local = false)
10
8
  <<RUN_CODE
@@ -1,17 +1,17 @@
1
1
  require 'tmpdir'
2
2
  require 'fileutils'
3
3
 
4
- require_relative '../../feature/ruby/merge_gem'
4
+ require_relative '../../feature/ruby/merge_gem_dependency'
5
5
  require_relative '../../feature/ruby/merge_gemfile'
6
- require_relative '../../feature/ruby/merge_exec'
6
+ require_relative '../../feature/ruby/merge_gem'
7
7
 
8
8
  module IronWorkerNG
9
9
  module Code
10
10
  module Runtime
11
11
  module Ruby
12
- include IronWorkerNG::Feature::Ruby::MergeGem::InstanceMethods
12
+ include IronWorkerNG::Feature::Common::MergeExec::InstanceMethods
13
+ include IronWorkerNG::Feature::Ruby::MergeGemDependency::InstanceMethods
13
14
  include IronWorkerNG::Feature::Ruby::MergeGemfile::InstanceMethods
14
- include IronWorkerNG::Feature::Ruby::MergeExec::InstanceMethods
15
15
 
16
16
  def runtime_bundle(container)
17
17
  container.get_output_stream(@dest_dir + '__runner__.rb') do |runner|
@@ -70,8 +70,8 @@ end
70
70
 
71
71
  require '#{File.basename(@exec.path)}'
72
72
 
73
- unless #{@exec.klass == nil}
74
- exec_class = Kernel.const_get('#{@exec.klass}')
73
+ unless #{@exec.arg(:class, 0) == nil}
74
+ exec_class = Kernel.const_get('#{@exec.arg(:class, 0)}')
75
75
  exec_inst = exec_class.new
76
76
 
77
77
  params.keys.each do |param|
@@ -95,7 +95,7 @@ RUN_CODE
95
95
  end
96
96
 
97
97
  def install
98
- gemfile_dir = Dir.tmpdir + '/' + Dir::Tmpname.make_tmpname('iron-worker-ng-', 'gemfile')
98
+ gemfile_dir = ::Dir.tmpdir + '/' + ::Dir::Tmpname.make_tmpname('iron-worker-ng-', 'gemfile')
99
99
 
100
100
  FileUtils.mkdir(gemfile_dir)
101
101
 
@@ -103,8 +103,10 @@ RUN_CODE
103
103
 
104
104
  gemfile.puts('source :rubygems')
105
105
 
106
- @merge_gem_reqs.each do |req|
107
- gemfile.puts("gem '#{req.name}', '#{req.requirement.to_s}'")
106
+ deps = @features.reject { |f| f.class != IronWorkerNG::Feature::Ruby::MergeGemDependency::Feature }
107
+
108
+ deps.each do |dep|
109
+ gemfile.puts("gem '#{dep.name}', '#{dep.version}'")
108
110
  end
109
111
 
110
112
  gemfile.close
@@ -1,5 +1,3 @@
1
- require 'fileutils'
2
-
3
1
  module IronWorkerNG
4
2
  module Feature
5
3
  class Base
@@ -12,26 +10,18 @@ module IronWorkerNG
12
10
  end
13
11
 
14
12
  def container_add(container, dest, src)
15
- new_src, clean = IronWorkerNG::Fetcher.fetch(src, true)
16
-
17
- new_src = File.expand_path(new_src) unless new_src.nil?
18
-
19
- if new_src.nil? || (not File.exists?(new_src))
20
- IronCore::Logger.error 'IronWorkerNG', "Can't find src with path='#{src}'", IronCore::Error
21
- end
22
-
23
- src = new_src
24
-
25
- if File.directory?(src)
26
- Dir.glob(src + '/**/**') do |path|
27
- container.add(@code.dest_dir + dest + path[src.length .. -1], path)
13
+ IronWorkerNG::Fetcher.fetch_to_file(src) do |local_src|
14
+ if local_src.nil? || (not File.exists?(local_src))
15
+ IronCore::Logger.error 'IronWorkerNG', "Can't find src with path='#{src}'", IronCore::Error
28
16
  end
29
- else
30
- container.add(@code.dest_dir + dest, src)
31
- end
32
17
 
33
- unless clean.nil?
34
- FileUtils.rm_f(clean)
18
+ if File.directory?(local_src)
19
+ ::Dir.glob(local_src + '/**/**') do |path|
20
+ container.add(@code.dest_dir + dest + path[local_src.length .. -1], path)
21
+ end
22
+ else
23
+ container.add(@code.dest_dir + dest, local_src, IronWorkerNG::Fetcher.remote?(src))
24
+ end
35
25
  end
36
26
  end
37
27
 
@@ -41,6 +31,10 @@ module IronWorkerNG
41
31
 
42
32
  def bundle(container)
43
33
  end
34
+
35
+ def command(remote = false)
36
+ nil
37
+ end
44
38
  end
45
39
  end
46
40
  end
@@ -1,5 +1,3 @@
1
- require 'pathname'
2
-
3
1
  module IronWorkerNG
4
2
  module Feature
5
3
  module Common
@@ -12,14 +10,13 @@ module IronWorkerNG
12
10
  super(code)
13
11
 
14
12
  @path = path
15
- @dest = dest
16
- @dest = Pathname.new(dest).cleanpath.to_s + '/' unless @dest.empty?
13
+ @dest = dest + (dest.empty? || dest.end_with?('/') ? '' : '/')
17
14
  end
18
15
 
19
16
  def hash_string
20
17
  s = @path + @dest + File.mtime(rebase(@path)).to_i.to_s
21
18
 
22
- Dir.glob(rebase(@path) + '/**/**') do |path|
19
+ ::Dir.glob(rebase(@path) + '/**/**') do |path|
23
20
  s += path + File.mtime(path).to_i.to_s
24
21
  end
25
22
 
@@ -31,6 +28,18 @@ module IronWorkerNG
31
28
 
32
29
  container_add(container, @dest + File.basename(@path), rebase(@path))
33
30
  end
31
+
32
+ def command(remote = false)
33
+ if remote
34
+ if IronWorkerNG::Fetcher.remote?(rebase(@path))
35
+ "dir '#{rebase(@path)}', '#{@dest}'"
36
+ else
37
+ "dir '#{@dest}#{File.basename(@path)}', '#{@dest}'"
38
+ end
39
+ else
40
+ "dir '#{@path}', '#{@dest}'"
41
+ end
42
+ end
34
43
  end
35
44
 
36
45
  module InstanceMethods
@@ -0,0 +1,79 @@
1
+ module IronWorkerNG
2
+ module Feature
3
+ module Common
4
+ module MergeExec
5
+ class Feature < IronWorkerNG::Feature::Base
6
+ attr_reader :path
7
+ attr_reader :args
8
+
9
+ def initialize(code, path, args)
10
+ super(code)
11
+
12
+ @path = path
13
+ @args = args
14
+ end
15
+
16
+ def arg(name, i = nil)
17
+ if @args.is_a?(Hash)
18
+ return @args[name.to_sym] || @args[name.to_s]
19
+ elsif @args.is_a?(Array) && (not i.nil?)
20
+ return @args[i]
21
+ end
22
+
23
+ nil
24
+ end
25
+
26
+ def hash_string
27
+ Digest::MD5.hexdigest(@path + File.mtime(rebase(@path)).to_i.to_s + args.to_s)
28
+ end
29
+
30
+ def bundle(container)
31
+ IronCore::Logger.debug 'IronWorkerNG', "Bundling exec with path='#{@path}' and args='#{@args.inspect}'"
32
+
33
+ container_add(container, File.basename(@path), rebase(@path))
34
+ end
35
+
36
+ def command(remote = false)
37
+ if remote
38
+ if IronWorkerNG::Fetcher.remote?(rebase(@path))
39
+ "exec '#{rebase(@path)}', #{@args.inspect}"
40
+ else
41
+ "exec '#{File.basename(@path)}', #{@args.inspect}"
42
+ end
43
+ else
44
+ "exec '#{@path}', #{@args.inspect}"
45
+ end
46
+ end
47
+ end
48
+
49
+ module InstanceMethods
50
+ def merge_exec(path = nil, args = {})
51
+ @exec ||= nil
52
+
53
+ return @exec unless path
54
+
55
+ if (not args.is_a?(Hash)) && (not args.is_a?(Array))
56
+ args = [args]
57
+ end
58
+
59
+ unless @exec.nil?
60
+ IronCore::Logger.warn 'IronWorkerNG', "Ignoring attempt to merge exec with path='#{path}' and args='#{args.inspect}'"
61
+ return
62
+ end
63
+
64
+ @exec = IronWorkerNG::Feature::Common::MergeExec::Feature.new(self, path, args)
65
+
66
+ IronCore::Logger.info 'IronWorkerNG', "Detected exec with path='#{path}' and args='#{args.inspect}'"
67
+
68
+ @features << @exec
69
+ end
70
+
71
+ alias :exec :merge_exec
72
+
73
+ alias :merge_worker :merge_exec
74
+ alias :worker :merge_worker
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end