Merge pull request #410 from abf/rosa-build:405-smart-build-scenarios-2

#405: Smart build scenarios 2
This commit is contained in:
avm 2014-07-01 13:30:23 +04:00
commit 94605f5ace
24 changed files with 225 additions and 71 deletions

View File

@ -1182,11 +1182,12 @@ div#advisory_search_block div.continue_input {
form.mass_build { form.mass_build {
section.left { section.left {
margin-left: 10px; margin-left: 10px;
width: 350px; width: 250px;
} }
section.right { section.right {
margin-right: 50px; margin-right: 50px;
width: 300px;
} }
input[type="submit"] { input[type="submit"] {
margin: 10px 0 10px 0; margin: 10px 0 10px 0;

View File

@ -14,6 +14,17 @@ class AutocompletesController < ApplicationController
render json: results.to_json render json: results.to_json
end end
def autocomplete_extra_mass_build
mb = MassBuild.where(id: params[:term]).first
results << {
id: mb.id,
value: mb.id,
label: "#{mb.id} - #{mb.name}",
path: platform_mass_build_path(mb.save_to_platform, mb)
} if mb && can?(:show, mb)
render json: results.to_json
end
def autocomplete_extra_repositories def autocomplete_extra_repositories
# Only personal and build for platform repositories can be attached to the build # Only personal and build for platform repositories can be attached to the build
Platform.includes(:repositories).search(params[:term]).search_order Platform.includes(:repositories).search(params[:term]).search_order

View File

@ -32,10 +32,11 @@ class BuildList < ActiveRecord::Base
EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm] EXTRA_PARAMS = %w[cfg_options cfg_urpm_options build_src_rpm build_rpm]
EXTERNAL_NODES = %w[owned everything] EXTERNAL_NODES = %w[owned everything]
AUTO_PUBLISH_STATUS_NONE = 'none' AUTO_PUBLISH_STATUSES = [
AUTO_PUBLISH_STATUS_DEFAULT = 'default' AUTO_PUBLISH_STATUS_NONE = 'none',
AUTO_PUBLISH_STATUS_DEFAULT = 'default',
AUTO_PUBLISH_STATUS_TESTING = 'testing' AUTO_PUBLISH_STATUS_TESTING = 'testing'
AUTO_PUBLISH_STATUSES = [AUTO_PUBLISH_STATUS_NONE, AUTO_PUBLISH_STATUS_DEFAULT, AUTO_PUBLISH_STATUS_TESTING] ]
validates :project_id, validates :project_id,
:project_version, :project_version,
@ -688,6 +689,11 @@ class BuildList < ActiveRecord::Base
end end
def prepare_extra_build_lists def prepare_extra_build_lists
if mass_build && mass_build.extra_mass_builds.present?
extra_build_lists ||= []
extra_build_lists << BuildList.where(mass_build_id: mass_build.extra_mass_builds, arch_id: arch_id).pluck(:id)
extra_build_lists.flatten!
end
return if extra_build_lists.blank? return if extra_build_lists.blank?
bls = BuildList.for_extra_build_lists(extra_build_lists, current_ability, save_to_platform) bls = BuildList.for_extra_build_lists(extra_build_lists, current_ability, save_to_platform)
if save_to_platform if save_to_platform

View File

@ -1,4 +1,7 @@
class MassBuild < ActiveRecord::Base class MassBuild < ActiveRecord::Base
AUTO_PUBLISH_STATUSES = %w(none default testing)
belongs_to :build_for_platform, -> { where(platform_type: 'main') }, class_name: 'Platform' belongs_to :build_for_platform, -> { where(platform_type: 'main') }, class_name: 'Platform'
belongs_to :save_to_platform, class_name: 'Platform' belongs_to :save_to_platform, class_name: 'Platform'
belongs_to :user belongs_to :user
@ -6,16 +9,17 @@ class MassBuild < ActiveRecord::Base
serialize :extra_repositories, Array serialize :extra_repositories, Array
serialize :extra_build_lists, Array serialize :extra_build_lists, Array
serialize :extra_mass_builds, Array
scope :recent, -> { order(created_at: :desc) } scope :recent, -> { order(created_at: :desc) }
scope :by_platform, -> (platform) { where(save_to_platform_id: platform.id) }
scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) } scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) }
scope :search, -> (q) { where("#{table_name}.description ILIKE ?", "%#{q}%") if q.present? } scope :search, -> (q) { where("#{table_name}.description ILIKE ?", "%#{q}%") if q.present? }
attr_accessor :arches attr_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id, attr_accessible :arches, :auto_publish_status, :projects_list, :build_for_platform_id,
:extra_repositories, :extra_build_lists, :increase_release_tag, :extra_repositories, :extra_build_lists, :increase_release_tag,
:use_cached_chroot, :use_extra_tests, :description :use_cached_chroot, :use_extra_tests, :description, :extra_mass_builds,
:include_testing_subrepository
validates :save_to_platform_id, validates :save_to_platform_id,
:build_for_platform_id, :build_for_platform_id,
@ -31,8 +35,10 @@ class MassBuild < ActiveRecord::Base
validates :description, validates :description,
length: { maximum: 255 } length: { maximum: 255 }
validates :auto_publish, validates :auto_publish_status,
:increase_release_tag, inclusion: { in: AUTO_PUBLISH_STATUSES }
validates :increase_release_tag,
:use_cached_chroot, :use_cached_chroot,
:use_extra_tests, :use_extra_tests,
inclusion: { in: [true, false] } inclusion: { in: [true, false] }

