Merge pull request #857 from warpc/create-container-for-build-list

[refs #857] Create container for BuildList
This commit is contained in:
Vladimir Sharshov 2013-01-25 09:49:14 -08:00
commit 5880be2d34
10 changed files with 67 additions and 8 deletions

View File

@ -5,7 +5,7 @@ class Projects::BuildListsController < Projects::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :search, :log] if APP_CONFIG['anonymous_access']
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log]
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log, :create_container]
load_and_authorize_resource :project, :only => NESTED_ACTIONS
load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true
@ -89,6 +89,11 @@ class Projects::BuildListsController < Projects::BaseController
end
end
def create_container
AbfWorker::BuildListsPublishTaskManager.create_container_for @build_list
redirect_to :back, :notice => t('layout.build_lists.container_will_be_created')
end
def cancel
notice = if @build_list.cancel
t('layout.build_lists.will_be_canceled')

View File

@ -77,11 +77,7 @@ module BuildListsHelper
end
def container_url
if @build_list.new_core?
@build_list.container_path
else
"http://#{request.host_with_port}/downloads#{@build_list.container_path}".html_safe
end
"http://#{request.host_with_port}/downloads#{@build_list.container_path}".html_safe
end
def build_list_log_url(log_type)

View File

@ -87,7 +87,7 @@ class Ability
can(:reject_publish, BuildList) do |build_list|
local_admin?(build_list.save_to_platform)
end
can(:cancel, BuildList) {|build_list| can?(:write, build_list.project)}
can([:cancel, :create_container], BuildList) {|build_list| can?(:write, build_list.project)}
can [:read, :owned, :related, :members], Platform, :owner_type => 'User', :owner_id => user.id
can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids

View File

@ -124,6 +124,11 @@ class BuildList < ActiveRecord::Base
serialize :results, Array
after_commit :place_build
after_destroy lambda {
if save_to_platform
system "rm -rf #{save_to_platform.path}/container/#{id}"
end
}
state_machine :status, :initial => :waiting_for_response do

View File

@ -14,6 +14,8 @@
[@build_list.save_to_platform, @build_list.save_to_repository])]
- elsif @build_list.container_path.present?
= link_to container_url, container_url
- elsif @build_list.container_path == ''
= t("layout.build_lists.creating")
.both
.leftlist= t("activerecord.attributes.build_list.bs_id")
@ -89,6 +91,9 @@
- if @build_list.can_cancel? && can?(:cancel, @build_list)
= link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
- if @build_list.success? && can?(:create_container, @build_list)
= link_to t("layout.build_lists.create_container"), create_container_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
- if @build_list.can_publish? && @build_list.save_to_platform.released && @build_list.advisory.nil? && can?(:publish, @build_list)
#advisory_block

View File

@ -47,6 +47,7 @@ en:
layout:
build_lists:
create_container: Create container
platform_deleted: platform has been deleted
filter_header: Filter
current: Curent
@ -64,6 +65,8 @@ en:
cancel: Cancel build
cancel_success: 'Build canceled'
will_be_canceled: 'Build will be canceled...'
container_will_be_created: 'Container will be created...'
creating: 'creating...'
publish_success: 'Build published'
cancel_fail: 'Errors during build cancelation!'
publish_fail: 'Errors during build publishing!'

View File

@ -46,6 +46,7 @@ ru:
layout:
build_lists:
create_container: Создать контейнер
platform_deleted: платформа была удалена
filter_header: Фильтр
current: Текущие
@ -62,6 +63,8 @@ ru:
show: Просмотр
cancel: Отменить сборку
will_be_canceled: 'Сборка будет отменена...'
container_will_be_created: 'Контейнер будет создан...'
creating: 'создается...'
cancel_success: 'Сборка отменена.'
cancel_fail: 'При отмене сборки произошла ошибка!'
publish_success: 'Сборка поставлена в очередь на публикацию.'

View File

@ -210,6 +210,7 @@ Rosa::Application.routes.draw do
resources :build_lists, :only => [:index, :show, :update] do
member do
put :cancel
put :create_container
get :log
end
collection { post :search }

View File

@ -65,6 +65,42 @@ module AbfWorker
def redis
Resque.redis
end
def create_container_for(build_list)
platform_path = "#{build_list.save_to_platform.path}/container/#{build_list.id}"
return if File.directory?(platform_path)
system "mkdir -p #{platform_path}"
build_list.update_attributes(:container_path => '')
packages = {:sources => [], :binaries => {:x86_64 => [], :i586 => []}}
packages[:sources] = build_list.packages.by_package_type('source').pluck(:sha1).compact
packages[:binaries][build_list.arch.name.to_sym] = build_list.packages.by_package_type('binary').pluck(:sha1).compact
Resque.push(
'publish_worker_default',
'class' => 'AbfWorker::PublishWorkerDefault',
'args' => [{
:id => build_list.id,
:arch => build_list.arch.name,
:distrib_type => build_list.build_for_platform.distrib_type,
:platform => {
:platform_path => platform_path,
:released => build_list.save_to_platform.released
},
:repository => {
:name => build_list.save_to_repository.name,
:id => build_list.save_to_repository.id
},
:type => :publish,
:time_living => 9600 # 160 min
:packages => packages,
:old_packages => {:sources => [], :binaries => {:x86_64 => [], :i586 => []}},
:build_list_ids => [build_list.id],
:projects_for_cleanup => [],
:extra => {:create_container => true}
})]
)
end
end
private

View File

@ -9,7 +9,12 @@ module AbfWorker
if options['type'] == 'resign'
AbfWorker::BuildListsPublishTaskManager.unlock_repository options['id']
else
update_rpm_builds options, status
if options['extra']['create_container'] # Container has been created
bl = BuildList.find(options['id'])
bl.update_attributes(:container_path => "/#{bl.save_to_platform.name}/container/#{bl.id}")
else
update_rpm_builds options, status
end
end
end