diff --git a/app/controllers/api/v1/build_lists_controller.rb b/app/controllers/api/v1/build_lists_controller.rb index 91e8ce058..6d9889357 100644 --- a/app/controllers/api/v1/build_lists_controller.rb +++ b/app/controllers/api/v1/build_lists_controller.rb @@ -26,6 +26,7 @@ class Api::V1::BuildListsController < Api::V1::BaseController @build_list.user = current_user @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority + @build_list.new_core = BuildList.has_access_to_new_core?(current_user) && bl_params[:new_core] == '1' if @build_list.save render :action => 'show' diff --git a/app/controllers/platforms/product_build_lists_controller.rb b/app/controllers/platforms/product_build_lists_controller.rb index c41dce55d..e5b6b6c45 100644 --- a/app/controllers/platforms/product_build_lists_controller.rb +++ b/app/controllers/platforms/product_build_lists_controller.rb @@ -44,6 +44,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController def create pbl = @product.product_build_lists.new params[:product_build_list] pbl.project = @product.project + pbl.user = current_user pbl.base_url = "http://#{request.host_with_port}" if pbl.save diff --git a/app/models/platform.rb b/app/models/platform.rb index e8b055138..a5c6f85f3 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -30,8 +30,8 @@ class Platform < ActiveRecord::Base end } - after_create :create_directory - before_destroy :destroy_directory + before_create :create_directory + before_destroy :delete_destroy after_update :freeze_platform_and_update_repos after_update :update_owner_relation @@ -57,8 +57,7 @@ class Platform < ActiveRecord::Base system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*") end - def urpmi_list(host = nil, pair = nil, add_commands = true, repository_name = 'main') - host ||= default_host + def urpmi_list(host, pair = nil) blank_pair = {:login => 'login', :pass => 'password'} pair = blank_pair if pair.blank? urpmi_commands = ActiveSupport::OrderedHash.new @@ -68,10 +67,8 @@ class Platform < ActiveRecord::Base local_pair = pl.id != self.id ? blank_pair : pair head = hidden? ? "http://#{local_pair[:login]}@#{local_pair[:pass]}:#{host}/private/" : "http://#{host}/downloads/" Arch.all.each do |arch| - tail = "/#{arch.name}/#{repository_name}/release" - command = add_commands ? "urpmi.addmedia #{name} " : '' - command << "#{head}#{name}/repository/#{pl.name}#{tail}" - urpmi_commands[pl.name][arch.name] = command + tail = "/#{arch.name}/main/release" + urpmi_commands[pl.name][arch.name] = "urpmi.addmedia #{name} #{head}#{name}/repository/#{pl.name}#{tail}" end end @@ -95,7 +92,7 @@ class Platform < ActiveRecord::Base end def prefix_url(pub, options = {}) - options[:host] ||= default_host + options[:host] ||= EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host] pub ? "http://#{options[:host]}/downloads" : "http://#{options[:login]}:#{options[:password]}@#{options[:host]}/private" end @@ -142,7 +139,7 @@ class Platform < ActiveRecord::Base def full_clone(attrs = {}) base_clone(attrs).tap do |c| - with_skip {c.save} and c.clone_relations(self) and c.xml_rpc_clone # later with resque + with_skip {c.save} and c.clone_relations(self) and c.fs_clone # later with resque end end @@ -156,6 +153,10 @@ class Platform < ActiveRecord::Base end end + def create_directory + system("sudo mkdir -p -m 0777 #{build_path [name, 'repositories']}") + end + def symlink_directory # umount_directory_for_rsync # TODO ignore errors system("ln -s #{path} #{symlink_path}") @@ -176,6 +177,33 @@ class Platform < ActiveRecord::Base end end + def build_all(opts={}) + # Set options to build all need + repositories = opts[:repositories] ? self.repositories.where(:id => opts[:repositories]) : self.repositories + arches = opts[:arches] ? Arch.where(:id => opts[:arches]) : Arch.all + auto_publish = opts[:auto_publish] || false + user = opts[:user] + mass_build_id = opts[:mass_build_id] + mass_build = MassBuild.find mass_build_id + + repositories.each do |rep| + rep.projects.find_in_batches(:batch_size => 2) do |group| + sleep 1 + group.each do |p| + arches.map(&:name).each do |arch| + begin + return if mass_build.reload.stop_build + p.build_for(self, rep.id, user, arch, auto_publish, mass_build_id) + rescue RuntimeError, Exception + # p.async(:build_for, self, user, arch, auto_publish, mass_build_id) # TODO need this? + end + end + end + end + end + end + later :build_all, :loner => true, :queue => :clone_build + def destroy with_skip {super} # avoid cascade XML RPC requests end @@ -183,41 +211,22 @@ class Platform < ActiveRecord::Base protected - def default_host - EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host] - end - def build_path(dir) File.join(APP_CONFIG['root_path'], 'platforms', dir) end - def create_directory - Resque.enqueue(AbfWorker::FileSystemWorker, - {:id => id, :action => 'create', :type => 'platform'}) - return true + def detele_directory + FileUtils.rm_rf path end - def destroy_directory - Resque.enqueue(AbfWorker::FileSystemWorker, - {:id => id, :action => 'destroy', :type => 'platform'}) - return true + def fs_clone(old_name = parent.name, new_name = name) + FileUtils.cp_r "#{parent.path}/repository", path end - - def xml_rpc_clone(old_name = parent.name, new_name = name) - result = BuildServer.clone_platform new_name, old_name, APP_CONFIG['root_path'] + '/platforms' - if result == BuildServer::SUCCESS - return true - else - raise "Failed to clone platform #{old_name} with code #{result}. Path: #{build_path(old_name)} to platform #{new_name}" - end - end - later :xml_rpc_clone, :loner => true, :queue => :clone_build + later :fs_clone, :loner => true, :queue => :clone_build def freeze_platform_and_update_repos if released_changed? && released == true - result = BuildServer.freeze(name) - raise "Failed freeze platform #{name} with code #{result}" if result != BuildServer::SUCCESS repositories.update_all(:publish_without_qa => false) end end -end +end \ No newline at end of file diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index c89b57786..7b28899f3 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -31,6 +31,7 @@ class ProductBuildList < ActiveRecord::Base belongs_to :product belongs_to :project belongs_to :arch + belongs_to :user validates :product_id, @@ -130,12 +131,14 @@ class ProductBuildList < ActiveRecord::Base def abf_worker_args file_name = "#{project.owner.uname}-#{project.name}-#{commit_hash}" + opts = {:host => ActionMailer::Base.default_url_options[:host]} + opts.merge!({:user => user.authentication_token, :password => ''}) if user.present? srcpath = url_helpers.archive_url( project.owner, project.name, file_name, 'tar.gz', - :host => ActionMailer::Base.default_url_options[:host] + opts ) { :id => id, @@ -146,7 +149,8 @@ class ProductBuildList < ActiveRecord::Base :time_living => time_living, :main_script => main_script, :arch => arch.name, - :distrib_type => product.platform.distrib_type + :distrib_type => product.platform.distrib_type, + :user => {:uname => user.try(:uname), :email => user.try(:email)} } end diff --git a/app/views/platforms/product_build_lists/show.html.haml b/app/views/platforms/product_build_lists/show.html.haml index d3f52459c..ce0efcdc9 100644 --- a/app/views/platforms/product_build_lists/show.html.haml +++ b/app/views/platforms/product_build_lists/show.html.haml @@ -10,6 +10,8 @@ = render 'show_field', :key => :id, :value => pbl.id = render 'show_field', :key => :status, :value => pbl.human_status +- if pbl.user + = render 'show_field', :key => :user, :value => link_to(pbl.user.try(:fullname), pbl.user) = render 'show_field', :key => :product, :value => link_to(pbl.product.name, platform_product_path(platform, product)) diff --git a/config/locales/models/product_build_list.en.yml b/config/locales/models/product_build_list.en.yml index 945bdaaec..e554e1d57 100644 --- a/config/locales/models/product_build_list.en.yml +++ b/config/locales/models/product_build_list.en.yml @@ -31,6 +31,7 @@ en: attributes: product_build_list: id: Id + user: User product: Product container_path: Container status: Status diff --git a/config/locales/models/product_build_list.ru.yml b/config/locales/models/product_build_list.ru.yml index a6efbd419..d593aa3f4 100644 --- a/config/locales/models/product_build_list.ru.yml +++ b/config/locales/models/product_build_list.ru.yml @@ -31,6 +31,7 @@ ru: attributes: product_build_list: id: Id + user: Пользователь product: Продукт container_path: Контейнер status: Статус diff --git a/db/migrate/20121214145009_add_user_to_product_build_list.rb b/db/migrate/20121214145009_add_user_to_product_build_list.rb new file mode 100644 index 000000000..daaef5242 --- /dev/null +++ b/db/migrate/20121214145009_add_user_to_product_build_list.rb @@ -0,0 +1,5 @@ +class AddUserToProductBuildList < ActiveRecord::Migration + def change + add_column :product_build_lists, :user_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 81f5cc892..cf6ffe34e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,14 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20121211132948) do +ActiveRecord::Schema.define(:version => 20121214145009) do create_table "activity_feeds", :force => true do |t| t.integer "user_id", :null => false t.string "kind" t.text "data" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "advisories", :force => true do |t| @@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "arches", :force => true do |t| t.string "name", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true @@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.integer "user_id" t.string "provider" t.string "uid" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true @@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.integer "level" t.integer "status" t.integer "build_list_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "version" end @@ -110,8 +110,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.integer "project_id" t.integer "arch_id" t.datetime "notified_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "is_circle", :default => false t.text "additional_repos" t.string "name" @@ -145,8 +145,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "commentable_type" t.integer "user_id" t.text "body" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.decimal "commentable_id", :precision => 50, :scale => 0 t.integer "project_id" t.text "data" @@ -164,8 +164,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "controller" t.string "action" t.text "message" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end create_table "flash_notifies", :force => true do |t| @@ -179,8 +179,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "groups", :force => true do |t| t.integer "owner_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "uname" t.integer "own_projects_count", :default => 0, :null => false t.text "description" @@ -197,8 +197,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "title" t.text "body" t.string "status", :default => "open" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" t.datetime "closed_at" t.integer "closed_by" @@ -260,14 +260,14 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "description" t.string "name", :null => false t.integer "parent_platform_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "released", :default => false, :null => false t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open", :null => false t.string "platform_type", :default => "main", :null => false - t.string "distrib_type" + t.string "distrib_type", :null => false end add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false @@ -276,16 +276,16 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.integer "platform_id" t.string "login" t.string "password" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "user_id" end create_table "product_build_lists", :force => true do |t| t.integer "product_id" - t.integer "status", :default => 3, :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "status", :default => 2, :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "project_id" t.string "project_version" t.string "commit_hash" @@ -294,6 +294,7 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.text "results" t.integer "arch_id" t.integer "time_living" + t.integer "user_id" end add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id" @@ -301,8 +302,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "products", :force => true do |t| t.string "name", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "description" t.integer "project_id" t.string "params" @@ -315,8 +316,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "name" t.string "version" t.datetime "file_mtime" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "platform_id" end @@ -325,27 +326,27 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "project_to_repositories", :force => true do |t| t.integer "project_id" t.integer "repository_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end add_index "project_to_repositories", ["repository_id", "project_id"], :name => "index_project_to_repositories_on_repository_id_and_project_id", :unique => true create_table "projects", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.integer "owner_id" t.string "owner_type" t.string "visibility", :default => "open" t.text "description" t.string "ancestry" t.boolean "has_issues", :default => true - t.boolean "has_wiki", :default => false t.string "srpm_file_name" - t.string "srpm_content_type" t.integer "srpm_file_size" t.datetime "srpm_updated_at" + t.string "srpm_content_type" + t.boolean "has_wiki", :default => false t.string "default_branch", :default => "master" t.boolean "is_package", :default => true, :null => false t.integer "average_build_time", :default => 0, :null => false @@ -375,8 +376,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "token" t.boolean "approved", :default => false t.boolean "rejected", :default => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "interest" t.text "more" t.string "language" @@ -390,16 +391,16 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "actor_type" t.integer "target_id" t.string "target_type" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "role" end create_table "repositories", :force => true do |t| t.string "description", :null => false t.integer "platform_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.string "name", :null => false t.boolean "publish_without_qa", :default => true end @@ -413,8 +414,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.boolean "new_comment_reply", :default => true t.boolean "new_issue", :default => true t.boolean "issue_assign", :default => true - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "new_comment_commit_owner", :default => true t.boolean "new_comment_commit_repo_owner", :default => true t.boolean "new_comment_commit_commentor", :default => true @@ -425,8 +426,8 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "subscribes", :force => true do |t| t.string "subscribeable_type" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.boolean "status", :default => true t.integer "project_id" t.decimal "subscribeable_id", :precision => 50, :scale => 0 @@ -434,21 +435,18 @@ ActiveRecord::Schema.define(:version => 20121211132948) do create_table "users", :force => true do |t| t.string "name" - t.string "email", :default => "", :null => false - t.string "encrypted_password", :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" t.text "ssh_key" t.string "uname" t.string "role" - t.string "language", :default => "en" - t.integer "own_projects_count", :default => 0, :null => false - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" + t.string "language", :default => "en" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -457,11 +455,14 @@ ActiveRecord::Schema.define(:version => 20121211132948) do t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" - t.integer "failed_attempts", :default => 0 + t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" - t.integer "build_priority", :default => 50 + t.integer "build_priority", :default => 50 end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token" diff --git a/lib/recipes/resque.rb b/lib/recipes/resque.rb index be682f2e8..6b9ff53e0 100644 --- a/lib/recipes/resque.rb +++ b/lib/recipes/resque.rb @@ -33,6 +33,7 @@ Capistrano::Configuration.instance(:must_exist).load do :notification, :iso_worker_observer, :rpm_worker_observer, + :publish_build_list_container_observer, :file_system_worker ].join(',') run "cd #{fetch :current_path} && COUNT=#{workers_count} QUEUE=#{queue} #{rails_env} BACKGROUND=yes bundle exec rake resque:workers"