View File

@ -188,13 +188,14 @@ class Project < ActiveRecord::Base
bl.arch = arch bl.arch = arch
bl.project_version = project_version bl.project_version = project_version
bl.user = user bl.user = user
bl.auto_publish_status = mass_build.auto_publish? ? BuildList::AUTO_PUBLISH_STATUS_DEFAULT : BuildList::AUTO_PUBLISH_STATUS_NONE bl.auto_publish_status = mass_build.auto_publish_status
bl.include_repos = include_repos bl.include_repos = include_repos
bl.extra_repositories = mass_build.extra_repositories bl.extra_repositories = mass_build.extra_repositories
bl.extra_build_lists = mass_build.extra_build_lists bl.extra_build_lists = mass_build.extra_build_lists
bl.priority = priority bl.priority = priority
bl.mass_build_id = mass_build.id bl.mass_build_id = mass_build.id
bl.save_to_repository_id = repository_id bl.save_to_repository_id = repository_id
bl.include_testing_subrepository = mass_build.include_testing_subrepository?
bl.use_cached_chroot = mass_build.use_cached_chroot? bl.use_cached_chroot = mass_build.use_cached_chroot?
bl.use_extra_tests = mass_build.use_extra_tests? bl.use_extra_tests = mass_build.use_extra_tests?
end end

View File

@ -60,5 +60,24 @@ module AbfWorkerService
end end
end end
def filter_build_lists_without_packages(*build_lists)
ids = []
build_lists = build_lists.flatten.select do |build_list|
sha1 = build_list.packages.pluck(:sha1).find do |sha1|
!FileStoreService::File.new(sha1: sha1).exist?
end
if sha1.present?
ids << build_list.id
false
else
true
end
end
BuildList.where(id: ids).update_all(status: BuildList::PACKAGES_FAIL)
build_lists
end
end end
end end

View File

