Added mock build. Part 2
This commit is contained in:
@@ -62,4 +62,12 @@ class IniConfig
|
||||
"projects"
|
||||
end
|
||||
end
|
||||
|
||||
def get_counter_path()
|
||||
unless @config["counter"]["path"].nil?
|
||||
@config["counter"]["path"].to_s
|
||||
else
|
||||
"locks/counter"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -204,4 +204,16 @@ class DBase
|
||||
@last_id = id
|
||||
end
|
||||
end
|
||||
|
||||
def get_git_recips(git_id)
|
||||
res = []
|
||||
recip = RepocRecips.where(repo_id: git_id.to_i).all
|
||||
unless recip.nil?
|
||||
res = recip.map do |item|
|
||||
rcp_info = Recips[item[:recip_id]]
|
||||
rcp_info
|
||||
end
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,9 @@ require_relative "spork"
|
||||
require_relative "runner"
|
||||
|
||||
class MockManager
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db
|
||||
|
||||
def initialize(path, config, cfg_counter_path)
|
||||
def initialize(path, config, cfg_counter_path, db)
|
||||
@error = nil
|
||||
unless File.exist? (path)
|
||||
Dir.mkdir(path)
|
||||
@@ -12,6 +12,7 @@ class MockManager
|
||||
@path = path
|
||||
@config = config
|
||||
cntr = 0
|
||||
@db = db
|
||||
|
||||
File.open(cfg_counter_path, "r+") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
@@ -23,5 +24,6 @@ class MockManager
|
||||
end
|
||||
tmp_name = (0...10).map { ("a".."z").to_a[rand(26)] }.join
|
||||
@prep_dir = File.join(path, "#{cntr}_#{tmp_name}")
|
||||
pp @prep_dir
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,6 +131,7 @@ class ProjectsActions
|
||||
config_opts['plugin_conf']['root_cache_enable'] = True
|
||||
config_opts['plugin_conf']['showrc_enable'] = True
|
||||
config_opts['plugin_conf']['yum_cache_enable'] = True
|
||||
config_opts['chroot_setup_cmd'] += " procenv gcc gcc-c++ make"
|
||||
PRJ_CFG
|
||||
File.open(proj_conf_path, "w") { |f| f << proj_config }
|
||||
generate_linked_repos(id, proj_path, proj_name, prj_incl_path)
|
||||
@@ -241,6 +242,38 @@ class ProjectsActions
|
||||
end
|
||||
end
|
||||
|
||||
def build_projects_git(prj_id, git_id)
|
||||
def build_projects_git(prj_id, git_id, counter_file)
|
||||
build_ok = true
|
||||
proj_path = get_project_path(prj_id)
|
||||
git_name = @db.get_repo_info_by_id(git_id)
|
||||
prep_script = @db.get_git_recips(git_id)
|
||||
prepare_path = File.join(proj_path, PROJECTS_STRUCTURE[:SRCPRP], git_name[:reponame])
|
||||
if File.exist?(prepare_path)
|
||||
lockf_path = File.join(prepare_path, "lock")
|
||||
File.open(lockf_path, File::RDWR | File::CREAT) do |f|
|
||||
result = f.flock(File::LOCK_EX | File::LOCK_NB)
|
||||
unless result
|
||||
#Файл заблокирован считать id и вывести сведения о сборке
|
||||
build_ok = false
|
||||
else
|
||||
#Сборка завершилась, но каталог не подчистился
|
||||
FileUtils.rm_rf(prepare_path)
|
||||
f.flock(File::LOCK_UN)
|
||||
build_ok = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#Верная ситуация
|
||||
if build_ok
|
||||
Dir.mkdir(prepare_path)
|
||||
lockf_path = File.join(prepare_path, "lock")
|
||||
File.open(lockf_path, File::RDWR | File::CREAT) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
#Начинаем сборку
|
||||
mock = MockManager.new(prepare_path, get_project_config(prj_id), counter_file, @db)
|
||||
FileUtils.rm_rf(prepare_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user