Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote build worker #64

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.bundle
.rvmrc
pkg
*iron.json
10 changes: 0 additions & 10 deletions Gemfile

This file was deleted.

28 changes: 0 additions & 28 deletions Gemfile.lock

This file was deleted.

11 changes: 3 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@ task :test do
end

Jeweler::Tasks.new do |gem|
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end

gem.name = "iron_worker_ng"
gem.homepage = "https://github.com/iron-io/iron_worker_ruby_ng"
gem.description = %Q{New generation ruby client for IronWorker}
gem.summary = %Q{New generation ruby client for IronWorker}
gem.email = "info@iron.io"
gem.authors = ["Andrew Kirilenko", "Iron.io, Inc"]
gem.files.exclude('.document', 'Gemfile', 'Gemfile.lock', 'Rakefile', 'iron_worker_ng.gemspec', 'test/**/**', 'examples/**/**')
gem.add_dependency 'iron_core'
#gem.add_dependency 'typhoeus'
gem.required_ruby_version = '>= 1.9'
end

Jeweler::RubygemsDotOrgTasks.new
7 changes: 7 additions & 0 deletions lib/iron_worker_ng/code/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def iron_task_id
@iron_task_id
end

begin
# load bundle if it's here
require_relative 'bundle/bundler/setup'
puts "loaded standalone bundle"
rescue LoadError => ex
end

require '#{File.basename(@exec.path)}'

unless #{@exec.klass == nil}
Expand Down
1 change: 1 addition & 0 deletions test/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source 'http://rubygems.org'
gem 'pry'
gem 'jeweler2'
gem 'iron_worker_ng'
gem 'test-unit'
18 changes: 8 additions & 10 deletions test/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
PATH
remote: ..
specs:
iron_worker_ng (0.5.0)
bundler (> 1.0.0)
iron_core
zip

GEM
remote: http://rubygems.org/
specs:
Expand All @@ -15,11 +7,15 @@ GEM
bundler (> 1.0.0)
rest
rest-client
iron_worker_ng (0.6.0)
bundler (> 1.0.0)
iron_core
zip
jeweler2 (2.0.9)
git (>= 1.2.5)
method_source (0.7.1)
mime-types (1.18)
pry (0.9.9.4)
pry (0.9.9.6)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
Expand All @@ -29,12 +25,14 @@ GEM
rest-client (1.6.7)
mime-types (>= 1.16)
slop (2.4.4)
test-unit (2.5.0)
zip (2.0.2)

PLATFORMS
ruby

DEPENDENCIES
iron_worker_ng!
iron_worker_ng
jeweler2
pry
test-unit
155 changes: 155 additions & 0 deletions test/build_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
require 'iron_worker_ng'

p params

puts "ENV"
p ENV

puts "pwd: " + `pwd`
puts `ls -al`

class WorkerFile

attr_accessor :wruntime,
:wname,
:exec_file,
:files,
:gems,
:build_command

def initialize(raw)
@files = []
@gems = []

puts 'evaling'
eval(raw)
puts 'done evaling '
end

def runtime(s)
@wruntime = s
end

def exec(s)
@exec_file = s
end

def name(s)
@wname = s
end

def file(s)
@files << s
end

def gem(s)
@gems << s
end

def build_command(s=nil)
if s
@build_command = s
end
@build_command
end

end


code = nil

def get_code_by_runtime(runtime)
if runtime == "ruby"
return IronWorkerNG::Code::Ruby.new()
elsif runtime == "binary"
return IronWorkerNG::Code::Binary.new()
else
raise "No runtime found for #{runtime}!"
end
end

if params['worker_file_url']
wfurl = params['worker_file_url']
puts "worker_file_url: #{wfurl}"
if wfurl.include?("github.com")
require 'open-uri'

raw_url = wfurl.sub("blob", "raw")
p raw_url

raw = open(raw_url).read
puts "raw worker file:\n#{raw}"

worker_file = WorkerFile.new(raw)
puts "worker_file: " + worker_file.inspect

endpoint_dir = File.dirname(raw_url)
puts "endpoint_dir: " + endpoint_dir

get_files = worker_file.files
unless worker_file.build_command
# need to build first, exec isn't on server
get_files += [worker_file.exec_file]
end
get_files.each do |f|
open(f, 'w') do |file|
url = "#{endpoint_dir}/#{f}"
puts "Getting #{url}"
file << open(url).read
end
end

code = get_code_by_runtime(worker_file.wruntime)

if worker_file.gems && worker_file.gems.size > 0
open("Gemfile", 'w') do |gemfile|
gemfile << "source 'http://rubygems.org'\n"
worker_file.gems.each do |gem|
gemfile << "gem '#{gem}'\n"
end
end

puts `ls -al`

# now build bundle
puts "building bundle"
puts `bundle install --standalone`
code.merge_dir 'bundle'
end


if worker_file.build_command
puts `#{worker_file.build_command}`
end


code.name = params['name'] || worker_file.wname
code.merge_exec worker_file.exec_file
worker_file.files.each do |f|
code.merge_file f
end

else
raise "I don't know how to get your worker code from this location."
end
end

if params['build_command']
puts "build_commmand: #{params['build_command']}"
puts `#{params['build_command']}`
code = IronWorkerNG::Code::Binary.new()
code.name = params['name']
code.merge_exec params['exec']

end


puts `ls -al`

# just for testing
#puts `./hello`

puts "Uploading code..."
@client = IronWorkerNG::Client.new(params)
p @client.codes_create(code)

5 changes: 3 additions & 2 deletions test/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
gem 'test-unit'
require 'test/unit'
require 'tempfile'

require './lib/iron_worker_ng.rb'
require_relative '../lib/iron_worker_ng'
require_relative 'iron_io_config.rb'

def code_bundle(*args,&block)
Expand Down Expand Up @@ -31,7 +32,7 @@ def inspect_zip(code)
File.unlink zip_file
end

IronCore::Logger.logger.level = ::Logger::DEBUG
#IronCore::Logger.logger.level = ::Logger::DEBUG

class IWNGTest < Test::Unit::TestCase
attr_accessor :client
Expand Down
Loading