Paperclip: add support for Azure blob storage (#23607)

pull/2339/head
Misty De Méo 2023-07-19 00:02:49 -07:00 committed by GitHub
parent 4c18928a93
commit b848ba3867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 1 deletions

View File

@ -18,6 +18,7 @@ gem 'aws-sdk-s3', '~> 1.123', require: false
gem 'fog-core', '<= 2.4.0'
gem 'fog-openstack', '~> 0.3', require: false
gem 'kt-paperclip', '~> 7.2'
gem 'md-paperclip-azure', '~> 2.2', require: false
gem 'blurhash', '~> 0.1'
gem 'active_model_serializers', '~> 0.10'

View File

@ -118,6 +118,14 @@ GEM
aws-sigv4 (~> 1.6)
aws-sigv4 (1.6.0)
aws-eventstream (~> 1, >= 1.0.2)
azure-storage-blob (2.0.3)
azure-storage-common (~> 2.0)
nokogiri (~> 1, >= 1.10.8)
azure-storage-common (2.0.4)
faraday (~> 1.0)
faraday_middleware (~> 1.0, >= 1.0.0.rc1)
net-http-persistent (~> 4.0)
nokogiri (~> 1, >= 1.10.8)
bcrypt (3.1.18)
better_errors (2.10.1)
erubi (>= 1.0.0)
@ -261,6 +269,8 @@ GEM
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
fast_blank (1.0.1)
fastimage (2.2.7)
ffi (1.15.5)
@ -410,6 +420,10 @@ GEM
mario-redis-lock (1.2.1)
redis (>= 3.0.5)
matrix (0.4.2)
md-paperclip-azure (2.2.0)
addressable (~> 2.5)
azure-storage-blob (~> 2.0.1)
hashie (~> 5.0)
memory_profiler (1.0.1)
method_source (1.0.0)
mime-types (3.4.1)
@ -423,6 +437,8 @@ GEM
multipart-post (2.3.0)
net-http (0.3.2)
uri
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
net-imap (0.3.6)
date
net-protocol
@ -822,6 +838,7 @@ DEPENDENCIES
link_header (~> 0.0)
lograge (~> 0.12)
mario-redis-lock (~> 1.2)
md-paperclip-azure (~> 2.2)
memory_profiler
mime-types (~> 3.4.1)
net-http (~> 0.3.2)

View File

@ -235,6 +235,6 @@ module ApplicationHelper
private
def storage_host_var
ENV.fetch('S3_ALIAS_HOST', nil) || ENV.fetch('S3_CLOUDFRONT_HOST', nil)
ENV.fetch('S3_ALIAS_HOST', nil) || ENV.fetch('S3_CLOUDFRONT_HOST', nil) || ENV.fetch('AZURE_ALIAS_HOST', nil)
end
end

View File

@ -15,6 +15,7 @@ assets_host ||= host_to_url(base_host)
media_host = host_to_url(ENV['S3_ALIAS_HOST'])
media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST'])
media_host ||= host_to_url(ENV['AZURE_ALIAS_HOST'])
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host

View File

@ -131,6 +131,26 @@ elsif ENV['SWIFT_ENABLED'] == 'true'
fog_host: ENV['SWIFT_OBJECT_URL'],
fog_public: true
)
elsif ENV['AZURE_ENABLED'] == 'true'
require 'paperclip-azure'
Paperclip::Attachment.default_options.merge!(
storage: :azure,
azure_options: {
protocol: 'https',
},
azure_credentials: {
storage_account_name: ENV['AZURE_STORAGE_ACCOUNT'],
storage_access_key: ENV['AZURE_STORAGE_ACCESS_KEY'],
container: ENV['AZURE_CONTAINER_NAME'],
}
)
if ENV.has_key?('AZURE_ALIAS_HOST')
Paperclip::Attachment.default_options.merge!(
url: ':azure_alias_url',
azure_host_alias: ENV['AZURE_ALIAS_HOST']
)
end
else
Paperclip::Attachment.default_options.merge!(
storage: :filesystem,