From 82869f57a73b414a12c7383ff59e256f2ec465e9 Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 14:47:57 +0400 Subject: [PATCH 1/6] build list items and more statuses --- app/controllers/build_lists_controller.rb | 36 ++++++--- app/models/build_list.rb | 19 +++-- app/models/build_list/item.rb | 38 ++++++++++ app/views/build_lists/index.html.haml | 2 +- app/views/build_lists/show.html.haml | 76 +++++++++++++++++++ config/locales/ru.yml | 17 +++++ config/routes.rb | 2 +- .../20110408123808_create_build_list_items.rb | 21 +++++ ...541_add_additional_repos_to_build_lists.rb | 9 +++ .../20110408134718_add_name_to_build_lists.rb | 9 +++ db/schema.rb | 17 ++++- 11 files changed, 227 insertions(+), 19 deletions(-) create mode 100644 app/models/build_list/item.rb create mode 100644 app/views/build_lists/show.html.haml create mode 100644 db/migrate/20110408123808_create_build_list_items.rb create mode 100644 db/migrate/20110408132541_add_additional_repos_to_build_lists.rb create mode 100644 db/migrate/20110408134718_add_name_to_build_lists.rb diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 6101a9699..fb64cee4c 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -1,12 +1,12 @@ class BuildListsController < ApplicationController before_filter :authenticate_user! - before_filter :find_platform, :only => [:index, :filter] - before_filter :find_repository, :only => [:index, :filter] - before_filter :find_project, :only => [:index, :filter] + before_filter :find_platform, :only => [:index, :filter, :show] + before_filter :find_repository, :only => [:index, :filter, :show] + before_filter :find_project, :only => [:index, :filter, :show] before_filter :find_arches, :only => [:index, :filter] before_filter :find_branches, :only => [:index, :filter] - before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build] + before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build, :new_bbdt] def index @build_lists = @project.build_lists.recent.paginate :page => params[:page] @@ -20,13 +20,20 @@ class BuildListsController < ApplicationController render :action => "index" end + def show + @build_list = @project.build_lists.find(params[:id]) + @item_groups = @build_list.items.group_by_level + end + def status_build -# -# @build_list.status = params[:status] -# @build_list.container_path = params[:container_path] -# @build_list.notified_at = Time.now -# -# @build_list.save + @item = @build_list.items.find_by_name!(params[:package_name]) + @item.status = params[:status] + @item.save + + @build_list.container_path = params[:container_path] + @build_list.notified_at = Time.now + + @build_list.save render :nothing => true, :status => 200 end @@ -61,6 +68,15 @@ class BuildListsController < ApplicationController render :nothing => true, :status => 200 end + def new_bbdt + @build_list.name = params[:name] + @build_list.additional_repos = params[:additional_repos] + @build_list.set_items(params[:items]) + @build_list.save + + render :nothing => true, :status => 200 + end + protected def find_platform @platform = Platform.find params[:platform_id] diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 1d6272fb8..f798e700e 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -1,6 +1,7 @@ class BuildList < ActiveRecord::Base belongs_to :project belongs_to :arch + has_many :items, :class_name => "BuildList::Item", :dependent => :destroy validates :project_id, :presence => true validates :branch_name, :presence => true @@ -8,12 +9,8 @@ class BuildList < ActiveRecord::Base BUILD_PENDING = 2 BUILD_STARTED = 3 - STATUSES = [BuildServer::SUCCESS, BUILD_PENDING, BUILD_STARTED, BuildServer::BUILD_ERROR] #, BuildServer::DEPENDENCIES_FAIL, BuildServer::SRPM_NOT_FOUND, BuildServer::MOCK_NOT_FOUND] -# BUILD_ERROR_STATUSES = [ BuildServer::BUILD_ERROR, BuildServer::MOCK_NOT_FOUND, BuildServer::DEPENDENCIES_FAIL, BuildServer::SRPM_NOT_FOUND] + STATUSES = [BuildServer::SUCCESS, BUILD_PENDING, BUILD_STARTED, BuildServer::BUILD_ERROR] HUMAN_STATUSES = { BuildServer::BUILD_ERROR => :build_error, -# BuildServer::MOCK_NOT_FOUND => :mock_not_found, -# BuildServer::DEPENDENCIES_FAIL => :dependencies_fail, -# BuildServer::SRPM_NOT_FOUND => :srpm_not_found, BUILD_PENDING => :build_pending, BUILD_STARTED => :build_started, BuildServer::SUCCESS => :success @@ -44,6 +41,8 @@ class BuildList < ActiveRecord::Base end } + serialize :additional_repos + def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") end @@ -52,4 +51,14 @@ class BuildList < ActiveRecord::Base self.class.human_status(status) end + def set_items(items_hash) + self.items = [] + + items_hash.each do |level, items| + items.each do |item| + self.items << self.items.build(:name => item, :level => level.to_i) + end + end + end + end \ No newline at end of file diff --git a/app/models/build_list/item.rb b/app/models/build_list/item.rb new file mode 100644 index 000000000..a4cb2cdab --- /dev/null +++ b/app/models/build_list/item.rb @@ -0,0 +1,38 @@ +class BuildList::Item < ActiveRecord::Base + belongs_to :build_list + + attr_protected :build_list_id + + STATUSES = [BuildServer::SUCCESS, BuildServer::DEPENDENCIES_FAIL, BuildServer::SRPM_NOT_FOUND, BuildServer::MOCK_NOT_FOUND] + HUMAN_STATUSES = { + BuildServer::MOCK_NOT_FOUND => :mock_not_found, + BuildServer::DEPENDENCIES_FAIL => :dependencies_fail, + BuildServer::SRPM_NOT_FOUND => :srpm_not_found, + BuildServer::SUCCESS => :success + } + + scope :recent, order("level ASC, name ASC") + + def self.group_by_level + items = scoped({}).recent + + groups = [] + current_level = -1 + items.each do |item| + groups << [] if current_level < item.level + groups.last << item + current_level = item.level + end + + groups + end + + def self.human_status(status) + I18n.t("layout.build_lists.items.statuses.#{HUMAN_STATUSES[status]}") + end + + def human_status + self.class.human_status(status) + end + +end \ No newline at end of file diff --git a/app/views/build_lists/index.html.haml b/app/views/build_lists/index.html.haml index d375846c4..8a3ac16ba 100644 --- a/app/views/build_lists/index.html.haml +++ b/app/views/build_lists/index.html.haml @@ -12,4 +12,4 @@ .inner = render :partial => "build_lists/build_lists", :object => @build_lists -- content_for :sidebar, render(:partial => 'git/shared/sidebar') \ No newline at end of file +-#- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file diff --git a/app/views/build_lists/show.html.haml b/app/views/build_lists/show.html.haml new file mode 100644 index 000000000..77e31e5cc --- /dev/null +++ b/app/views/build_lists/show.html.haml @@ -0,0 +1,76 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.build_lists.current"), platform_repository_project_path(@platform, @repository, @project) + "#build_lists" + %li= link_to t("layout.build_lists.all"), platform_repository_project_build_lists_path(@platform, @repository, @project) + + .content + .inner + %p + %b + = t("activerecord.attributes.build_list.name") + \: + = @build_list.present? ? @build_list.name : t("layout.build_lists.name_not_yet_defined") + %p + %b + = t("activerecord.attributes.build_list.bs_id") + \: + = @build_list.bs_id + %p + %b + = t("activerecord.attributes.build_list.container_path") + \: + = @build_list.container_path + %p + %b + = t("activerecord.attributes.build_list.status") + \: + = @build_list.human_status + %p + %b + = t("activerecord.attributes.build_list.branch_name") + \: + = @build_list.branch_name + %p + %b + = t("activerecord.attributes.build_list.project") + \: + = @build_list.project.name + %p + %b + = t("activerecord.attributes.build_list.arch") + \: + = @build_list.arch.name + %p + %b + = t("activerecord.attributes.build_list.notified_at") + \: + = @build_list.notified_at + %p + %b + = t("activerecord.attributes.build_list.is_circle") + \: + = @build_list.is_circle + + %p + %b + = t("activerecord.attributes.build_list.additional_repos") + \: + = @build_list.additional_repos + +.block + .content + .inner + - @item_groups.each_with_index do |group, level| + %h3.title Level ##{level} + %table.table + %tr + %th.first= t("activerecord.attributes.build_list/item.name") + %th.last= t("activerecord.attributes.build_list/item.status") + + - group.each do |item| + %tr{:class => cycle("odd", "even")} + %td= item.name + %td.last= item.human_status + +-#- content_for :sidebar, render(:partial => 'sidebar') diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 9c3addeb7..82639c4c0 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -90,6 +90,13 @@ ru: created_at_end: "Время постановки на сборку по:" notified_at_start: "Время последнего обновления от BS с:" notified_at_end: "Время последнего обновления от BS по:" + items: + statuses: + build_error: ошибка сборки + mock_not_found: mock не найден + dependencies_fail: dependencies fail + srpm_not_found: srpm не найден + success: собран statuses: build_error: ошибка сборки mock_not_found: mock не найден @@ -140,6 +147,8 @@ ru: project: Проект rpm: RPM user: Пользователь + build_list: Сборочный лист + build_list item: Элемент сборочного листа attributes: repository: @@ -198,6 +207,7 @@ ru: build_list: bs_id: Id + name: Название container_path: Путь до контейнера status: Статус branch_name: Branch @@ -207,5 +217,12 @@ ru: arch: Архитектура is_circle: Циклическая сборка notified_at: Информация получена + additional_repos: Дополнительные репозитории updated_at: Обновлен created_at: Создан + + build_list/item: + name: Название + level: Уровень + status: Статус + build_list: Сборочный лист diff --git a/config/routes.rb b/config/routes.rb index 874c20a22..e510f4a42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ Rosa::Application.routes.draw do resources :repositories do resources :projects do resource :repo, :controller => "git/repositories", :only => [:show] - resources :build_lists, :only => [:index] do + resources :build_lists, :only => [:index, :show] do collection do get :recent post :filter diff --git a/db/migrate/20110408123808_create_build_list_items.rb b/db/migrate/20110408123808_create_build_list_items.rb new file mode 100644 index 000000000..db9538fef --- /dev/null +++ b/db/migrate/20110408123808_create_build_list_items.rb @@ -0,0 +1,21 @@ +class CreateBuildListItems < ActiveRecord::Migration + def self.up + create_table :build_list_items, :force => true do |t| + t.string :name + t.integer :level + t.integer :status + + t.integer :build_list_id + + t.timestamps + end + + add_index :build_list_items, :build_list_id + end + + def self.down + remove_index :build_list_items, :build_list_id + + drop_table :build_list_items + end +end diff --git a/db/migrate/20110408132541_add_additional_repos_to_build_lists.rb b/db/migrate/20110408132541_add_additional_repos_to_build_lists.rb new file mode 100644 index 000000000..480655348 --- /dev/null +++ b/db/migrate/20110408132541_add_additional_repos_to_build_lists.rb @@ -0,0 +1,9 @@ +class AddAdditionalReposToBuildLists < ActiveRecord::Migration + def self.up + add_column :build_lists, :additional_repos, :text + end + + def self.down + remove_column :build_lists, :additional_repos + end +end diff --git a/db/migrate/20110408134718_add_name_to_build_lists.rb b/db/migrate/20110408134718_add_name_to_build_lists.rb new file mode 100644 index 000000000..dd1ad13ec --- /dev/null +++ b/db/migrate/20110408134718_add_name_to_build_lists.rb @@ -0,0 +1,9 @@ +class AddNameToBuildLists < ActiveRecord::Migration + def self.up + add_column :build_lists, :name, :string + end + + def self.down + remove_column :build_lists, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index a7a7d0fdc..d3fd8bd9a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110407144147) do +ActiveRecord::Schema.define(:version => 20110408134718) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -20,6 +20,17 @@ ActiveRecord::Schema.define(:version => 20110407144147) do add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true + create_table "build_list_items", :force => true do |t| + t.string "name" + t.integer "level" + t.integer "status" + t.integer "build_list_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "build_list_items", ["build_list_id"], :name => "index_build_list_items_on_build_list_id" + create_table "build_lists", :force => true do |t| t.integer "bs_id" t.string "container_path" @@ -30,7 +41,9 @@ ActiveRecord::Schema.define(:version => 20110407144147) do t.datetime "notified_at" t.datetime "created_at" t.datetime "updated_at" - t.boolean "is_circle", :default => false + t.boolean "is_circle", :default => false + t.text "additional_repos" + t.string "name" end add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id" From 4c5ef7e8f3ea2181a7054f9c538f8dc08509e2f0 Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 14:50:09 +0400 Subject: [PATCH 2/6] link to a build list --- app/views/build_lists/_build_lists.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/build_lists/_build_lists.html.haml b/app/views/build_lists/_build_lists.html.haml index 6f58ce692..dd5155944 100644 --- a/app/views/build_lists/_build_lists.html.haml +++ b/app/views/build_lists/_build_lists.html.haml @@ -10,7 +10,7 @@ - build_lists.each do |build_list| %tr{:class => cycle("odd", "even")} - %td= build_list.bs_id + %td= link_to build_list.bs_id, platform_repository_project_build_list_path(@platform, @repository, @project, build_list) %td= build_list.human_status %td= link_to build_list.branch_name, "#" %td= link_to build_list.project.name, platform_repository_project_path(@platform, @repository, @project) From 4da241672b26adf1b1dde152137feb7478c6bf8e Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 16:56:22 +0400 Subject: [PATCH 3/6] auth by ip --- app/controllers/application_controller.rb | 6 ++++++ app/controllers/build_lists_controller.rb | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 067db12ee..9d4dd539b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -10,4 +10,10 @@ class ApplicationController < ActionController::Base "application" end end + + def authenticate_by_ip! + if request.remote_ip != APP_CONFIG['auth_by_ip'] + render :nothing => true, :status => 403 + end + end end diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index fb64cee4c..72163dc7c 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -1,5 +1,6 @@ class BuildListsController < ApplicationController - before_filter :authenticate_user! + before_filter :authenticate_user!, :except => [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt] + before_filter :authenticate_by_ip!, :only => [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt] before_filter :find_platform, :only => [:index, :filter, :show] before_filter :find_repository, :only => [:index, :filter, :show] before_filter :find_project, :only => [:index, :filter, :show] From 3895defa454ae29233a9d11d2cb0bece9c89fd57 Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 17:04:03 +0400 Subject: [PATCH 4/6] defferent ip auth for build service and product builder --- app/controllers/application_controller.rb | 10 ++++++++-- app/controllers/build_lists_controller.rb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9d4dd539b..51b260773 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -11,8 +11,14 @@ class ApplicationController < ActionController::Base end end - def authenticate_by_ip! - if request.remote_ip != APP_CONFIG['auth_by_ip'] + def authenticate_build_service! + if request.remote_ip != APP_CONFIG['build_service_ip'] + render :nothing => true, :status => 403 + end + end + + def authenticate_product_builder! + if request.remote_ip != APP_CONFIG['product_builder_ip'] render :nothing => true, :status => 403 end end diff --git a/app/controllers/build_lists_controller.rb b/app/controllers/build_lists_controller.rb index 72163dc7c..de415f9c8 100644 --- a/app/controllers/build_lists_controller.rb +++ b/app/controllers/build_lists_controller.rb @@ -1,6 +1,6 @@ class BuildListsController < ApplicationController before_filter :authenticate_user!, :except => [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt] - before_filter :authenticate_by_ip!, :only => [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt] + before_filter :authenticate_build_service!, :only => [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt] before_filter :find_platform, :only => [:index, :filter, :show] before_filter :find_repository, :only => [:index, :filter, :show] before_filter :find_project, :only => [:index, :filter, :show] From 1a6330956bc26c1ad90a791c7b51cf63853eacbf Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 20:37:09 +0400 Subject: [PATCH 5/6] build list creation --- Gemfile | 1 + Gemfile.lock | 5 ++ app/controllers/projects_controller.rb | 57 ++++++++++++++++++- app/models/build_list.rb | 43 ++++++++++++-- app/views/build_lists/_build_lists.html.haml | 4 +- app/views/build_lists/_sidebar.html.haml | 14 +++++ app/views/build_lists/index.html.haml | 2 +- app/views/build_lists/show.html.haml | 10 +++- app/views/projects/build.html.haml | 37 ++++++++++++ app/views/projects/new.html.haml | 3 + app/views/projects/show.html.haml | 1 + config/locales/ru.yml | 23 +++++++- config/routes.rb | 6 ++ .../20110411160955_create_delayed_jobs.rb | 21 +++++++ db/schema.rb | 17 +++++- script/delayed_job | 5 ++ 16 files changed, 235 insertions(+), 14 deletions(-) create mode 100644 app/views/build_lists/_sidebar.html.haml create mode 100644 app/views/projects/build.html.haml create mode 100644 db/migrate/20110411160955_create_delayed_jobs.rb create mode 100755 script/delayed_job diff --git a/Gemfile b/Gemfile index 68de76b3d..c770fbf38 100644 --- a/Gemfile +++ b/Gemfile @@ -50,5 +50,6 @@ gem "hoptoad_notifier", "~> 2.3" gem "russian" gem "grit" gem 'unicorn' +gem 'delayed_job' gem 'jammit' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index cca96982a..e0082a62f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,10 @@ GEM closure-compiler (1.1.1) compass (0.10.6) haml (>= 3.0.4) + daemons (1.1.0) + delayed_job (2.1.4) + activesupport (~> 3.0) + daemons devise (1.1.7) bcrypt-ruby (~> 2.1.2) warden (~> 1.0.2) @@ -142,6 +146,7 @@ DEPENDENCIES capistrano capistrano-ext compass (>= 0.10.6) + delayed_job devise factory_girl_rails grit diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 84c1464e5..76f69c1f7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -2,7 +2,7 @@ class ProjectsController < ApplicationController before_filter :authenticate_user! before_filter :find_platform before_filter :find_repository - before_filter :find_project, :only => [:show, :destroy] + before_filter :find_project, :only => [:show, :destroy, :build, :process_build] def new @project = @repository.projects.new @@ -12,6 +12,37 @@ class ProjectsController < ApplicationController @current_build_lists = @project.build_lists.current.recent.paginate :page => params[:page] end + def build + @branches = @project.git_repository.branches + @arches = Arch.recent + end + + def process_build + @arch_ids = params[:build][:arches].select{|_,v| v == "1"}.collect{|x| x[0].to_i } + @arches = Arch.where(:id => @arch_ids) + + @branches = @project.git_repository.branches + @branch = @branches.select{|branch| branch.name == params[:build][:branch] }.first + + if !check_arches || !check_branches + @arches = Arch.recent + render :action => "build" + else + flash[:notice], flash[:error] = "", "" + @arches.each do |arch| + build_list = @project.build_lists.new(:arch => arch, :branch_name => @branch.name) + + if build_list.save + flash[:notice] += t("flash.build_list.saved", :branch_name => @branch.name, :arch => arch.name) + else + flash[:error] += t("flash.build_list.save_error", :branch_name => @branch.name, :arch => arch.name) + end + end + + redirect_to platform_repository_project_path(@platform, @repository, @project) + end + end + def create @project = @repository.projects.new params[:project] if @project.save @@ -43,4 +74,28 @@ class ProjectsController < ApplicationController def find_project @project = @repository.projects.find params[:id] end + + def check_arches + if @arch_ids.blank? + flash[:error] = t("flash.build_list.no_arch_selected") + false + elsif @arch_ids.length != @arches.length + flash[:error] = t("flash.build_list.no_arch_found") + false + else + true + end + end + + def check_branches + if @branch.blank? + flash[:error] = t("flash.build_list.no_branch_selected") + false + elsif !@branches.include?(@branch) + flash[:error] = t("flash.build_list.no_branch_found") + false + else + true + end + end end diff --git a/app/models/build_list.rb b/app/models/build_list.rb index f798e700e..eceba83e2 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -6,18 +6,36 @@ class BuildList < ActiveRecord::Base validates :project_id, :presence => true validates :branch_name, :presence => true - BUILD_PENDING = 2 - BUILD_STARTED = 3 + WAITING_FOR_RESPONSE = 4000 + BUILD_PENDING = 2000 + BUILD_STARTED = 3000 + + STATUSES = [WAITING_FOR_RESPONSE, + BuildServer::SUCCESS, + BUILD_PENDING, + BUILD_STARTED, + BuildServer::BUILD_ERROR, + BuildServer::PLATFORM_NOT_FOUND, + BuildServer::PLATFORM_PENDING, + BuildServer::PROJECT_NOT_FOUND, + BuildServer::BRANCH_NOT_FOUND] - STATUSES = [BuildServer::SUCCESS, BUILD_PENDING, BUILD_STARTED, BuildServer::BUILD_ERROR] HUMAN_STATUSES = { BuildServer::BUILD_ERROR => :build_error, BUILD_PENDING => :build_pending, BUILD_STARTED => :build_started, - BuildServer::SUCCESS => :success + BuildServer::SUCCESS => :success, + WAITING_FOR_RESPONSE => :waiting_for_response, + BuildServer::PLATFORM_NOT_FOUND => :platform_not_found, + BuildServer::PLATFORM_PENDING => :platform_pending, + BuildServer::PROJECT_NOT_FOUND => :project_not_found, + BuildServer::BRANCH_NOT_FOUND => :branch_not_found } scope :recent, order("created_at DESC") - scope :current, lambda { where(["status in (?) OR (status in (?) AND notified_at >= ?)", [BUILD_PENDING, BUILD_STARTED], [BuildServer::SUCCESS, BuildServer::ERROR], Time.now - 2.days]) } + scope :current, lambda { + outdatable_statuses = [BuildServer::SUCCESS, BuildServer::ERROR, BuildServer::PLATFORM_NOT_FOUND, BuildServer::PLATFORM_PENDING, BuildServer::PROJECT_NOT_FOUND, BuildServer::BRANCH_NOT_FOUND] + where(["status in (?) OR (status in (?) AND notified_at >= ?)", [WAITING_FOR_RESPONSE, BUILD_PENDING, BUILD_STARTED], outdatable_statuses, Time.now - 2.days]) + } scope :for_status, lambda {|status| where(:status => status) } scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) } scope :scoped_to_branch, lambda {|branch| where(:branch_name => branch) } @@ -42,6 +60,9 @@ class BuildList < ActiveRecord::Base } serialize :additional_repos + + before_create :set_default_status + after_create :place_build def self.human_status(status) I18n.t("layout.build_lists.statuses.#{HUMAN_STATUSES[status]}") @@ -61,4 +82,16 @@ class BuildList < ActiveRecord::Base end end + private + def set_default_status + self.status = WAITING_FOR_RESPONSE unless self.status.present? + end + + def place_build + self.status = BuildServer.add_build_list project.name, branch_name, project.platform.name, arch.name + self.status = BUILD_PENDING if self.status == 0 + save + end + handle_asynchronously :place_build + end \ No newline at end of file diff --git a/app/views/build_lists/_build_lists.html.haml b/app/views/build_lists/_build_lists.html.haml index dd5155944..3f4142409 100644 --- a/app/views/build_lists/_build_lists.html.haml +++ b/app/views/build_lists/_build_lists.html.haml @@ -10,12 +10,12 @@ - build_lists.each do |build_list| %tr{:class => cycle("odd", "even")} - %td= link_to build_list.bs_id, platform_repository_project_build_list_path(@platform, @repository, @project, build_list) + %td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), platform_repository_project_build_list_path(@platform, @repository, @project, build_list) %td= build_list.human_status %td= link_to build_list.branch_name, "#" %td= link_to build_list.project.name, platform_repository_project_path(@platform, @repository, @project) %td= build_list.arch.name - %td= build_list.is_circle? + %td= t("layout.#{build_list.is_circle?}_") %td.last= build_list.notified_at = will_paginate build_lists \ No newline at end of file diff --git a/app/views/build_lists/_sidebar.html.haml b/app/views/build_lists/_sidebar.html.haml new file mode 100644 index 000000000..cf9f05506 --- /dev/null +++ b/app/views/build_lists/_sidebar.html.haml @@ -0,0 +1,14 @@ +.block.notice + %h3= t("layout.platforms.current_platform_header") + .content + %p= link_to @platform.name, platform_path(@platform) + +.block.notice + %h3= t("layout.repositories.current_repository_header") + .content + %p= link_to @repository.name + repository_name_postfix(@platform), platform_repository_path(@platform, @repository) + +.block.notice + %h3= t("layout.projects.current_project_header") + .content + %p= link_to @project.name, platform_repository_path(@platform, @repository) + "#projects" \ No newline at end of file diff --git a/app/views/build_lists/index.html.haml b/app/views/build_lists/index.html.haml index 8a3ac16ba..3e369ecb2 100644 --- a/app/views/build_lists/index.html.haml +++ b/app/views/build_lists/index.html.haml @@ -12,4 +12,4 @@ .inner = render :partial => "build_lists/build_lists", :object => @build_lists --#- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file +- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file diff --git a/app/views/build_lists/show.html.haml b/app/views/build_lists/show.html.haml index 77e31e5cc..5e6b6fc2c 100644 --- a/app/views/build_lists/show.html.haml +++ b/app/views/build_lists/show.html.haml @@ -3,6 +3,7 @@ %ul.wat-cf %li.first= link_to t("layout.build_lists.current"), platform_repository_project_path(@platform, @repository, @project) + "#build_lists" %li= link_to t("layout.build_lists.all"), platform_repository_project_build_lists_path(@platform, @repository, @project) + %li.active= link_to t("layout.build_lists.show"), platform_repository_project_build_list_path(@platform, @repository, @project, @build_list) .content .inner @@ -50,7 +51,7 @@ %b = t("activerecord.attributes.build_list.is_circle") \: - = @build_list.is_circle + = t("layout.#{@build_list.is_circle?}_") %p %b @@ -60,7 +61,12 @@ .block .content + %h2= t("layout.build_lists.items_header") + .inner + - if @item_groups.blank? + = t("layout.build_lists.no_items_data") + - @item_groups.each_with_index do |group, level| %h3.title Level ##{level} %table.table @@ -73,4 +79,4 @@ %td= item.name %td.last= item.human_status --#- content_for :sidebar, render(:partial => 'sidebar') +- content_for :sidebar, render(:partial => 'sidebar') \ No newline at end of file diff --git a/app/views/projects/build.html.haml b/app/views/projects/build.html.haml new file mode 100644 index 000000000..e50f2fd32 --- /dev/null +++ b/app/views/projects/build.html.haml @@ -0,0 +1,37 @@ +.block + .secondary-navigation + %ul.wat-cf + %li.first= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" + %li= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) + %li= link_to t("layout.projects.show"), platform_repository_project_path(@platform, @repository, @project) + %li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project) + %li.active= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project) + + .content + %h2.title= t("layout.projects.new_build") + + .inner + = form_for :build, :url => process_build_platform_repository_project_path(@platform, @repository, @project), :html => { :class => :form, :method => :post } do |f| + .columns.wat-cf + .column.left + .group + = f.label :branch, "Branch", :class => :label + = f.select :branch, @branches.collect{|branch| [branch.name, branch.name]} + + .column.right + .group + = f.label :arches, t("activerecord.attributes.build_list.arch"), :class => :label + - @arches.each do |arch| + = f.check_box "arches[#{arch.id}]" + = arch.name + %br + + .group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.projects.build_button")) + = t("layout.projects.build_button") + %span.text_button_padding= t("layout.or") + = link_to t("layout.cancel"), platform_repository_path(@platform, @repository), :class => "text_button_padding link_button" + + +- content_for :sidebar, render(:partial => 'sidebar') diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index 54aaee9e0..ff1751dfe 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -3,6 +3,9 @@ %ul.wat-cf %li.first= link_to t("layout.projects.list"), platform_repository_path(@platform, @repository) + "#projects" %li.active= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) + %li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project) + %li= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project) + .content %h2.title= t("layout.projects.new_header") .inner diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index a8c12d65d..417edd325 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -5,6 +5,7 @@ %li= link_to t("layout.projects.new"), new_platform_repository_project_path(@platform, @repository) %li.active= link_to t("layout.projects.show"), platform_repository_project_path(@platform, @repository, @project) %li= link_to "git-repo", platform_repository_project_repo_path(@platform, @repository, @project) + %li= link_to t("layout.projects.build"), build_platform_repository_project_path(@platform, @repository, @project) .content .inner diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 82639c4c0..c15c204ac 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -16,6 +16,8 @@ ru: or: или yes_: Да no_: Нет + true_: Да + false_: Нет menu: users: Пользователи platforms: Платформы @@ -56,15 +58,17 @@ ru: list: Список list_header: Проекты show: Проект + build: Собрать + new_build: Новая сборка confirm_delete: Вы уверены, что хотите удалить этот проект? new: Новый проект new_header: Новый проект new_header: Новый проект location: Расположение git_repo_location: Путь к git-репозиторию - back_to_the_list: ⇐ К списку проектов репозитория current_project_header: Текущий проект current_build_lists: Текущие сборки + build_button: Начать сборку users: list: Список new: Создать @@ -90,6 +94,10 @@ ru: created_at_end: "Время постановки на сборку по:" notified_at_start: "Время последнего обновления от BS с:" notified_at_end: "Время последнего обновления от BS по:" + bs_id_not_set: Id еще не присвоен + items_header: Элементы сборки + no_items_data: Данных нет + show: Просмотр items: statuses: build_error: ошибка сборки @@ -102,9 +110,14 @@ ru: mock_not_found: mock не найден dependencies_fail: dependencies fail srpm_not_found: srpm не найден + waiting_for_response: ожидает ответа build_pending: ожидает сборку success: собран build_started: собирается + platform_not_found: платформа не найдена + platform_pending: платформа в процессе создания + project_not_found: проект не найден + branch_not_found: бранч не найден flash: project: @@ -127,7 +140,13 @@ ru: unfreezed: Платформа успешно разморожена unfreeze_error: Не удалось разморозить платформу, попробуйте еще раз destroyed: Платформа успешно удалена - + build_list: + saved: Билд лист для бранча '%{branch_name}' и архитектуры '%{arch}' создан успешно + save_error: Не удалось сохранить билд лист для бранча '%{branch_name}' и архитектуры '%{arch}' + no_branch_selected: Выберите какой-нибудь бранч + no_branch_found: Выбранный бранч '%{branch_name}' не найден + no_arch_selected: Выберите хотя бы одну ахритектуру + no_arch_found: Выбранные ахритектуры не найдены attributes: password: Пароль diff --git a/config/routes.rb b/config/routes.rb index ad5902f1e..bc9da8597 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,12 @@ Rosa::Application.routes.draw do post :filter end end + + member do + get :build + post :process_build + end + end end end diff --git a/db/migrate/20110411160955_create_delayed_jobs.rb b/db/migrate/20110411160955_create_delayed_jobs.rb new file mode 100644 index 000000000..ac579dfcd --- /dev/null +++ b/db/migrate/20110411160955_create_delayed_jobs.rb @@ -0,0 +1,21 @@ +class CreateDelayedJobs < ActiveRecord::Migration + def self.up + create_table :delayed_jobs, :force => true do |table| + table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue + table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually. + table.text :handler # YAML-encoded string of the object that will do work + table.text :last_error # reason for last failure (See Note below) + table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. + table.datetime :locked_at # Set when a client is working on this object + table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) + table.string :locked_by # Who is working on this object (if locked) + table.timestamps + end + + add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' + end + + def self.down + drop_table :delayed_jobs + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index b8d388cc6..62c6f592b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110411082826) do +ActiveRecord::Schema.define(:version => 20110411160955) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -58,6 +58,21 @@ ActiveRecord::Schema.define(:version => 20110411082826) do t.datetime "updated_at" end + create_table "delayed_jobs", :force => true do |t| + t.integer "priority", :default => 0 + t.integer "attempts", :default => 0 + t.text "handler" + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority" + create_table "platforms", :force => true do |t| t.string "name" t.string "unixname" diff --git a/script/delayed_job b/script/delayed_job new file mode 100755 index 000000000..edf195985 --- /dev/null +++ b/script/delayed_job @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) +require 'delayed/command' +Delayed::Command.new(ARGV).daemonize From ad61eec876d800e2c661b598c6da398157b468ec Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Mon, 11 Apr 2011 20:51:54 +0400 Subject: [PATCH 6/6] added dj to deploy (starting only one worker for now) --- config/deploy.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 9e6583f78..e1242959a 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -34,24 +34,27 @@ task :symlink_config_files do run "mkdir -p #{deploy_to}/#{shared_dir}/config" run "yes n | cp -i #{release_path}/config/database.yml.sample #{deploy_to}/#{shared_dir}/config/database.yml" -# run "yes n | cp -i #{release_path}/config/config.yml.sample #{deploy_to}/#{shared_dir}/config/config.yml" run "yes n | cp -i #{release_path}/config/application.yml.sample #{deploy_to}/#{shared_dir}/config/application.yml" run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml" -# run "ln -nfs #{deploy_to}/#{shared_dir}/config/config.yml #{release_path}/config/config.yml" run "ln -nfs #{deploy_to}/#{shared_dir}/config/application.yml #{release_path}/config/application.yml" - end namespace :deploy do desc "Restarting mod_rails with restart.txt" task :restart, :roles => :app, :except => { :no_release => true } do run "cd #{deploy_to}/current ; ([ -f tmp/pids/unicorn.pid ] && kill -USR2 `cat tmp/pids/unicorn.pid`); true" + restart_dj end %w(start).each { |name| task name, :roles => :app do deploy.restart end } + desc "Restart delayed job" + task :restart_dj, :roles => :web do + run "cd #{deploy_to}/current ; RAILS_ENV=production ./script/delayed_job stop; RAILS_ENV=production ./script/delayed_job start; true" + end + desc "Rude restart application" task :rude_restart, :roles => :web do run "cd #{deploy_to}/current ; pkill unicorn; sleep 0.5; pkill -9 unicorn; sleep 0.5 ; unicorn_rails -c config/unicorn.rb -E production -D " @@ -64,9 +67,7 @@ namespace :deploy do envs = "RAILS_ENV=production" # Precaching assets - run_locally "bash -c '" + -# "#{envs} compass compile && " + - "#{envs} jammit'" + run_locally "bash -c '#{envs} jammit'" # Uploading prechached assets top.upload assets_path, "#{current_release}/public", :via => :scp, :recursive => true