Skip to content

Commit

Permalink
switch image.rb to google storage via fog library (#9807)
Browse files Browse the repository at this point in the history
* switch image.rb to google storage via fog library

* Update app/models/image.rb

* Update app/models/image.rb

* Update app/models/image.rb

* Update image.rb

* Add missing env vars

* Add missing env vars to other environments

* Update paperclip.rb

* Update docker-compose-production.yml

* Update docker-compose-stable.yml

* Update docker-compose-unstable.yml

* install fog-google

* added local fog config and switch

* fixed local storage for dev

* fog_host relative

* revert fog-google to before double-splat bug

* Omit local_root parameter

* Revert "Omit local_root parameter"

This reverts commit 8406611.

* Add JSON key option to Google Cloud Storage config

* fixed display config with style, path

* google_project

* Update Gemfile

* remove XML keys

```
    google_storage_access_key_id: ENV["GOOGLE_STORAGE_KEY"] || '' ,
    google_storage_secret_access_key: ENV["GOOGLE_STORAGE_SECRET"] || ''
```

* Add path adjustment to fog storage provider

Co-authored-by: Sebastian Silva <[email protected]>
  • Loading branch information
jywarren and icarito authored Jul 17, 2021
1 parent 3d3de3f commit 4a891dc
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ gem 'authlogic-oid'
gem "composite_primary_keys"
gem 'figaro' # To easily test OAuth providers in the development mode
gem 'friendly_id'
gem 'fog-google', '1.13.0' # Limited to `v1.13.0` due to https://github.com/fog/fog-google/issues/535
gem 'fog-local', '0.6.0'
gem 'gemoji'
gem 'geocoder'
gem 'georuby', '2.0'
Expand Down
34 changes: 33 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ GEM
dry-logic (~> 1.0, >= 1.0.2)
equalizer (0.0.11)
erubi (1.10.0)
excon (0.83.0)
execjs (2.7.0)
faraday (1.5.0)
faraday-em_http (~> 1.0)
Expand All @@ -155,15 +156,44 @@ GEM
rake
figaro (1.2.0)
thor (>= 0.14.0, < 2)
fog-core (2.1.0)
builder
excon (~> 0.58)
formatador (~> 0.2)
mime-types
fog-google (1.13.0)
fog-core (<= 2.1.0)
fog-json (~> 1.2)
fog-xml (~> 0.1.0)
google-api-client (>= 0.44.2, < 0.51)
google-cloud-env (~> 1.2)
fog-json (1.2.0)
fog-core
multi_json (~> 1.10)
fog-local (0.6.0)
fog-core (>= 1.27, < 3.0)
fog-xml (0.1.3)
fog-core
nokogiri (>= 1.5.11, < 2.0.0)
font-awesome-rails (4.7.0.7)
railties (>= 3.2, < 7)
formatador (0.3.0)
friendly_id (5.4.2)
activerecord (>= 4.0.0)
gemoji (3.0.1)
geocoder (1.6.7)
georuby (2.0.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-api-client (0.50.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.9)
httpclient (>= 2.8.1, < 3.0)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
rexml
signet (~> 0.12)
google-apis-core (0.4.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
Expand Down Expand Up @@ -617,6 +647,8 @@ DEPENDENCIES
critical-path-css-rails (~> 4.1.1)
execjs
figaro
fog-google (= 1.13.0)
fog-local (= 0.6.0)
font-awesome-rails
friendly_id
gemoji
Expand Down Expand Up @@ -714,4 +746,4 @@ RUBY VERSION
ruby 2.6.6p146

BUNDLED WITH
2.2.3
2.2.21
2 changes: 1 addition & 1 deletion app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Image < ApplicationRecord
belongs_to :user, foreign_key: :uid
belongs_to :node, foreign_key: :nid

has_attached_file :photo, styles: { thumb: '200x150>', medium: '500x375>', large: '800x600>' } # ,
has_attached_file :photo, styles: { thumb: '200x150>', medium: '500x375>', large: '800x600>' }

validates :uid, presence: true
validates :photo, presence: true, unless: :remote_url_provided?
Expand Down
10 changes: 10 additions & 0 deletions config/initializers/paperclip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
csv: ['application/octet-stream', 'text/plain']
}
Paperclip::DataUriAdapter.register
Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_directory] = ENV["GOOGLE_STORAGE_BUCKET_NAME"] || ''
Paperclip::Attachment.default_options[:path] = ":rails_root/public/system/public/system/:class/:attachment/:id_partition/:style/:filename"
Paperclip::Attachment.default_options[:fog_credentials] = {
provider: ENV["FOG_PROVIDER"] || "Local",
local_root: "#{Rails.root}/public",
google_project: 'public-lab' ,
google_json_key_location: ENV["GOOGLE_JSON_KEY_FILE"] || ''
}
Paperclip::Attachment.default_options[:fog_host] = ""
5 changes: 5 additions & 0 deletions containers/docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ services:
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
- TWEET_SEARCH=${TWEET_SEARCH}
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
- FOG_PROVIDER=${FOG_PROVIDER}
volumes:
- ..:/app
- /etc/passwd:/etc/passwd:ro
Expand Down
5 changes: 5 additions & 0 deletions containers/docker-compose-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ services:
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
- TWEET_SEARCH=${TWEET_SEARCH}
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
- FOG_PROVIDER=${FOG_PROVIDER}
volumes:
- ..:/app
- /etc/passwd:/etc/passwd:ro
Expand Down
5 changes: 5 additions & 0 deletions containers/docker-compose-unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ services:
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
- TWEET_SEARCH=${TWEET_SEARCH}
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
- FOG_PROVIDER=${FOG_PROVIDER}
volumes:
- ..:/app
- /etc/passwd:/etc/passwd:ro
Expand Down

0 comments on commit 4a891dc

Please sign in to comment.