2012-12-25 20:15:21 +00:00
|
|
|
namespace :new_core do
|
2012-12-29 16:16:56 +00:00
|
|
|
|
2013-01-10 12:30:18 +00:00
|
|
|
desc 'Extracts all rpms from BuildList container and updates BuildList::Package#sha1 field'
|
2014-01-21 04:51:49 +00:00
|
|
|
task update_packages: :environment do
|
2013-01-10 12:30:18 +00:00
|
|
|
say "[#{Time.zone.now}] Starting to extract rpms..."
|
|
|
|
|
2014-03-18 13:58:51 +00:00
|
|
|
token = User.find_by(uname: 'rosa_system').authentication_token
|
2014-01-21 04:51:49 +00:00
|
|
|
BuildList.where(new_core: true).
|
|
|
|
where(status: [
|
2013-01-24 11:32:00 +00:00
|
|
|
BuildList::SUCCESS,
|
2013-01-10 12:30:18 +00:00
|
|
|
BuildList::FAILED_PUBLISH,
|
|
|
|
BuildList::BUILD_PUBLISHED,
|
|
|
|
BuildList::BUILD_PUBLISH
|
|
|
|
]).
|
|
|
|
order(:id).
|
2014-01-21 04:51:49 +00:00
|
|
|
find_in_batches(batch_size: 100) do | build_lists |
|
2013-01-11 13:06:21 +00:00
|
|
|
|
2013-01-15 11:55:51 +00:00
|
|
|
build_lists.each do | bl |
|
|
|
|
puts "[#{Time.zone.now}] - where build_lists.id #{bl.id}"
|
|
|
|
|
|
|
|
sha1 = (bl.results.find{ |r| r['file_name'] =~ /.*\.tar\.gz$/ } || {})['sha1']
|
|
|
|
next unless sha1
|
|
|
|
dir = Dir.mktmpdir('update-packages-', "#{APP_CONFIG['root_path']}")
|
|
|
|
begin
|
|
|
|
system "cd #{dir} && curl -L -O #{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}; tar -xzf #{sha1}"
|
|
|
|
system "rm -f #{dir}/#{sha1}"
|
|
|
|
|
|
|
|
extract_rpms_and_update_packages("#{dir}/archives/SRC_RPM", bl, 'source', token)
|
|
|
|
extract_rpms_and_update_packages("#{dir}/archives/RPM", bl, 'binary', token)
|
|
|
|
ensure
|
|
|
|
# remove the directory.
|
2013-01-15 18:55:32 +00:00
|
|
|
`sudo rm -rf #{dir}`
|
2013-01-15 11:55:51 +00:00
|
|
|
end
|
2013-01-11 13:06:21 +00:00
|
|
|
end
|
2013-01-15 11:55:51 +00:00
|
|
|
end
|
2013-01-10 12:30:18 +00:00
|
|
|
|
|
|
|
say "[#{Time.zone.now}] done"
|
|
|
|
end
|
|
|
|
|
2013-01-10 12:49:01 +00:00
|
|
|
def extract_rpms_and_update_packages(dir, bl, package_type, token)
|
2013-01-10 12:30:18 +00:00
|
|
|
Dir.glob("#{dir}/*.rpm") do |rpm_file|
|
|
|
|
fullname = File.basename rpm_file
|
2013-01-11 12:27:29 +00:00
|
|
|
package = bl.packages.by_package_type(package_type).find{ |p| p.fullname == fullname }
|
2013-01-10 12:30:18 +00:00
|
|
|
next unless package
|
2014-01-21 04:51:49 +00:00
|
|
|
|
2013-01-10 12:30:18 +00:00
|
|
|
package.sha1 = Digest::SHA1.file(rpm_file).hexdigest
|
2013-01-10 14:48:26 +00:00
|
|
|
if %x[ curl #{APP_CONFIG['file_store_url']}/api/v1/file_stores.json?hash=#{package.sha1} ] == '[]'
|
2013-01-10 12:30:18 +00:00
|
|
|
system "curl --user #{token}: -POST -F 'file_store[file]=@#{rpm_file}' #{APP_CONFIG['file_store_url']}/api/v1/upload"
|
|
|
|
end
|
|
|
|
package.save!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-25 20:15:21 +00:00
|
|
|
end
|