Skip to content

Commit 5ff9fa5

Browse files
authored
Added rake task that allows cloud storage migration (#6075)
1 parent 6853fa9 commit 5ff9fa5

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

config/environments/development.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
end
5353

5454
# Store uploaded files on the local file system (see config/storage.yml for options).
55-
config.active_storage.service = if ENV['S3_ACCESS_KEY_ID'].present? && ENV['S3_ENDPOINT'].present?
55+
config.active_storage.service = if ENV['AS_MIRROR_PRIMARY'].present?
56+
:mirror
57+
elsif ENV['S3_ACCESS_KEY_ID'].present? && ENV['S3_ENDPOINT'].present?
5658
:s3
5759
elsif ENV['S3_ACCESS_KEY_ID'].present?
5860
:amazon

config/environments/production.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
5656

5757
# Store uploaded files on the local file system (see config/storage.yml for options).
58-
config.active_storage.service = if ENV['S3_ACCESS_KEY_ID'].present? && ENV['S3_ENDPOINT'].present?
58+
config.active_storage.service = if ENV['AS_MIRROR_PRIMARY'].present?
59+
:mirror
60+
elsif ENV['S3_ACCESS_KEY_ID'].present? && ENV['S3_ENDPOINT'].present?
5961
:s3
6062
elsif ENV['S3_ACCESS_KEY_ID'].present?
6163
:amazon

config/storage.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ google:
6262
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
6363
# container: your_container_name-<%= Rails.env %>
6464

65-
# mirror:
66-
# service: Mirror
67-
# primary: local
68-
# mirrors: [ amazon, google, microsoft ]
65+
mirror:
66+
service: Mirror
67+
primary: <%= ENV['AS_MIRROR_PRIMARY'] %>
68+
mirrors: [ <%= ENV['AS_MIRROR_SECONDARY'] %> ]

lib/tasks/attachments.rake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2+
#
3+
# Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below).
4+
#
5+
# This program is free software; you can redistribute it and/or modify it under the
6+
# terms of the GNU Lesser General Public License as published by the Free Software
7+
# Foundation; either version 3.0 of the License, or (at your option) any later
8+
# version.
9+
#
10+
# Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12+
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public License along
15+
# with Greenlight; if not, see <http://www.gnu.org/licenses/>.
16+
17+
# frozen_string_literal: true
18+
19+
require_relative 'task_helpers'
20+
21+
namespace :attachments do
22+
desc 'Checks that the application was configured correctly'
23+
task start: :environment do
24+
ActiveStorage::Blob.update_all(service_name: 'mirror') # rubocop:disable Rails/SkipsModelValidations
25+
ActiveStorage::Blob.find_each(&:mirror_later)
26+
success('Started mirroring process...')
27+
end
28+
29+
task :finish, %i[new_service] => :environment do |_task, args|
30+
ActiveStorage::Blob.update_all(service_name: args[:new_service]) # rubocop:disable Rails/SkipsModelValidations
31+
success('Finished mirroring process...')
32+
end
33+
end

0 commit comments

Comments
 (0)