iron_worker_ng 0.6.8 → 0.7.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.8
1
+ 0.7.0
@@ -58,7 +58,19 @@ module IronWorkerNG
58
58
 
59
59
  def codes_create(code, options = {})
60
60
  zip_file = code.create_zip
61
- res = @api.codes_create(code.name, zip_file, 'sh', '__runner__.sh', options)
61
+
62
+ if code.remote_build_command.nil?
63
+ res = @api.codes_create(code.name, zip_file, 'sh', '__runner__.sh', options)
64
+ else
65
+ builder_code_name = code.name + 'Builder'
66
+
67
+ @api.codes_create(builder_code_name, zip_file, 'sh', '__runner__.sh', options)
68
+ builder_task_id = tasks.create(builder_code_name, :iron_token => token, :iron_project_id => project_id, :code_name => code.name, :codes_create_options => options.to_json).id
69
+ tasks.wait_for(builder_task_id)
70
+
71
+ res = {} # TODO: fetch real res from build worker
72
+ end
73
+
62
74
  File.unlink(zip_file)
63
75
 
64
76
  OpenStruct.new(res)
@@ -10,6 +10,7 @@ module IronWorkerNG
10
10
  class Base
11
11
  attr_reader :features
12
12
  attr_accessor :base_dir
13
+ attr_accessor :dest_dir
13
14
 
14
15
  @@registered_types = []
15
16
 
@@ -28,6 +29,8 @@ module IronWorkerNG
28
29
  end
29
30
 
30
31
  def self.register_feature(feature)
32
+ return if feature[:for_klass].to_s == 'IronWorkerNG::Code::Builder'
33
+
31
34
  @@registered_features << feature
32
35
  end
33
36
 
@@ -43,12 +46,13 @@ module IronWorkerNG
43
46
  def initialize(*args, &block)
44
47
  @features = []
45
48
  @base_dir = ''
49
+ @dest_dir = ''
46
50
 
47
51
  initialize_code(*args, &block)
48
52
  end
49
53
 
50
- def name(code_name = nil)
51
- @name = code_name if code_name
54
+ def name(name = nil)
55
+ @name = name if name
52
56
 
53
57
  if @name.nil? and @exec
54
58
  @name = IronWorkerNG::Code::Base.guess_name_for_path(@exec.path)
@@ -62,6 +66,16 @@ module IronWorkerNG
62
66
  @name = name
63
67
  end
64
68
 
69
+ def remote_build_command(remote_build_command = nil)
70
+ @remote_build_command = remote_build_command if remote_build_command
71
+
72
+ @remote_build_command
73
+ end
74
+
75
+ def remote_build_command=(remote_build_command)
76
+ @remote_build_command = remote_build_command
77
+ end
78
+
65
79
  def runtime(*args)
66
80
  end
67
81
 
@@ -70,7 +84,7 @@ module IronWorkerNG
70
84
 
71
85
  def fixate
72
86
  IronWorkerNG::Code::Base.registered_features.each do |rf|
73
- if rf[:for_klass] == self.class && respond_to?(rf[:name] + '_fixate')
87
+ if (rf[:for_klass] == self.class || self.class == IronWorkerNG::Code::Builder) && respond_to?(rf[:name] + '_fixate')
74
88
  send(rf[:name] + '_fixate')
75
89
  end
76
90
  end
@@ -86,24 +100,9 @@ module IronWorkerNG
86
100
  @features.each do |feature|
87
101
  feature.bundle(zip)
88
102
  end
89
- end
90
103
 
91
- def create_zip
92
- unless @exec
93
- IronCore::Logger.error 'IronWorkerNG', 'No exec specified'
94
- raise IronCore::IronError.new('No exec specified')
95
- end
96
-
97
- fixate
98
-
99
- zip_name = Dir.tmpdir + '/' + Dir::Tmpname.make_tmpname("iron-worker-ng-", "code.zip")
100
-
101
- IronCore::Logger.debug 'IronWorkerNG', "Creating code zip '#{zip_name}'"
102
-
103
- Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zip|
104
- bundle(zip)
105
-
106
- zip.get_output_stream('__runner__.sh') do |runner|
104
+ unless self.class == IronWorkerNG::Code::Base
105
+ zip.get_output_stream(@dest_dir + '__runner__.sh') do |runner|
107
106
  runner.write <<RUNNER
108
107
  #!/bin/sh
109
108
  # iron_worker_ng-#{IronWorkerNG.full_version}
@@ -125,6 +124,42 @@ cd "$(root "$@")"
125
124
  RUNNER
126
125
  end
127
126
  end
127
+ end
128
+
129
+ def create_zip
130
+ unless self.class == IronWorkerNG::Code::Base
131
+ unless @exec
132
+ IronCore::Logger.error 'IronWorkerNG', 'No exec specified'
133
+ raise IronCore::IronError.new('No exec specified')
134
+ end
135
+ end
136
+
137
+ fixate
138
+
139
+ zip_name = Dir.tmpdir + '/' + Dir::Tmpname.make_tmpname("iron-worker-ng-", "code.zip")
140
+
141
+ IronCore::Logger.debug 'IronWorkerNG', "Creating code zip '#{zip_name}'"
142
+
143
+ if @remote_build_command
144
+ @dest_dir = '__build__/'
145
+ end
146
+
147
+ Zip::ZipFile.open(zip_name, Zip::ZipFile::CREATE) do |zip|
148
+ bundle(zip)
149
+
150
+ if @remote_build_command
151
+ IronCore::Logger.info 'IronWorkerNG', 'Creating builder'
152
+
153
+ builder = IronWorkerNG::Code::Builder.new
154
+ builder.remote_build_command = @remote_build_command
155
+
156
+ builder.gem('iron_worker_ng')
157
+ builder.fixate
158
+
159
+ builder.bundle(zip)
160
+ end
161
+
162
+ end
128
163
 
129
164
  zip_name
130
165
  end
@@ -0,0 +1,41 @@
1
+ require_relative '../feature/ruby/merge_gem'
2
+
3
+ module IronWorkerNG
4
+ module Code
5
+ class Builder < IronWorkerNG::Code::Ruby
6
+ def bundle(zip)
7
+ @exec = IronWorkerNG::Feature::Ruby::MergeExec::Feature.new(self, '__builder__.rb', nil)
8
+
9
+ super(zip)
10
+
11
+ zip.get_output_stream(@dest_dir + '__builder__.sh') do |builder|
12
+ builder.write <<BUILDER_SH
13
+ # iron_worker_ng-#{IronWorkerNG.full_version}
14
+ #{remote_build_command}
15
+ BUILDER_SH
16
+ end
17
+
18
+ zip.get_output_stream(@dest_dir + '__builder__.rb') do |builder|
19
+ builder.write <<BUILDER_RUBY
20
+ # iron_worker_ng-#{IronWorkerNG.full_version}
21
+
22
+ require 'iron_worker_ng'
23
+ require 'json'
24
+
25
+ puts `cd __build__ && sh ../__builder__.sh && cd ..`
26
+
27
+ Dir.chdir('__build__')
28
+
29
+ code = IronWorkerNG::Code::Base.new
30
+ code.name params[:code_name]
31
+ code.dir '.'
32
+
33
+ client = IronWorkerNG::Client.new(:token => params[:iron_token], :project_id => params[:iron_project_id])
34
+
35
+ client.codes.create(code, JSON.parse(params[:codes_create_options]))
36
+ BUILDER_RUBY
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -4,6 +4,7 @@ require_relative 'ruby'
4
4
  require_relative 'java'
5
5
  require_relative 'node'
6
6
  require_relative 'binary'
7
+ require_relative 'builder'
7
8
 
8
9
  module IronWorkerNG
9
10
  module Code
@@ -20,8 +21,8 @@ module IronWorkerNG
20
21
  initialize_code(*args, &block)
21
22
  end
22
23
 
23
- def name(code_name = nil)
24
- @name = code_name if code_name
24
+ def name(name = nil)
25
+ @name = name if name
25
26
 
26
27
  @name
27
28
  end
@@ -30,6 +31,12 @@ module IronWorkerNG
30
31
  @name = name
31
32
  end
32
33
 
34
+ def remote_build_command(remote_build_command = nil)
35
+ end
36
+
37
+ def remote_build_command=(remote_build_command)
38
+ end
39
+
33
40
  def runtime(*args)
34
41
  @runtime = args[0] if args.length == 1
35
42
 
@@ -12,7 +12,7 @@ module IronWorkerNG
12
12
  def bundle(zip)
13
13
  super(zip)
14
14
 
15
- zip.get_output_stream('__runner__.rb') do |runner|
15
+ zip.get_output_stream(@dest_dir + '__runner__.rb') do |runner|
16
16
  runner.write <<RUBY_RUNNER
17
17
  # iron_worker_ng-#{IronWorkerNG.full_version}
18
18
 
@@ -19,10 +19,10 @@ module IronWorkerNG
19
19
 
20
20
  if File.directory?(src)
21
21
  Dir.glob(src + '/**/**') do |path|
22
- zip.add(dest + path[src.length .. -1], path)
22
+ zip.add(@code.dest_dir + dest + path[src.length .. -1], path)
23
23
  end
24
24
  else
25
- zip.add(dest, src)
25
+ zip.add(@code.dest_dir + dest, src)
26
26
  end
27
27
  end
28
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_worker_ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -112,6 +112,7 @@ files:
112
112
  - lib/iron_worker_ng/client.rb
113
113
  - lib/iron_worker_ng/code/base.rb
114
114
  - lib/iron_worker_ng/code/binary.rb
115
+ - lib/iron_worker_ng/code/builder.rb
115
116
  - lib/iron_worker_ng/code/creator.rb
116
117
  - lib/iron_worker_ng/code/initializer.rb
117
118
  - lib/iron_worker_ng/code/java.rb
@@ -144,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  version: '0'
145
146
  segments:
146
147
  - 0
147
- hash: 808244481
148
+ hash: -348555501
148
149
  required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  none: false
150
151
  requirements: