Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Paperclip config for OpenStack Swift #2322

Merged
merged 1 commit into from Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -15,6 +15,7 @@ gem 'pghero', '~> 1.7'
gem 'dotenv-rails', '~> 2.2'

gem 'aws-sdk', '~> 2.9'
gem 'fog-openstack', '~> 0.1'
gem 'paperclip', '~> 5.1'
gem 'paperclip-av-transcoder', '~> 0.6'

Expand Down
15 changes: 15 additions & 0 deletions Gemfile.lock
Expand Up @@ -154,12 +154,25 @@ GEM
erubis (2.7.0)
et-orbi (1.0.5)
tzinfo
excon (0.58.0)
execjs (2.7.0)
fabrication (2.16.2)
faker (1.7.3)
i18n (~> 0.5)
fast_blank (1.0.0)
ffi (1.9.18)
fog-core (1.45.0)
builder
excon (~> 0.58)
formatador (~> 0.2)
fog-json (1.0.2)
fog-core (~> 1.0)
multi_json (~> 1.10)
fog-openstack (0.1.21)
fog-core (>= 1.40)
fog-json (>= 1.0)
ipaddress (>= 0.8)
formatador (0.2.5)
fuubar (2.2.0)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
Expand Down Expand Up @@ -211,6 +224,7 @@ GEM
rainbow (~> 2.2)
terminal-table (>= 1.5.1)
idn-ruby (0.1.0)
ipaddress (0.8.3)
jmespath (1.3.1)
json (2.1.0)
json-ld (2.1.5)
Expand Down Expand Up @@ -535,6 +549,7 @@ DEPENDENCIES
fabrication (~> 2.16)
faker (~> 1.7)
fast_blank (~> 1.0)
fog-openstack (~> 0.1)
fuubar (~> 2.2)
goldfinger (~> 2.0)
hamlit-rails (~> 0.2)
Expand Down
8 changes: 7 additions & 1 deletion app/helpers/routing_helper.rb
Expand Up @@ -12,8 +12,14 @@ def default_url_options
end

def full_asset_url(source, options = {})
source = ActionController::Base.helpers.asset_url(source, options) unless Rails.configuration.x.use_s3
source = ActionController::Base.helpers.asset_url(source, options) unless use_storage?

URI.join(root_url, source).to_s
end

private

def use_storage?
Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
end
end
1 change: 1 addition & 0 deletions config/initializers/ostatus.rb
Expand Up @@ -12,6 +12,7 @@
config.x.web_domain = web_host
config.x.use_https = https
config.x.use_s3 = ENV['S3_ENABLED'] == 'true'
config.x.use_swift = ENV['SWIFT_ENABLED'] == 'true'

config.x.alternate_domains = alternate_domains.split(/\s*,\s*/)

Expand Down
15 changes: 15 additions & 0 deletions config/initializers/paperclip.rb
Expand Up @@ -40,6 +40,21 @@
Paperclip::Attachment.default_options[:url] = ':s3_alias_url'
Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
end
elsif ENV['SWIFT_ENABLED'] == 'true'
Paperclip::Attachment.default_options.merge!(
path: ':class/:attachment/:id_partition/:style/:filename',
storage: :fog,
fog_credentials: {
provider: 'OpenStack',
openstack_username: ENV.fetch('SWIFT_USERNAME'),
openstack_tenant: ENV.fetch('SWIFT_TENANT'),
openstack_api_key: ENV.fetch('SWIFT_PASSWORD'),
openstack_auth_url: ENV.fetch('SWIFT_AUTH_URL'),
},
fog_directory: ENV.fetch('SWIFT_CONTAINER'),
fog_host: ENV.fetch('SWIFT_OBJECT_URL'),
fog_public: true
)
else
Paperclip::Attachment.default_options[:path] = (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:url] = (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename'
Expand Down