mock build
This commit is contained in:
161
classes/mock.rb
161
classes/mock.rb
@@ -2,6 +2,7 @@ require_relative "spork"
|
||||
require_relative "runner"
|
||||
require "fileutils"
|
||||
require "logger"
|
||||
require_relative "repomanage"
|
||||
|
||||
BUILD_STRUCTURE = {
|
||||
:SRC => "src",
|
||||
@@ -10,12 +11,10 @@ BUILD_STRUCTURE = {
|
||||
:RESULT_SRPM => "result_srpm",
|
||||
}
|
||||
|
||||
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg result/bayrepo-neuro-farm-0.1-2.src.rpm --resultdir result2/ --isolation simple
|
||||
|
||||
class MockManager
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path, :git_path, :build_id, :log, :recips, :spec, :repo_lock
|
||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path, :git_path, :build_id, :log, :recips, :spec, :repo_lock, :git_id
|
||||
|
||||
def initialize(path, config, cfg_counter_path, db, result_path, repo_path, git_path, build_id, recips, spec_file, repo_lock)
|
||||
def initialize(path, config, cfg_counter_path, db, result_path, repo_path, git_path, build_id, recips, spec_file, repo_lock, git_id)
|
||||
@error = nil
|
||||
unless File.exist? (path)
|
||||
Dir.mkdir(path)
|
||||
@@ -31,6 +30,7 @@ class MockManager
|
||||
@recips = recips
|
||||
@spec = spec_file
|
||||
@repo_lock = repo_lock
|
||||
@git_id = git_id
|
||||
|
||||
File.open(cfg_counter_path, "r+") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
@@ -52,10 +52,6 @@ class MockManager
|
||||
@process_log
|
||||
end
|
||||
|
||||
def finalize_build_task()
|
||||
@log.close
|
||||
end
|
||||
|
||||
def clean_build
|
||||
@log.info("Удаление временной сборочной среды #{@path}")
|
||||
FileUtils.rm_rf(@path)
|
||||
@@ -91,7 +87,7 @@ class MockManager
|
||||
@recips.each_with_index do |item, index|
|
||||
@log.info("Формируем рецепт #{item[:filepath]}")
|
||||
rcp_name = "#{index}rcp_#{item[:filepath]}"
|
||||
File.open(File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name)) do |f|
|
||||
File.open(File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name), "w") do |f|
|
||||
f.write(item[:content])
|
||||
end
|
||||
Dir.chdir(File.join(@prep_dir, BUILD_STRUCTURE[:SRC])) do
|
||||
@@ -100,6 +96,7 @@ class MockManager
|
||||
cmd = Runner.new(cmd_args, @log)
|
||||
cmd.run_clean
|
||||
@error = true if cmd.exit_status != 0
|
||||
@log.error("Ошибка операции") if @error
|
||||
end
|
||||
break if @error
|
||||
end
|
||||
@@ -110,11 +107,11 @@ class MockManager
|
||||
spec_file = File.join(@prep_dir, BUILD_STRUCTURE[:SRC], @spec)
|
||||
if File.exist?(spec_file)
|
||||
Dir.chdir(File.join(@prep_dir, BUILD_STRUCTURE[:SRC])) do
|
||||
script = File.join(@prep_dir, BUILD_STRUCTURE[:SRC], rcp_name)
|
||||
cmd_args = %Q(/usr/bin/mock -r #{@config} --buildsrpm --spec #{spec_file} --sources #{File.join(@prep_dir, BUILD_STRUCTURE[:SRC])} --resultdir #{File.join(@prep_dir, BUILD_STRUCTURE[:RESULT_SRPM])} --isolation=simple --disable-plugin=ccache")
|
||||
cmd = Runner.new(cmd_args, @log)
|
||||
cmd.run_clean
|
||||
@error = true if cmd.exit_status != 0
|
||||
@log.error("Ошибка операции") if @error
|
||||
end
|
||||
else
|
||||
@error = true
|
||||
@@ -123,40 +120,138 @@ class MockManager
|
||||
end
|
||||
|
||||
def build_rpm()
|
||||
@log.info("Начало сборки пакетов")
|
||||
srpm_result_dir = File.join(@prep_dir, BUILD_STRUCTURE[:RESULT_SRPM])
|
||||
srpms = get_src_rpm_files_in_dir(srpm_result_dir)
|
||||
if srpms.nil? || srpms.length == 0
|
||||
@error = true
|
||||
@log.info("Нечего собирать, нет src.rpm пакетов")
|
||||
else
|
||||
srpm = srpms.first
|
||||
path_srpm = File.join(@prep_dir, srpm)
|
||||
cmd_args = %Q(/usr/bin/mock -r #{@config} #{path_srpm} --resultdir #{File.join(@prep_dir, BUILD_STRUCTURE[:RESULT])} --isolation simple)
|
||||
cmd = Runner.new(cmd_args, @log)
|
||||
cmd.run_clean
|
||||
@error = true if cmd.exit_status != 0
|
||||
@log.error("Ошибка операции") if @error
|
||||
end
|
||||
end
|
||||
|
||||
def save_logs()
|
||||
FileUtils.mkdir_p(File.join(@resultpath, "#{@build_id}"))
|
||||
src_result = File.join(@prep_dir, BUILD_STRUCTURE[:RESULT_SRPM])
|
||||
rpm_result = File.join(@prep_dir, BUILD_STRUCTURE[:RESULT])
|
||||
if File.exist?(src_result)
|
||||
logs = get_log_paths(src_result)
|
||||
logs.each do |item|
|
||||
src = File.join(src_result, item)
|
||||
dst_dir = File.dirname(item)
|
||||
dst_fname = File.basename(item)
|
||||
dst = File.join(@resultpath, "#{@build_id}", dst_dir, "srpms_build_#{dst_fname}")
|
||||
FileUtils.cp_r(src, dst, verbose: true, remove_destination: true)
|
||||
end
|
||||
end
|
||||
if File.exist?(rpm_result)
|
||||
logs = get_log_paths(rpm_result)
|
||||
logs.each do |item|
|
||||
src = File.join(rpm_result, item)
|
||||
dst_dir = File.dirname(item)
|
||||
dst_fname = File.basename(item)
|
||||
dst = File.join(@resultpath, "#{@build_id}", dst_dir, "rpm_build_#{dst_fname}")
|
||||
FileUtils.cp_r(src, dst, verbose: true, remove_destination: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_rpms()
|
||||
File.open(@repo_lock, File::RDWR | File::CREAT) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
# выклдака пакетов и пересоздание repodata
|
||||
@log.info("Формирование репозитория")
|
||||
repo = RepoManager.new(@repo_path)
|
||||
rpms = get_rpm_paths(File.join(@prep_dir, BUILD_STRUCTURE[:RESULT]))
|
||||
if rpms.nil? || rpms.length == 0
|
||||
@error = true
|
||||
@log.error("Пакеты не найдены")
|
||||
else
|
||||
prep_rpms = []
|
||||
rpms.each do |item|
|
||||
res = {}
|
||||
rpm_path = File.join(@prep_dir, BUILD_STRUCTURE[:RESULT], item)
|
||||
result = repo.get_rpm_info(rpm_path)
|
||||
if result[:error].nil?
|
||||
res[:src] = rpm_path
|
||||
res[:name] = result[:pkginfo].to_s
|
||||
arch = result[:pkginfo].arch
|
||||
if rpm_path =~ /\.src\.rpm$/
|
||||
res[:dst] = File.join(@repo_path, "SRPMS", File.basename(rpm_path))
|
||||
elsif rpm_path =~ /(debuginfo.+rpm$)|(debugsource.+rpm$)/
|
||||
res[:dst] = File.join(@repo_path, "Debug", File.basename(rpm_path))
|
||||
else
|
||||
if arch.nil? || arch.strip == ""
|
||||
arch = "noarch"
|
||||
end
|
||||
res[:dst] = File.join(@repo_path, arch, File.basename(rpm_path))
|
||||
end
|
||||
prep_rpms << res
|
||||
else
|
||||
@error = true
|
||||
@log.error("Ошибка пакета #{rpm_path}")
|
||||
break
|
||||
end
|
||||
end
|
||||
if @error == false
|
||||
File.open(@repo_lock, File::RDWR | File::CREAT) do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
# выклдака пакетов и пересоздание repodata
|
||||
prep_rpms.each do |item|
|
||||
FileUtils.cp_r(item[:src], item[:dst], verbose: true, remove_destination: true)
|
||||
@db.save_rpm(@build_id, item[:dst], item[:name], @git_id)
|
||||
@log.info("Копируется пакет #{item[:src]} в репозиторий #{item[:dst]}")
|
||||
end
|
||||
repo.create_repo
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_prg_log()
|
||||
FileUtils.mkdir_p(File.join(@resultpath, "#{@build_id}"))
|
||||
if File.exist?(@process_log)
|
||||
dst = File.join(@resultpath, "#{@build_id}")
|
||||
FileUtils.cp_r(@process_log, dst, verbose: true, remove_destination: true)
|
||||
end
|
||||
end
|
||||
|
||||
def build_task()
|
||||
@error = false
|
||||
@db.before_fork
|
||||
spock = Spork.spork(:logger => log) do
|
||||
@db.after_fork
|
||||
$stdout = File.open(@process_log, "w")
|
||||
@log = Logger.new($stdout)
|
||||
if @sepc == ""
|
||||
@error = true
|
||||
@log.error("Не могу найти spec файл")
|
||||
end
|
||||
prepare_structure if @error == false
|
||||
prepare_src if @error == false
|
||||
prepare_source if @error == false
|
||||
prepare_src_rpm if @error == false
|
||||
build_rpm if @error == false
|
||||
save_logs
|
||||
save_rpms if @error == false
|
||||
clean_build
|
||||
@log.close
|
||||
#@db.before_fork
|
||||
#spock = Spork.spork(:logger => log) do
|
||||
# @db.after_fork
|
||||
#$stdout = File.open(@process_log, "w")
|
||||
@log = Logger.new($stdout)
|
||||
if @spec == ""
|
||||
@error = true
|
||||
@log.error("Не могу найти spec файл")
|
||||
end
|
||||
@db.after_fork
|
||||
spock
|
||||
#begin
|
||||
prepare_structure if @error == false
|
||||
prepare_src if @error == false
|
||||
prepare_source if @error == false
|
||||
prepare_src_rpm if @error == false
|
||||
build_rpm if @error == false
|
||||
save_logs
|
||||
save_rpms if @error == false
|
||||
#rescue => e
|
||||
# puts e
|
||||
#end
|
||||
save_prg_log
|
||||
clean_build
|
||||
@log.close
|
||||
if @error
|
||||
@db.update_build_task_status(@build_id, 1)
|
||||
else
|
||||
@db.update_build_task_status(@build_id, 2)
|
||||
end
|
||||
#end
|
||||
#@db.after_fork
|
||||
#spock
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user