@ -9,6 +9,12 @@ module AbfWorkerService
def create! def create!
cleanup_folder cleanup_folder
if filter_build_lists_without_packages(build_list).blank?
build_list.fail_publish_container
return
end
Resque.push( Resque.push(
'publish_worker', # Low priority 'publish_worker', # Low priority
'class' => 'AbfWorker::PublishWorker', 'class' => 'AbfWorker::PublishWorker',

View File

@ -237,24 +237,5 @@ module AbfWorkerService
end end
end end
def filter_build_lists_without_packages(build_lists)
ids = []
build_lists = build_lists.select do |build_list|
sha1 = build_list.packages.pluck(:sha1).find do |sha1|
!FileStoreService::File.new(sha1: sha1).exist?
end
if sha1.present?
ids << build_list.id
false
else
true
end
end
BuildList.where(id: ids).update_all(status: BuildList::PACKAGES_FAIL)
build_lists
end
end end
end end

View File

@ -36,6 +36,12 @@
placeholder: 'uxteam_personal', placeholder: 'uxteam_personal',
subject: @mass_build, subject: @mass_build,
autocomplete_path: autocomplete_extra_repositories_autocompletes_path autocomplete_path: autocomplete_extra_repositories_autocompletes_path
= render 'shared/autocomplete_form',
field: :extra_mass_builds,
field_class: MassBuild,
placeholder: '1000000',
subject: @mass_build,
autocomplete_path: autocomplete_extra_mass_build_autocompletes_path
= render 'shared/autocomplete_form', = render 'shared/autocomplete_form',
field: :extra_build_lists, field: :extra_build_lists,
field_class: BuildList, field_class: BuildList,
@ -43,7 +49,10 @@
subject: @mass_build, subject: @mass_build,
autocomplete_path: autocomplete_extra_build_list_autocompletes_path autocomplete_path: autocomplete_extra_build_list_autocompletes_path
%h3= t("activerecord.attributes.build_list.preferences") %h3= t("activerecord.attributes.build_list.preferences")
- %i(auto_publish increase_release_tag use_cached_chroot use_extra_tests).each do |field| .both
= f.select :auto_publish_status, auto_publish_statuses
= f.label :auto_publish_status
- %i(increase_release_tag include_testing_subrepository use_cached_chroot use_extra_tests).each do |field|
.both .both
= f.check_box field = f.check_box field
= f.label field = f.label field

View File

@ -10,12 +10,79 @@
%td %td
%b= t('activerecord.attributes.mass_build.name') %b= t('activerecord.attributes.mass_build.name')
%td= link_to_mass_build(@mass_build) %td= link_to_mass_build(@mass_build)
- %i(id arch_names auto_publish increase_release_tag use_cached_chroot use_extra_tests created_at description).each do |field|
%tr %tr
%td %td
%b= t("activerecord.attributes.mass_build.#{field}") %b= t('activerecord.attributes.mass_build.id')
%td= @mass_build.send field %td= @mass_build.id
%tr
%td
%b= t('activerecord.attributes.mass_build.arch_names')
%td= @mass_build.arch_names
%tr
%td
%b= t('activerecord.attributes.mass_build.build_for_platform')
%td= link_to @mass_build.build_for_platform.name, platform_path(@mass_build.build_for_platform)
%tr
%td
%b= t('activerecord.attributes.mass_build.auto_publish_status')
%td= t("layout.build_lists.auto_publish_status.#{@mass_build.auto_publish_status}")
%tr
%td
%b= t('activerecord.attributes.mass_build.increase_release_tag')
%td= t("layout.#{@mass_build.increase_release_tag?}_")
%tr
%td
%b= t('activerecord.attributes.mass_build.include_testing_subrepository')
%td= t("layout.#{@mass_build.include_testing_subrepository?}_")
%tr
%td
%b= t('activerecord.attributes.mass_build.use_cached_chroot')
%td= t("layout.#{@mass_build.use_cached_chroot?}_")
%tr
%td
%b= t('activerecord.attributes.mass_build.use_extra_tests')
%td= t("layout.#{@mass_build.use_extra_tests?}_")
%tr
%td
%b= t('activerecord.attributes.mass_build.created_at')
%td= @mass_build.created_at
%tr
%td
%b= t('activerecord.attributes.mass_build.description')
%td= @mass_build.description
%tr
%td
%b= t("activerecord.attributes.build_list.extra_repositories")
%td
- if @mass_build.extra_repositories.present?
- Repository.where(id: @mass_build.extra_repositories).each do |repo|
%p= link_to "#{repo.platform.name}/#{repo.name}", [repo.platform, repo]
.both
- else
= t('layout.false_')
%tr
%td
%b= t("activerecord.attributes.build_list.extra_mass_builds")
%td
- if @mass_build.extra_mass_builds.present?
- MassBuild.where(id: @mass_build.extra_mass_builds).each do |mb|
%p= link_to "#{mb.id} - #{mb.name}", platform_mass_build_path(mb.save_to_platform, mb)
.both
- else
= t('layout.false_')
%tr
%td
%b= t("activerecord.attributes.build_list.extra_build_lists")
%td
- if @mass_build.extra_build_lists.present?
- BuildList.where(id: @mass_build.extra_build_lists).each do |bl|
%p= link_to "#{bl.id} (#{bl.project.name} - #{bl.arch.name})", bl
.both
- else
= t('layout.false_')
%tr %tr
%td %td
@ -49,7 +116,7 @@
.buttons_block .buttons_block
- if can?(:publish, @mass_build) - if can?(:publish, @mass_build)
- unless @mass_build.auto_publish? - unless @mass_build.auto_publish_status == BuildList::AUTO_PUBLISH_STATUS_DEFAULT
= link_to t('layout.mass_builds.publish_success'), = link_to t('layout.mass_builds.publish_success'),
publish_platform_mass_build_path(@platform, @mass_build.id), publish_platform_mass_build_path(@platform, @mass_build.id),
method: :post, data: { confirm: t("layout.confirm") }, class: 'button' method: :post, data: { confirm: t("layout.confirm") }, class: 'button'

View File

@ -0,0 +1,3 @@
:markdown
__Ability to attach at assembly packages of mass builds as additional sources of packages.__

View File

@ -0,0 +1,3 @@
:markdown
__Возможность подключить для сборки пакеты из массовой сборки как дополнительные источники пакетов.__

View File

@ -9,6 +9,7 @@ en:
name: Name name: Name
extra_repositories: Extra repositories extra_repositories: Extra repositories
extra_build_lists: Extra build lists extra_build_lists: Extra build lists
extra_mass_builds: Extra mass builds
auto_create_container: Create container automatically auto_create_container: Create container automatically
use_cached_chroot: Use cached chroot use_cached_chroot: Use cached chroot
use_extra_tests: Use extra tests use_extra_tests: Use extra tests

View File

@ -9,6 +9,7 @@ ru:
name: Название name: Название
extra_repositories: Дополнительные репозитории extra_repositories: Дополнительные репозитории
extra_build_lists: Дополнительные сборки extra_build_lists: Дополнительные сборки
extra_mass_builds: Дополнительные массовые сборки
auto_create_container: Создать контейнер автоматически auto_create_container: Создать контейнер автоматически
use_cached_chroot: Использовать кэшированный chroot use_cached_chroot: Использовать кэшированный chroot
use_extra_tests: Использовать дополнительные тесты use_extra_tests: Использовать дополнительные тесты

View File

@ -31,9 +31,11 @@ en:
updated_at: Updated updated_at: Updated
arch_names: Architectures arch_names: Architectures
user: User user: User
auto_publish: Automated publishing auto_publish_status: Automated publishing
increase_release_tag: Increase release tag increase_release_tag: Increase release tag
use_cached_chroot: Use cached chroot use_cached_chroot: Use cached chroot
use_extra_tests: Use extra tests use_extra_tests: Use extra tests
include_testing_subrepository: "Include 'testing' subrepository"
repositories: Repositories repositories: Repositories
projects_list: Projects list projects_list: Projects list
build_for_platform: Build for platform

View File

@ -32,9 +32,11 @@ ru:
updated_at: Обновлен updated_at: Обновлен
arch_names: Архитектуры arch_names: Архитектуры
user: Пользователь user: Пользователь
auto_publish: Автоматическая публикация auto_publish_status: Автоматическая публикация
increase_release_tag: Увеличить release тег increase_release_tag: Увеличить release тег
use_cached_chroot: Использовать кэшированный chroot use_cached_chroot: Использовать кэшированный chroot
use_extra_tests: Использовать дополнительные тесты use_extra_tests: Использовать дополнительные тесты
include_testing_subrepository: "Подключить 'testing' подрепозиторий"
repositories: Репозитории repositories: Репозитории
projects_list: Список проектов projects_list: Список проектов
build_for_platform: Собрано для платформы

View File

@ -230,6 +230,7 @@ Rosa::Application.routes.draw do
get :autocomplete_user_uname get :autocomplete_user_uname
get :autocomplete_group_uname get :autocomplete_group_uname
get :autocomplete_extra_build_list get :autocomplete_extra_build_list
get :autocomplete_extra_mass_build
get :autocomplete_extra_repositories get :autocomplete_extra_repositories
end end
end end

View File

@ -0,0 +1,16 @@
class AddAutoPublishStatusToMassBuilds < ActiveRecord::Migration
class MassBuild < ActiveRecord::Base
end
def up
add_column :mass_builds, :auto_publish_status, :string, default: 'none', null: false
MassBuild.where(auto_publish: true).update_all(auto_publish_status: :default)
remove_column :mass_builds, :auto_publish
end
def down
add_column :mass_builds, :auto_publish, :boolean, default: false
MassBuild.where(auto_publish_status: :default).update_all(auto_publish: true)
remove_column :mass_builds, :auto_publish_status
end
end

View File

@ -0,0 +1,5 @@
class AddExtraMassBuildsToMassBuilds < ActiveRecord::Migration
def change
add_column :mass_builds, :extra_mass_builds, :text
end
end

View File

@ -0,0 +1,5 @@
class AddIncludeTestingSubrepositoryToMassBuilds < ActiveRecord::Migration
def change
add_column :mass_builds, :include_testing_subrepository, :boolean, null: false, default: false
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140626195741) do ActiveRecord::Schema.define(version: 20140630205045) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -314,7 +314,6 @@ ActiveRecord::Schema.define(version: 20140626195741) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "arch_names" t.string "arch_names"
t.integer "user_id" t.integer "user_id"
t.boolean "auto_publish", default: false, null: false
t.integer "build_lists_count", default: 0, null: false t.integer "build_lists_count", default: 0, null: false
t.boolean "stop_build", default: false, null: false t.boolean "stop_build", default: false, null: false
t.text "projects_list" t.text "projects_list"
@ -328,6 +327,9 @@ ActiveRecord::Schema.define(version: 20140626195741) do
t.boolean "use_cached_chroot", default: true, null: false t.boolean "use_cached_chroot", default: true, null: false
t.boolean "use_extra_tests", default: false, null: false t.boolean "use_extra_tests", default: false, null: false
t.string "description" t.string "description"
t.string "auto_publish_status", default: "none", null: false
t.text "extra_mass_builds"
t.boolean "include_testing_subrepository", default: false, null: false
end end
create_table "users", force: true do |t| create_table "users", force: true do |t|

View File

@ -130,7 +130,6 @@ describe Platforms::MassBuildsController do
@create_params = { @create_params = {
mass_build: { mass_build: {
:projects_list => @repository.projects.map(&:name).join("\n"), :projects_list => @repository.projects.map(&:name).join("\n"),
:auto_publish => true,
:build_for_platform_id => @platform :build_for_platform_id => @platform
}, },
:platform_id => @platform, :platform_id => @platform,

View File

@ -4,7 +4,6 @@ FactoryGirl.define do
association :user association :user
projects_list "first" projects_list "first"
arches { [ Arch.where(name: 'x86_64').first_or_create.id ] } arches { [ Arch.where(name: 'x86_64').first_or_create.id ] }
auto_publish true
stop_build false stop_build false
end end
end end

View File

@ -12,10 +12,18 @@ describe AbfWorkerService::Container do
context '#create!' do context '#create!' do
it 'creates task' do it 'creates task' do
expect(build_list).to_not receive(:fail_publish_container)
expect(Resque).to receive(:push) expect(Resque).to receive(:push)
subject.create! subject.create!
end end
it 'fails when no packages on FS' do
expect(subject).to receive(:filter_build_lists_without_packages).and_return([])
expect(build_list).to receive(:fail_publish_container)
expect(Resque).to_not receive(:push)
subject.create!
end
end end
end end