From d2ba7c115297237e7d37bb2f3ff35032324bc712 Mon Sep 17 00:00:00 2001 From: Kegan Myers Date: Sat, 15 Apr 2017 23:38:55 -0500 Subject: [PATCH] Allow uploading of files to google cloud storage. (dirty, but working) --- Gemfile | 1 + Gemfile.lock | 141 +++++++++++++++++++++++++++++++ config/initializers/ostatus.rb | 2 +- config/initializers/paperclip.rb | 20 +++++ 4 files changed, 163 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2971a7a2..1de9a83d 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,7 @@ gem 'best_in_place', '~> 3.0.1' gem 'paperclip', '~> 5.1' gem 'paperclip-av-transcoder' gem 'aws-sdk', '>= 2.0' +gem 'fog' gem 'addressable' gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index b0ef1c76..7ad54bca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + CFPropertyList (2.3.5) actioncable (5.0.2) actionpack (= 5.0.2) nio4r (>= 1.2, < 3.0) @@ -145,13 +146,142 @@ GEM thread_safe encryptor (3.0.0) erubis (2.7.0) + excon (0.55.0) execjs (2.7.0) fabrication (2.16.1) faker (1.7.3) i18n (~> 0.5) fast_blank (1.0.0) + fission (0.5.0) + CFPropertyList (~> 2.2) + fog (1.38.0) + fog-aliyun (>= 0.1.0) + fog-atmos + fog-aws (>= 0.6.0) + fog-brightbox (~> 0.4) + fog-cloudatcost (~> 0.1.0) + fog-core (~> 1.32) + fog-dynect (~> 0.0.2) + fog-ecloud (~> 0.1) + fog-google (<= 0.1.0) + fog-json + fog-local + fog-openstack + fog-powerdns (>= 0.1.1) + fog-profitbricks + fog-rackspace + fog-radosgw (>= 0.0.2) + fog-riakcs + fog-sakuracloud (>= 0.0.4) + fog-serverlove + fog-softlayer + fog-storm_on_demand + fog-terremark + fog-vmfusion + fog-voxel + fog-vsphere (>= 0.4.0) + fog-xenserver + fog-xml (~> 0.1.1) + ipaddress (~> 0.5) + fog-aliyun (0.1.0) + fog-core (~> 1.27) + fog-json (~> 1.0) + ipaddress (~> 0.8) + xml-simple (~> 1.1) + fog-atmos (0.1.0) + fog-core + fog-xml + fog-aws (1.3.0) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-brightbox (0.11.0) + fog-core (~> 1.22) + fog-json + inflecto (~> 0.0.2) + fog-cloudatcost (0.1.2) + fog-core (~> 1.36) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-core (1.43.0) + builder + excon (~> 0.49) + formatador (~> 0.2) + fog-dynect (0.0.3) + fog-core + fog-json + fog-xml + fog-ecloud (0.3.0) + fog-core + fog-xml + fog-google (0.1.0) + fog-core + fog-json + fog-xml + fog-json (1.0.2) + fog-core (~> 1.0) + multi_json (~> 1.10) + fog-local (0.3.1) + fog-core (~> 1.27) + fog-openstack (0.1.20) + fog-core (>= 1.40) + fog-json (>= 1.0) + ipaddress (>= 0.8) + fog-powerdns (0.1.1) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + fog-profitbricks (3.0.0) + fog-core (~> 1.42) + fog-json (~> 1.0) + fog-rackspace (0.1.4) + fog-core (>= 1.35) + fog-json (>= 1.0) + fog-xml (>= 0.1) + ipaddress (>= 0.8) + fog-radosgw (0.0.5) + fog-core (>= 1.21.0) + fog-json + fog-xml (>= 0.0.1) + fog-riakcs (0.1.0) + fog-core + fog-json + fog-xml + fog-sakuracloud (1.7.5) + fog-core + fog-json + fog-serverlove (0.1.2) + fog-core + fog-json + fog-softlayer (1.1.4) + fog-core + fog-json + fog-storm_on_demand (0.1.1) + fog-core + fog-json + fog-terremark (0.1.0) + fog-core + fog-xml + fog-vmfusion (0.1.0) + fission + fog-core + fog-voxel (0.1.0) + fog-core + fog-xml + fog-vsphere (1.9.1) + fog-core + rbvmomi (~> 1.9) + fog-xenserver (0.3.0) + fog-core + fog-xml + fog-xml (0.1.3) + fog-core + nokogiri (>= 1.5.11, < 2.0.0) font-awesome-rails (4.7.0.1) railties (>= 3.2, < 5.1) + formatador (0.2.5) fuubar (2.2.0) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) @@ -197,6 +327,8 @@ GEM parser (>= 2.2.3.0) rainbow (~> 2.2) terminal-table (>= 1.5.1) + inflecto (0.0.2) + ipaddress (0.8.3) jmespath (1.3.1) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) @@ -243,6 +375,7 @@ GEM mimemagic (0.3.2) mini_portile2 (2.1.0) minitest (5.10.1) + multi_json (1.12.1) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (4.1.0) @@ -332,6 +465,11 @@ GEM thor (>= 0.18.1, < 2.0) rainbow (2.2.1) rake (12.0.0) + rbvmomi (1.11.0) + builder (~> 3.0) + json (>= 1.8) + nokogiri (~> 1.5) + trollop (~> 2.1) react-rails (1.11.0) babel-transpiler (>= 0.7.0) connection_pool @@ -433,6 +571,7 @@ GEM thread (0.2.2) thread_safe (0.3.6) tilt (2.0.7) + trollop (2.1.2) twitter-text (1.14.5) unf (~> 0.1.0) tzinfo (1.2.3) @@ -456,6 +595,7 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) whatlanguage (1.0.6) + xml-simple (1.1.5) xpath (2.0.0) nokogiri (~> 1.3) @@ -485,6 +625,7 @@ DEPENDENCIES fabrication faker fast_blank + fog font-awesome-rails fuubar goldfinger diff --git a/config/initializers/ostatus.rb b/config/initializers/ostatus.rb index 155d0a9f..26b91dc9 100644 --- a/config/initializers/ostatus.rb +++ b/config/initializers/ostatus.rb @@ -9,7 +9,7 @@ Rails.application.configure do config.x.local_domain = host config.x.web_domain = web_host config.x.use_https = https - config.x.use_s3 = ENV['S3_ENABLED'] == 'true' + config.x.use_s3 = ENV['S3_ENABLED'] == 'true' || ENV['GCS_ENABLED'] == 'true' config.action_mailer.default_url_options = { host: web_host, protocol: https ? 'https://' : 'http://', trailing_slash: false } config.x.streaming_api_base_url = 'http://localhost:4000' diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb index 77bc13b3..87c2d892 100644 --- a/config/initializers/paperclip.rb +++ b/config/initializers/paperclip.rb @@ -42,3 +42,23 @@ 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' end + +if ENV['GCS_ENABLED'] == 'true' + Paperclip::Attachment.default_options.update({ + :path => "images/:class/:id/:attachment/:style/img_:fingerprint", + :storage => :fog, + :fog_credentials => { + :provider => 'Google', + :google_storage_access_key_id => ENV.fetch('GCS_ACCESS_KEY_ID'), + :google_storage_secret_access_key => ENV.fetch('GCS_SECRET_ACCESS_KEY'), + :path_style => !ENV['GCS_ALIAS_HOST'].blank? + }, + :fog_directory => ENV.fetch('GCS_BUCKET'), + :fog_public => true, + :fog_host => 'https://' + ENV.fetch('GCS_BUCKET'), + }) + + unless ENV['GCS_ALIAS_HOST'].blank? + Paperclip::Attachment.default_options[:url] = ENV['GCS_ALIAS_HOST'] + end +end