Merge branch 'staging'
This commit is contained in:
commit
f3f5ef8c3b
6 changed files with 137 additions and 0 deletions
2
Gemfile
2
Gemfile
|
@ -90,6 +90,8 @@ gem 'as_csv'
|
|||
gem 'apipie-rails', '=0.3.1'
|
||||
gem "maruku" # for Markdown support in apipie
|
||||
|
||||
gem 'openstack'
|
||||
|
||||
group :test do
|
||||
gem 'capybara'
|
||||
gem 'factory_girl'
|
||||
|
|
|
@ -391,6 +391,8 @@ GEM
|
|||
validate_email
|
||||
validate_url
|
||||
webfinger (>= 1.0.1)
|
||||
openstack (2.0.2)
|
||||
json
|
||||
orm_adapter (0.5.0)
|
||||
parallel (1.6.1)
|
||||
parallel_tests (1.9.0)
|
||||
|
@ -659,6 +661,7 @@ DEPENDENCIES
|
|||
mina!
|
||||
nyan-cat-formatter
|
||||
openid_connect
|
||||
openstack
|
||||
parallel_tests
|
||||
pg
|
||||
poltergeist
|
||||
|
|
16
Rakefile
16
Rakefile
|
@ -6,12 +6,28 @@ require File.expand_path('../config/application', __FILE__)
|
|||
Rails.application.load_tasks
|
||||
|
||||
task :deploy do
|
||||
domains = %w(37.187.249.111 149.202.72.152 149.202.198.6)
|
||||
domains.each do |domain|
|
||||
sh "mina deploy domain=#{domain}"
|
||||
end
|
||||
end
|
||||
|
||||
task :deploy_ha do
|
||||
domains = %w(149.202.72.152 149.202.198.6)
|
||||
domains.each do |domain|
|
||||
sh "mina deploy domain=#{domain}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
task :deploy_old do
|
||||
domains = %w(37.187.154.237 37.187.249.111)
|
||||
domains.each do |domain|
|
||||
sh "mina deploy domain=#{domain}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
task :deploy_test do
|
||||
domains = %w(192.168.0.116)
|
||||
branch = 'clamav'
|
||||
|
|
|
@ -65,6 +65,7 @@ set :shared_paths, [
|
|||
'config/database.yml',
|
||||
"config/fog_credentials.yml",
|
||||
'config/initializers/secret_token.rb',
|
||||
'config/initializers/features.yml',
|
||||
"config/environments/#{ENV['to']}.rb",
|
||||
"config/initializers/token.rb",
|
||||
"config/initializers/super_admin.rb",
|
||||
|
|
1
config/initializers/openstack_version.rb
Normal file
1
config/initializers/openstack_version.rb
Normal file
|
@ -0,0 +1 @@
|
|||
OpenStack::VERSION = 2.0
|
114
lib/tasks/cloud_storage.rake
Normal file
114
lib/tasks/cloud_storage.rake
Normal file
|
@ -0,0 +1,114 @@
|
|||
namespace :cloudstorage do
|
||||
|
||||
task init: :environment do
|
||||
os_config = (YAML.load_file(Fog.credentials_path))['default']
|
||||
@os = OpenStack::Connection.create(
|
||||
{
|
||||
username: os_config['openstack_username'],
|
||||
api_key: os_config['openstack_api_key'],
|
||||
auth_method: "password",
|
||||
auth_url: "https://auth.cloud.ovh.net/v2.0/",
|
||||
authtenant_name: os_config['openstack_tenant'],
|
||||
service_type: "object-store",
|
||||
region: os_config['openstack_region']
|
||||
}
|
||||
)
|
||||
@cont = @os.container(CarrierWave::Uploader::Base.fog_directory)
|
||||
end
|
||||
|
||||
desc 'Move local attestations on cloud storage'
|
||||
task migrate: :environment do
|
||||
puts 'Starting migration'
|
||||
|
||||
Rake::Task['cloudstorage:init'].invoke
|
||||
|
||||
error_count = 0
|
||||
[Cerfa, PieceJustificative, Procedure].each { |c|
|
||||
c.all.each { |entry|
|
||||
content = (c == Procedure) ? entry.logo : entry.content
|
||||
unless content.current_path.nil? || File.exist?(File.dirname(content.current_path) + '/uploaded')
|
||||
secure_token = SecureRandom.uuid
|
||||
filename = "#{entry.class.to_s.underscore}-#{secure_token}#{File.extname(content.current_path)}"
|
||||
puts "Uploading #{content.current_path}"
|
||||
begin
|
||||
@cont.create_object(filename, {}, File.open(content.current_path))
|
||||
|
||||
File.open(File.dirname(content.current_path) + '/uploaded', "w+") { |f| f.write(File.basename(content.current_path)) }
|
||||
File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "w+") { |f| f.write(filename) }
|
||||
File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "w+") { |f| f.write(secure_token) }
|
||||
|
||||
entry.update_column(c == Procedure ? :logo : :content, filename)
|
||||
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
|
||||
rescue Errno::ENOENT
|
||||
puts "ERROR: #{content.current_path} does not exist!"
|
||||
File.open('upload_errors.report', "a+") { |f| f.write(content.current_path) }
|
||||
error_count += 1
|
||||
end
|
||||
else
|
||||
if !content.current_path.nil? && File.exist?(File.dirname(content.current_path) + '/uploaded')
|
||||
filename = File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read
|
||||
secure_token = File.open(File.dirname(content.current_path) + '/secure_token_cloudstorage', "r").read
|
||||
|
||||
entry.update_column(c == Procedure ? :logo : :content, filename)
|
||||
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, secure_token)
|
||||
|
||||
puts "RESTORE IN DATABASE: #{filename} "
|
||||
elsif !content.current_path.nil?
|
||||
puts "Skipping #{content.current_path}"
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
puts "There were #{error_count} errors while uploading files. See upload_errors.report file for details."
|
||||
puts 'Enf of migration'
|
||||
end
|
||||
|
||||
desc 'Clear documents in tenant and revert file entries in database'
|
||||
task :revert do
|
||||
Rake::Task['cloudstorage:init'].invoke
|
||||
|
||||
[Cerfa, PieceJustificative, Procedure].each { |c|
|
||||
c.all.each { |entry|
|
||||
content = (c == Procedure) ? entry.logo : entry.content
|
||||
unless content.current_path.nil?
|
||||
if File.exist?(File.dirname(content.current_path) + '/uploaded')
|
||||
previous_filename = File.read(File.dirname(content.current_path) + '/uploaded')
|
||||
|
||||
entry.update_column(c == Procedure ? :logo : :content, previous_filename)
|
||||
entry.update_column(c == Procedure ? :logo_secure_token : :content_secure_token, nil)
|
||||
|
||||
puts "restoring #{content.current_path} db data to #{previous_filename}"
|
||||
|
||||
@cont.delete_object(File.open(File.dirname(content.current_path) + '/filename_cloudstorage', "r").read)
|
||||
|
||||
FileUtils.rm(File.dirname(content.current_path) + '/uploaded')
|
||||
FileUtils.rm(File.dirname(content.current_path) + '/filename_cloudstorage')
|
||||
FileUtils.rm(File.dirname(content.current_path) + '/secure_token_cloudstorage')
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
desc 'Clear old documents in tenant'
|
||||
task :clear do
|
||||
Rake::Task['cloudstorage:init'].invoke
|
||||
|
||||
@cont.objects.each { |object|
|
||||
puts "Removing #{object}"
|
||||
@cont.delete_object(object)
|
||||
}
|
||||
end
|
||||
|
||||
task :clear_old_objects do
|
||||
Rake::Task['cloudstorage:init'].invoke
|
||||
|
||||
@cont.objects_detail.each { |object, details|
|
||||
last_modified = DateTime.parse(details[:last_modified])
|
||||
@cont.delete_object(object) unless last_modified.utc > (Time.now - 2.year).utc
|
||||
}
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue