Added preparing actions for custom build
This commit is contained in:
128
app.rb
128
app.rb
@@ -1916,6 +1916,134 @@ get "/prjuplrpm/:id" do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/prjcstmbld/:id/:git_id" do
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
repo = GitRepo.new(cfg.get_repo, db)
|
||||||
|
if repo.path.nil?
|
||||||
|
print_error_page(503, "Путь к репозиториям не существует")
|
||||||
|
else
|
||||||
|
prj_info = prj.get_project(params["id"])
|
||||||
|
if prj_info.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
git_info = repo.get_repo_short_info_by_id(params["git_id"].to_i)
|
||||||
|
|
||||||
|
@page_name = "#{prj_info[:projname]} задать скрипт сборки git проекта #{git_info[:reponame]}"
|
||||||
|
@proj_name = prj_info[:projname]
|
||||||
|
@proj_descr = prj_info[:descr]
|
||||||
|
@git_name = git_info[:reponame]
|
||||||
|
@proj_id = prj_info[:id]
|
||||||
|
@git_id = git_info[:id]
|
||||||
|
cust_bld = prj.get_project_custom_build(prj_info[:id], git_info[:id])
|
||||||
|
if session[:errora_data].nil?
|
||||||
|
@old_filepath = cust_bld[:script_name]
|
||||||
|
else
|
||||||
|
@old_filepath = session[:old_filepath]
|
||||||
|
end
|
||||||
|
if session[:old_content].nil?
|
||||||
|
@old_content = cust_bld[:content]
|
||||||
|
else
|
||||||
|
@old_content = session[:old_content]
|
||||||
|
end
|
||||||
|
if session[:old_descr].nil?
|
||||||
|
@old_descr = cust_bld[:description]
|
||||||
|
else
|
||||||
|
@old_descr = session[:old_descr]
|
||||||
|
end
|
||||||
|
@error_data = session[:errora_data]
|
||||||
|
session[:errora_data] = nil
|
||||||
|
session[:old_filepath] = nil
|
||||||
|
session[:old_descr] = nil
|
||||||
|
session[:old_content] = nil
|
||||||
|
erb :prjcustombld
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post "/prjcstmbld/:id/:git_id" do
|
||||||
|
unless params["cancel"].nil?
|
||||||
|
session[:old_filepath] = nil
|
||||||
|
session[:old_descr] = nil
|
||||||
|
session[:old_content] = nil
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
else
|
||||||
|
session[:old_filepath] = params["filepath"]
|
||||||
|
session[:old_descr] = params["description"]
|
||||||
|
session[:old_content] = params["codedata"]
|
||||||
|
if params["filepath"].nil? || params["description"].nil? || params["filepath"].strip == "" || params["description"].strip == ""
|
||||||
|
session[:errora_data] = "Имя рецепта и описание не должны быть пустыми"
|
||||||
|
redirect "/prjcstmbld/#{params["id"]}/#{params["git_id"]}"
|
||||||
|
else
|
||||||
|
if params["filepath"] =~ /^[0-9a-zA-Z_\.]+$/
|
||||||
|
# Valid filepath
|
||||||
|
# Proceed with further processing
|
||||||
|
codedata = params["codedata"].gsub(/\r$/, "")
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
repo = GitRepo.new(cfg.get_repo, db)
|
||||||
|
if repo.path.nil?
|
||||||
|
print_error_page(503, "Путь к репозиториям не существует")
|
||||||
|
else
|
||||||
|
prj_info = prj.get_project(params["id"])
|
||||||
|
if prj_info.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
unless params["save"].nil?
|
||||||
|
prj.set_project_custom_build(params["id"], params["git_id"], params["filepath"], params["description"], codedata)
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# Invalid filepath
|
||||||
|
session[:errora_data] = "Недопустимые символы в имени файла"
|
||||||
|
redirect "/prjcstmbld/#{params["id"]}/#{params["git_id"]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
post "/prjcstmblddel/:id/:git_id" do
|
||||||
|
|
||||||
|
prj = ProjectsActions.new(cfg.get_projects_path, db)
|
||||||
|
if prj.path.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
repo = GitRepo.new(cfg.get_repo, db)
|
||||||
|
if repo.path.nil?
|
||||||
|
print_error_page(503, "Путь к репозиториям не существует")
|
||||||
|
else
|
||||||
|
prj_info = prj.get_project(params["id"])
|
||||||
|
if prj_info.nil?
|
||||||
|
print_error_page(503, "Путь к проектам не существует")
|
||||||
|
else
|
||||||
|
git_info = repo.get_repo_short_info_by_id(params["git_id"].to_i)
|
||||||
|
input_name = params["rcpnamedup"]
|
||||||
|
info = prj.get_project_custom_build(prj_info[:id], git_info[:id])
|
||||||
|
if info.nil?
|
||||||
|
print_error_page(404, "Скрипта не существует")
|
||||||
|
else
|
||||||
|
puts input_name
|
||||||
|
puts info
|
||||||
|
if info[:script_name] == input_name
|
||||||
|
prj.del_project_custom_build(params["id"], params["git_id"])
|
||||||
|
end
|
||||||
|
redirect "/prjedit/#{params["id"]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
get "/sanitize" do
|
get "/sanitize" do
|
||||||
#Подчистим гит проекты, которые есть в базе, но нет в файловой системе
|
#Подчистим гит проекты, которые есть в базе, но нет в файловой системе
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ end
|
|||||||
class RpmUploaded < Sequel::Model(:rpm_uploaded)
|
class RpmUploaded < Sequel::Model(:rpm_uploaded)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class CustomBuildScript < Sequel::Model(:custom_build_script)
|
||||||
|
end
|
||||||
|
|
||||||
class DBase
|
class DBase
|
||||||
attr :error, :last_id, :cfg
|
attr :error, :last_id, :cfg
|
||||||
|
|
||||||
@@ -79,6 +82,7 @@ class DBase
|
|||||||
rep_id = Repos.where(reponame: repo_name).first
|
rep_id = Repos.where(reponame: repo_name).first
|
||||||
unless rep_id[:id].nil?
|
unless rep_id[:id].nil?
|
||||||
id = rep_id[:id]
|
id = rep_id[:id]
|
||||||
|
CustomBuildScript.where(repo_id: id).delete
|
||||||
RepocRecips.where(repo_id: id).delete
|
RepocRecips.where(repo_id: id).delete
|
||||||
ReposProjects.where(repo_id: id).delete
|
ReposProjects.where(repo_id: id).delete
|
||||||
Repos.where(reponame: repo_name).delete
|
Repos.where(reponame: repo_name).delete
|
||||||
@@ -369,6 +373,7 @@ class DBase
|
|||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
return 1 if count > 0
|
return 1 if count > 0
|
||||||
|
CustomBuildScript.where(proj_id: proj_id.to_i).delete
|
||||||
RpmUploaded.where(proj_id: prj_id.to_i).delete
|
RpmUploaded.where(proj_id: prj_id.to_i).delete
|
||||||
ReposProjects.where(proj_id: prj_id.to_i).delete
|
ReposProjects.where(proj_id: prj_id.to_i).delete
|
||||||
ProjectsReposSpec.where(proj_id: prj_id.to_i).delete
|
ProjectsReposSpec.where(proj_id: prj_id.to_i).delete
|
||||||
@@ -431,4 +436,22 @@ class DBase
|
|||||||
def get_project_uploaded_rpms(proj_id)
|
def get_project_uploaded_rpms(proj_id)
|
||||||
RpmUploaded.where(proj_id: proj_id.to_i)
|
RpmUploaded.where(proj_id: proj_id.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_project_custom_build(proj_id, git_id)
|
||||||
|
CustomBuildScript.where(proj_id: proj_id.to_i, repo_id: git_id.to_i)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_project_custom_build(id, repo_id, script_name, descr, content)
|
||||||
|
result = get_project_custom_build(id, repo_id).first
|
||||||
|
unless result.nil?
|
||||||
|
CustomBuildScript.where(id: result[:id]).update(:content => content, :filepath => script_name, :descr => descr)
|
||||||
|
else
|
||||||
|
id = CustomBuildScript.insert(:content => content, :filepath => script_name, :descr => descr, :proj_id => id.to_i, :repo_id => repo_id.to_i)
|
||||||
|
@last_id = id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def del_project_custom_build(id, repo_id)
|
||||||
|
CustomBuildScript.where(proj_id: id.to_i, repo_id: repo_id.to_i).delete
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -585,4 +585,24 @@ class ProjectsActions
|
|||||||
end
|
end
|
||||||
list
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_project_custom_build(id, repo_id)
|
||||||
|
data = {:script_name => nil, :content => nil, :description => nil, :created => nil }
|
||||||
|
result = @db.get_project_custom_build(id, repo_id).first
|
||||||
|
unless result.nil?
|
||||||
|
data[:script_name]=result[:filepath]
|
||||||
|
data[:content]=result[:content]
|
||||||
|
data[:description]=result[:descr]
|
||||||
|
data[:created]=result[:create_at]
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_project_custom_build(id, repo_id, script_name, descr, content)
|
||||||
|
@db.set_project_custom_build(id, repo_id, script_name, descr, content)
|
||||||
|
end
|
||||||
|
|
||||||
|
def del_project_custom_build(id, repo_id)
|
||||||
|
@db.del_project_custom_build(id, repo_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
17
db/migrations/202604180000000_create_custom_build.rb
Normal file
17
db/migrations/202604180000000_create_custom_build.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
require "sequel"
|
||||||
|
|
||||||
|
Sequel.migration do
|
||||||
|
change do
|
||||||
|
|
||||||
|
create_table(:custom_build_script) do
|
||||||
|
primary_key :id
|
||||||
|
String :content, text: true
|
||||||
|
String :filepath, text: true
|
||||||
|
String :descr, text: true
|
||||||
|
Datetime :create_at, default: Sequel.lit("CURRENT_TIMESTAMP")
|
||||||
|
foreign_key :proj_id, :projects, :key => :id
|
||||||
|
foreign_key :repo_id, :repos, :key => :id
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
47
install/docker_install.yml
Normal file
47
install/docker_install.yml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
- name: Install Docker on AlmaLinux
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
become: True
|
||||||
|
become_user: root
|
||||||
|
become_method: su
|
||||||
|
tasks:
|
||||||
|
- name: Remove old Docker packages
|
||||||
|
dnf:
|
||||||
|
name:
|
||||||
|
- docker
|
||||||
|
- docker-client
|
||||||
|
- docker-client-latest
|
||||||
|
- docker-common
|
||||||
|
- docker-latest
|
||||||
|
- docker-latest-logrotate
|
||||||
|
- docker-logrotate
|
||||||
|
- docker-engine
|
||||||
|
- podman
|
||||||
|
- runc
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Add Docker repository
|
||||||
|
command: sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
||||||
|
|
||||||
|
- name: Install Docker components
|
||||||
|
dnf:
|
||||||
|
name:
|
||||||
|
- docker-ce
|
||||||
|
- docker-ce-cli
|
||||||
|
- containerd.io
|
||||||
|
- docker-buildx-plugin
|
||||||
|
- docker-compose-plugin
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Start and enable Docker service
|
||||||
|
systemd:
|
||||||
|
name: docker
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
- name: Add user mockgui to the docker group
|
||||||
|
user:
|
||||||
|
name: mockgui
|
||||||
|
groups: docker
|
||||||
|
append: yes
|
||||||
124
views/prjcustombld.erb
Normal file
124
views/prjcustombld.erb
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<%= erb :header %>
|
||||||
|
<script src="/js/edit_area_full.js"></script>
|
||||||
|
<script language="javascript" type="text/javascript">
|
||||||
|
editAreaLoader.init({
|
||||||
|
id: "codedata",
|
||||||
|
syntax: "bash",
|
||||||
|
start_highlight: true,
|
||||||
|
language: "ru",
|
||||||
|
toolbar: "search, go_to_line, fullscreen, |, undo, redo, |, select_font,|, highlight, reset_highlight, word_wrap, |, syntax_selection"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% unless @error_data.nil? %>
|
||||||
|
<div class="container">
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert"><span><%= @error_data %></span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Закрыть"></button></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">
|
||||||
|
<h3 class="bg-secondary-subtle text-center border-bottom border-primary-subtle rounded-1 pb-1 mb-2">
|
||||||
|
<a href="/prjedit/<%= ERB::Util.url_encode(@proj_id) %>"><%= @proj_name %></a>
|
||||||
|
</h3>
|
||||||
|
<div class="pb-2"><%= @proj_descr %></div>
|
||||||
|
<div class="pb-2">git репозиторий <%= @git_name %></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<form action="/prjcstmbld/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(@git_id) %>" method="post" id="sndFrm">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="filepath" class="form-label">Имя скрипта сценария (англиские буквы, _, .), не должен совпадать с каким нибудь файлом из проекта</label>
|
||||||
|
<input type="text" class="form-control" id="filepath" name="filepath" value="<%= @old_filepath %>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="description" class="form-label">Описание скрипта сборки</label>
|
||||||
|
<textarea class="form-control" id="description" name="description" rows="3"><%= @old_descr %></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="codedata" class="form-label">Код скрипта сборки. Будьте внимательны, данный скрипт выолняется на сборочной машине,
|
||||||
|
все его изменения затронут хостовую систему, поэтому желательно как можно быстрее выполнение скрипта перенесите в Docker.
|
||||||
|
Так же после выполенения скрипта удалите и остановите все запущенные контейнеры, т.к скрипт сам должен контролировать это.
|
||||||
|
Так же убедитесь, что все log файлы сборки и собранные пакеты положены в каталоги:.
|
||||||
|
Скрипт выполняется из корня git проекта.
|
||||||
|
</label>
|
||||||
|
<textarea class="form-control" id="codedata" name="codedata" rows="15"><%= @old_content %></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 text-center">
|
||||||
|
<button type="submit" class="btn btn-primary" name="save" value="1">Сохранить</button>
|
||||||
|
<button type="submit" class="btn btn-secondary" name="cancel" value="3">Отмена</button>
|
||||||
|
<% unless @old_filepath.nil? %>
|
||||||
|
<button type="submit" class="btn btn-danger" id="delete" name="delete" value="2">Удалить</button>
|
||||||
|
<% end %>
|
||||||
|
<div id="winkeeper"></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="/js/jquery-confirm.min.js"></script>
|
||||||
|
<script>
|
||||||
|
$("#delete").confirm({
|
||||||
|
title: 'Подтвердите удаление скрипта, после удаления сборка будет происходить стандартно, через mock!',
|
||||||
|
content: '' +
|
||||||
|
'<div class="container">' +
|
||||||
|
'<form action="/prjcstmblddel/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(@git_id) %>" class="formName" method="post">' +
|
||||||
|
'<div class="text-danger mx-auto p-2">' +
|
||||||
|
'<label>Введите название удаляемого скрипта</label>' +
|
||||||
|
'<input type="text" class="frmchk form-control" required name="rcpnamedup"/>' +
|
||||||
|
'<input type="hidden" class="frmchk form-control" id="rcphid" name="rcphid" value="<%= @old_filepath %>"/>' +
|
||||||
|
'</div>' +
|
||||||
|
'</form>' +
|
||||||
|
'</div>',
|
||||||
|
container: '#winkeeper',
|
||||||
|
theme: 'bootstrap',
|
||||||
|
buttons: {
|
||||||
|
formSubmit: {
|
||||||
|
text: 'Удалить',
|
||||||
|
titleClass: 'text-danger mx-auto p-2',
|
||||||
|
btnClass: 'btn btn-danger',
|
||||||
|
action: function () {
|
||||||
|
var correct_name = this.$content.find("#rcphid").val();
|
||||||
|
var name = this.$content.find('.frmchk').val();
|
||||||
|
if(!name){
|
||||||
|
$.alert({
|
||||||
|
title: 'Предупреждение!',
|
||||||
|
content: 'Название не может быть пустым',
|
||||||
|
container: '#winkeeper',
|
||||||
|
theme: 'bootstrap',
|
||||||
|
buttons: {
|
||||||
|
ok: {
|
||||||
|
text: 'Хорошо',
|
||||||
|
btnClass: 'btn btn-danger',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (name != correct_name){
|
||||||
|
$.alert({
|
||||||
|
title: 'Предупреждение!',
|
||||||
|
content: 'Название задано неверно',
|
||||||
|
container: '#winkeeper',
|
||||||
|
theme: 'bootstrap',
|
||||||
|
buttons: {
|
||||||
|
ok: {
|
||||||
|
text: 'Хорошо',
|
||||||
|
btnClass: 'btn btn-danger',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.$content.find('form').submit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
text: 'Отменить',
|
||||||
|
btnClass: 'btn btn-primary',
|
||||||
|
action: function () {
|
||||||
|
//close
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<%= erb :footer %>
|
||||||
@@ -92,9 +92,9 @@
|
|||||||
<% @proj_repo.each do |item| %>
|
<% @proj_repo.each do |item| %>
|
||||||
<div class="row justify-content-between border-bottom border-light-subtle m-2">
|
<div class="row justify-content-between border-bottom border-light-subtle m-2">
|
||||||
<% unless item[:is_repo_synced] %>
|
<% unless item[:is_repo_synced] %>
|
||||||
<div class="col-8">
|
<div class="col-5">
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="col-7">
|
<div class="col-6">
|
||||||
<% end %>
|
<% end %>
|
||||||
<a href="/prjgitf/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(item[:id]) %>" class="p-2"><%= item[:reponame] %></a>
|
<a href="/prjgitf/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(item[:id]) %>" class="p-2"><%= item[:reponame] %></a>
|
||||||
</div>
|
</div>
|
||||||
@@ -115,6 +115,9 @@
|
|||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<a href="/prjgitbld/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(item[:id]) %>" class="p-2"><i class="bi bi-bricks"></i></a>
|
<a href="/prjgitbld/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(item[:id]) %>" class="p-2"><i class="bi bi-bricks"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
|
<a href="/prjcstmbld/<%= ERB::Util.url_encode(@proj_id) %>/<%= ERB::Util.url_encode(item[:id]) %>" class="p-2"><i class="bi bi-hammer"></i></a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user