From f4c3d23d7c1c21b1979d4afb80657543896aa71f Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 25 Jan 2013 21:24:46 +0400 Subject: [PATCH] create container for BuildList --- .../projects/build_lists_controller.rb | 7 +++- app/helpers/build_lists_helper.rb | 6 +--- app/models/ability.rb | 2 +- app/views/projects/build_lists/show.html.haml | 5 +++ config/locales/models/build_list.en.yml | 3 ++ config/locales/models/build_list.ru.yml | 3 ++ config/routes.rb | 1 + .../build_lists_publish_task_manager.rb | 36 +++++++++++++++++++ lib/abf_worker/publish_observer.rb | 7 +++- 9 files changed, 62 insertions(+), 8 deletions(-) diff --git a/app/controllers/projects/build_lists_controller.rb b/app/controllers/projects/build_lists_controller.rb index 5d2e207c5..86a5b5829 100644 --- a/app/controllers/projects/build_lists_controller.rb +++ b/app/controllers/projects/build_lists_controller.rb @@ -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') diff --git a/app/helpers/build_lists_helper.rb b/app/helpers/build_lists_helper.rb index 44b48cdb1..e028ae8ad 100644 --- a/app/helpers/build_lists_helper.rb +++ b/app/helpers/build_lists_helper.rb @@ -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) diff --git a/app/models/ability.rb b/app/models/ability.rb index dd4450562..884757cde 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -84,7 +84,7 @@ class Ability can(:publish, BuildList) do |build_list| build_list.save_to_repository.publish_without_qa ? can?(:write, build_list.project) : local_admin?(build_list.save_to_platform) end - can(:reject_publish, BuildList) do |build_list| + can([:reject_publish, :create_container], BuildList) do |build_list| local_admin?(build_list.save_to_platform) end can(:cancel, BuildList) {|build_list| can?(:write, build_list.project)} diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index b209d5e7d..5cb879374 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -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 diff --git a/config/locales/models/build_list.en.yml b/config/locales/models/build_list.en.yml index eb8176233..dee17ed66 100644 --- a/config/locales/models/build_list.en.yml +++ b/config/locales/models/build_list.en.yml @@ -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!' diff --git a/config/locales/models/build_list.ru.yml b/config/locales/models/build_list.ru.yml index 878b108c0..8986c473f 100644 --- a/config/locales/models/build_list.ru.yml +++ b/config/locales/models/build_list.ru.yml @@ -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: 'Сборка поставлена в очередь на публикацию.' diff --git a/config/routes.rb b/config/routes.rb index d9ac372b0..28252dee4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 } diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index d516f6b8e..4bd11453f 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -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 diff --git a/lib/abf_worker/publish_observer.rb b/lib/abf_worker/publish_observer.rb index 7242e740b..4bdf6c027 100644 --- a/lib/abf_worker/publish_observer.rb +++ b/lib/abf_worker/publish_observer.rb @@ -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