Added mock build. Part 4
This commit is contained in:
29
app.rb
29
app.rb
@@ -751,12 +751,39 @@ get "/gitbld/:id/:git_id" do
|
|||||||
@proj_descr = prj_info[:descr]
|
@proj_descr = prj_info[:descr]
|
||||||
@git_name = git_info[:reponame]
|
@git_name = git_info[:reponame]
|
||||||
|
|
||||||
prj.build_projects_git(prj_info[:id], git_info[:id], cfg.get_counter_path)
|
@build_id = prj.build_projects_git(prj_info[:id], git_info[:id], cfg.get_counter_path)
|
||||||
|
|
||||||
|
if @build_id == 0
|
||||||
|
print_error_page(503, "Ошибка создания или получения информации о сборке, возможно проблемы с файлом блокировки")
|
||||||
|
else
|
||||||
erb :prjbld
|
erb :prjbld
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/buildinfo/:build_id" do
|
||||||
|
content_type "text/plain"
|
||||||
|
build_id = params["build_id"].to_i
|
||||||
|
if build_id > 0
|
||||||
|
info = db.get_build_task_process_log(build_id)
|
||||||
|
unless info.nil?
|
||||||
|
if File.exist?(info[:errlogpath])
|
||||||
|
output = ""
|
||||||
|
File.readlines(info[:errlogpath]).last(100).each do |line|
|
||||||
|
output << line
|
||||||
|
end
|
||||||
|
output
|
||||||
|
else
|
||||||
|
"Файла для чтения сборки уже не существует #{info[:errlogpath]}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
"Такого build id #{params["build_id"]} нет в базе"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
"Ошибка чтения build id #{params["build_id"]}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
not_found do
|
not_found do
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ end
|
|||||||
class ProjectsProjects < Sequel::Model(:projects_projects)
|
class ProjectsProjects < Sequel::Model(:projects_projects)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class BuildTask < Sequel::Model(:buildtask)
|
||||||
|
end
|
||||||
|
|
||||||
class DBase
|
class DBase
|
||||||
attr :error, :last_id
|
attr :error, :last_id
|
||||||
|
|
||||||
@@ -216,4 +219,23 @@ class DBase
|
|||||||
end
|
end
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#result = 0 (in progress), 1 (stopped - error), 2 (stopped - success)
|
||||||
|
def create_build_task(prj_id, git_id, proj_path)
|
||||||
|
id = BuildTask.insert(repo_id: git_id.to_i, proj_id: prj_id.to_i, signpath: "", logpath: "", errlogpath: "", result: 0)
|
||||||
|
@last_id = id
|
||||||
|
BuildTask.where(id: id).update(logpath: File.join(proj_path, "#{id}"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_build_task_status(build_id, status)
|
||||||
|
BuildTask.where(id: build_id.to_i).update(result: status.to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_build_task_error_log(build_id, path)
|
||||||
|
BuildTask.where(id: build_id.to_i).update(errlogpath: path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_build_task_process_log(build_id)
|
||||||
|
BuildTask.where(id: build_id.to_i).first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
require_relative "spork"
|
require_relative "spork"
|
||||||
require_relative "runner"
|
require_relative "runner"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
#
|
#
|
||||||
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg --buildsrpm --spec srcprp/bayrepo_neuro_farm.spec --sources srcprp/ --resultdir result/ --isolation=simple --disable-plugin=ccache
|
#mock -r /home/alexey/workspace/ruby-projects/mock-gui/projects/prjt1.prj/configs/prjt1.cfg --buildsrpm --spec srcprp/bayrepo_neuro_farm.spec --sources srcprp/ --resultdir result/ --isolation=simple --disable-plugin=ccache
|
||||||
#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
|
#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
|
class MockManager
|
||||||
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db
|
attr :path, :config, :error, :last_status, :last_pid, :prep_dir, :db, :resultpath, :process_log, :repo_path
|
||||||
|
|
||||||
def initialize(path, config, cfg_counter_path, db)
|
def initialize(path, config, cfg_counter_path, db, result_path, repo_path)
|
||||||
@error = nil
|
@error = nil
|
||||||
unless File.exist? (path)
|
unless File.exist? (path)
|
||||||
Dir.mkdir(path)
|
Dir.mkdir(path)
|
||||||
@@ -17,6 +18,8 @@ class MockManager
|
|||||||
@config = config
|
@config = config
|
||||||
cntr = 0
|
cntr = 0
|
||||||
@db = db
|
@db = db
|
||||||
|
@resultpath = result_path
|
||||||
|
@repo_path = repo_path
|
||||||
|
|
||||||
File.open(cfg_counter_path, "r+") do |f|
|
File.open(cfg_counter_path, "r+") do |f|
|
||||||
f.flock(File::LOCK_EX)
|
f.flock(File::LOCK_EX)
|
||||||
@@ -28,6 +31,20 @@ class MockManager
|
|||||||
end
|
end
|
||||||
tmp_name = (0...10).map { ("a".."z").to_a[rand(26)] }.join
|
tmp_name = (0...10).map { ("a".."z").to_a[rand(26)] }.join
|
||||||
@prep_dir = File.join(path, "#{cntr}_#{tmp_name}")
|
@prep_dir = File.join(path, "#{cntr}_#{tmp_name}")
|
||||||
pp @prep_dir
|
@process_log = File.join(@prep_dir, "process.log")
|
||||||
|
Dir.mkdir(@prep_dir)
|
||||||
|
FileUtils.touch(@process_log)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_build_process_log()
|
||||||
|
@process_log
|
||||||
|
end
|
||||||
|
|
||||||
|
def finalize_build_task()
|
||||||
|
FileUtils.rm_rf(@path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_task()
|
||||||
|
finalize_build_task
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ class ProjectsActions
|
|||||||
end
|
end
|
||||||
|
|
||||||
def build_projects_git(prj_id, git_id, counter_file)
|
def build_projects_git(prj_id, git_id, counter_file)
|
||||||
|
bld_id = 0
|
||||||
build_ok = true
|
build_ok = true
|
||||||
proj_path = get_project_path(prj_id)
|
proj_path = get_project_path(prj_id)
|
||||||
git_name = @db.get_repo_info_by_id(git_id)
|
git_name = @db.get_repo_info_by_id(git_id)
|
||||||
@@ -256,6 +257,13 @@ class ProjectsActions
|
|||||||
unless result
|
unless result
|
||||||
#Файл заблокирован считать id и вывести сведения о сборке
|
#Файл заблокирован считать id и вывести сведения о сборке
|
||||||
build_ok = false
|
build_ok = false
|
||||||
|
build_id = f.gets.strip.to_i
|
||||||
|
if build_id > 0
|
||||||
|
build_info = @db.get_build_task_process_log(build_id)
|
||||||
|
unless build_info.nil?
|
||||||
|
bld_id = build_info[:id]
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
#Сборка завершилась, но каталог не подчистился
|
#Сборка завершилась, но каталог не подчистился
|
||||||
FileUtils.rm_rf(prepare_path)
|
FileUtils.rm_rf(prepare_path)
|
||||||
@@ -272,9 +280,16 @@ class ProjectsActions
|
|||||||
File.open(lockf_path, File::RDWR | File::CREAT) do |f|
|
File.open(lockf_path, File::RDWR | File::CREAT) do |f|
|
||||||
f.flock(File::LOCK_EX)
|
f.flock(File::LOCK_EX)
|
||||||
#Начинаем сборку
|
#Начинаем сборку
|
||||||
mock = MockManager.new(prepare_path, get_project_config(prj_id), counter_file, @db)
|
build_path = File.join(proj_path, PROJECTS_STRUCTURE[:LOGS], git_name[:reponame])
|
||||||
FileUtils.rm_rf(prepare_path)
|
repo_path = File.join(proj_path, PROJECTS_STRUCTURE[:REPO])
|
||||||
|
@db.create_build_task(prj_id, git_id, build_path)
|
||||||
|
build_id = @db.last_id
|
||||||
|
mock = MockManager.new(prepare_path, get_project_config(prj_id), counter_file, @db, build_path, repo_path)
|
||||||
|
bld_id = build_id
|
||||||
|
@db.update_build_task_error_log(build_id, mock.get_build_process_log)
|
||||||
|
mock.build_task
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
bld_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
12
|
12
|
||||||
|
13
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ratio ratio-4x3">
|
<div class="ratio ratio-4x3">
|
||||||
<iframe src="/" title="Процесс сборки" id="bldframe" allowfullscreen></iframe>
|
<iframe src="/buildinfo/<%= ERB::Util.url_encode(@build_id) %>" title="Процесс сборки" id="bldframe" allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user