Invoking an analyzer from ruby
This commit is contained in:
@@ -6,4 +6,5 @@ require "pipeline"
|
|||||||
Pipeline.load_config(File.expand_path('../../config/pipeline.yml', __FILE__))
|
Pipeline.load_config(File.expand_path('../../config/pipeline.yml', __FILE__))
|
||||||
# Pipeline.build_analyzer(ARGV[0])
|
# Pipeline.build_analyzer(ARGV[0])
|
||||||
# Pipeline.scratch
|
# Pipeline.scratch
|
||||||
|
# Pipeline.release
|
||||||
Pipeline.analyzer
|
Pipeline.analyzer
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ module Pipeline
|
|||||||
def self.release
|
def self.release
|
||||||
FileUtils.rm_rf "/tmp/analyzer-env/"
|
FileUtils.rm_rf "/tmp/analyzer-env/"
|
||||||
env_base = "/tmp/analyzer-env/#{SecureRandom.hex}"
|
env_base = "/tmp/analyzer-env/#{SecureRandom.hex}"
|
||||||
|
env_base = "/tmp/analyzer-env/1e9c733fd7502974c2a3fdd85da9c844"
|
||||||
environment = Runtime::RuntimeEnvironment.new(env_base)
|
environment = Runtime::RuntimeEnvironment.new(env_base)
|
||||||
environment.prepare
|
environment.prepare
|
||||||
img = Pipeline::Util::ImgWrapper.new
|
img = Pipeline::Util::ImgWrapper.new
|
||||||
@@ -44,7 +45,11 @@ module Pipeline
|
|||||||
def self.analyzer
|
def self.analyzer
|
||||||
env_base = "/tmp/analyzer-env/1e9c733fd7502974c2a3fdd85da9c844"
|
env_base = "/tmp/analyzer-env/1e9c733fd7502974c2a3fdd85da9c844"
|
||||||
environment = Runtime::RuntimeEnvironment.new(env_base)
|
environment = Runtime::RuntimeEnvironment.new(env_base)
|
||||||
environment.create_analyzer_workdir("ruby")
|
solution_dir = environment.prepare_analysis("ruby", 42)
|
||||||
|
iteration_folder = "#{solution_dir}/iteration"
|
||||||
|
File.write("#{iteration_folder}/two_fer.rb", 'puts "hello"')
|
||||||
|
environment.run_analysis("ruby", solution_dir, "two_fer")
|
||||||
|
puts File.read("#{iteration_folder}/analysis.json")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -59,5 +59,41 @@ module Pipeline::Runtime
|
|||||||
FileUtils.mkdir_p iterations
|
FileUtils.mkdir_p iterations
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_analysis(track_slug, solution_id)
|
||||||
|
track_dir = "#{env_base}/#{track_slug}"
|
||||||
|
runs_dir = "#{track_dir}/runs"
|
||||||
|
current_dir = "#{track_dir}/current"
|
||||||
|
solution_dir = "#{runs_dir}/iteration_#{Time.now.to_i}-#{solution_id}-#{SecureRandom.hex}"
|
||||||
|
|
||||||
|
iteration_folder = "#{solution_dir}/iteration"
|
||||||
|
tmp_folder = "#{solution_dir}/tmp"
|
||||||
|
|
||||||
|
FileUtils.mkdir_p iteration_folder
|
||||||
|
FileUtils.mkdir_p tmp_folder
|
||||||
|
solution_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
def run_analysis(track_slug, solution_dir, exercise_slug)
|
||||||
|
track_dir = "#{env_base}/#{track_slug}"
|
||||||
|
runs_dir = "#{track_dir}/runs"
|
||||||
|
current_dir = "#{track_dir}/current"
|
||||||
|
img = Pipeline::Util::ImgWrapper.new
|
||||||
|
runc = Pipeline::Util::RuncWrapper.new
|
||||||
|
configurator = Pipeline::Util::RuncConfigurator.new
|
||||||
|
configurator.seed_from_env
|
||||||
|
|
||||||
|
rootfs_source = "#{File.readlink(current_dir)}/rootfs"
|
||||||
|
configurator.rootfs = rootfs_source
|
||||||
|
|
||||||
|
container_driver = Pipeline::Util::ContainerDriver.new(runc, img, configurator, solution_dir)
|
||||||
|
container_driver.run_analyzer_for("two-fer")
|
||||||
|
end
|
||||||
|
|
||||||
|
def analyze_solution(track_slug, solution_id, exercise_slug)
|
||||||
|
iteration_folder = prepare_analysis
|
||||||
|
yield iteration_folder
|
||||||
|
run_analysis(iteration_folder, exercise_slug)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
module Pipeline::Util
|
module Pipeline::Util
|
||||||
class RuncConfigurator
|
class RuncConfigurator
|
||||||
attr_accessor :uid_id, :gid_id, :invocation_args, :interactive
|
attr_accessor :uid_id, :gid_id, :invocation_args, :interactive, :rootfs
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@rootfs = "./rootfs"
|
||||||
|
end
|
||||||
|
|
||||||
def seed_from_env
|
def seed_from_env
|
||||||
@uid_id = `id -u`.chomp
|
@uid_id = `id -u`.chomp
|
||||||
@@ -49,7 +53,7 @@ module Pipeline::Util
|
|||||||
"noNewPrivileges": true
|
"noNewPrivileges": true
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"path": "./rootfs",
|
"path": "#{rootfs}",
|
||||||
"readonly": true
|
"readonly": true
|
||||||
},
|
},
|
||||||
"hostname": "exercism-runner",
|
"hostname": "exercism-runner",
|
||||||
|
|||||||
@@ -72,6 +72,14 @@ module Pipeline::Util
|
|||||||
assert_equal [ "rbind", "rw" ], mount["options"]
|
assert_equal [ "rbind", "rw" ], mount["options"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_build_config_supports_rootfs_override
|
||||||
|
configurator.rootfs = "/absolute/path/to/another/rootfs"
|
||||||
|
config = configurator.build
|
||||||
|
|
||||||
|
assert_equal "/absolute/path/to/another/rootfs", config["root"]["path"]
|
||||||
|
assert_equal true, config["root"]["readonly"]
|
||||||
|
end
|
||||||
|
|
||||||
def test_build_config_has_correct_ids
|
def test_build_config_has_correct_ids
|
||||||
config = configurator.build
|
config = configurator.build
|
||||||
refute config.nil?
|
refute config.nil?
|
||||||
|
|||||||
Reference in New Issue
Block a user