Skip to content

Commit 5161a43

Browse files
jywarrenicarito
authored andcommitted
switch image.rb to google storage via fog library (publiclab#9807)
* 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]>
1 parent 76f387d commit 5161a43

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ gem 'authlogic-oid'
1212
gem "composite_primary_keys"
1313
gem 'figaro' # To easily test OAuth providers in the development mode
1414
gem 'friendly_id'
15+
gem 'fog-google', '1.13.0' # Limited to `v1.13.0` due to https://github.com/fog/fog-google/issues/535
16+
gem 'fog-local', '0.6.0'
1517
gem 'gemoji'
1618
gem 'geocoder'
1719
gem 'georuby', '2.0'

Gemfile.lock

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ GEM
131131
dry-logic (~> 1.0, >= 1.0.2)
132132
equalizer (0.0.11)
133133
erubi (1.10.0)
134+
excon (0.83.0)
134135
execjs (2.7.0)
135136
faraday (1.5.0)
136137
faraday-em_http (~> 1.0)
@@ -155,15 +156,44 @@ GEM
155156
rake
156157
figaro (1.2.0)
157158
thor (>= 0.14.0, < 2)
159+
fog-core (2.1.0)
160+
builder
161+
excon (~> 0.58)
162+
formatador (~> 0.2)
163+
mime-types
164+
fog-google (1.13.0)
165+
fog-core (<= 2.1.0)
166+
fog-json (~> 1.2)
167+
fog-xml (~> 0.1.0)
168+
google-api-client (>= 0.44.2, < 0.51)
169+
google-cloud-env (~> 1.2)
170+
fog-json (1.2.0)
171+
fog-core
172+
multi_json (~> 1.10)
173+
fog-local (0.6.0)
174+
fog-core (>= 1.27, < 3.0)
175+
fog-xml (0.1.3)
176+
fog-core
177+
nokogiri (>= 1.5.11, < 2.0.0)
158178
font-awesome-rails (4.7.0.7)
159179
railties (>= 3.2, < 7)
180+
formatador (0.3.0)
160181
friendly_id (5.4.2)
161182
activerecord (>= 4.0.0)
162183
gemoji (3.0.1)
163184
geocoder (1.6.7)
164185
georuby (2.0.0)
165186
globalid (0.4.2)
166187
activesupport (>= 4.2.0)
188+
google-api-client (0.50.0)
189+
addressable (~> 2.5, >= 2.5.1)
190+
googleauth (~> 0.9)
191+
httpclient (>= 2.8.1, < 3.0)
192+
mini_mime (~> 1.0)
193+
representable (~> 3.0)
194+
retriable (>= 2.0, < 4.0)
195+
rexml
196+
signet (~> 0.12)
167197
google-apis-core (0.4.0)
168198
addressable (~> 2.5, >= 2.5.1)
169199
googleauth (>= 0.16.2, < 2.a)
@@ -617,6 +647,8 @@ DEPENDENCIES
617647
critical-path-css-rails (~> 4.1.1)
618648
execjs
619649
figaro
650+
fog-google (= 1.13.0)
651+
fog-local (= 0.6.0)
620652
font-awesome-rails
621653
friendly_id
622654
gemoji
@@ -714,4 +746,4 @@ RUBY VERSION
714746
ruby 2.6.6p146
715747

716748
BUNDLED WITH
717-
2.2.3
749+
2.2.21

app/models/image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Image < ApplicationRecord
44
belongs_to :user, foreign_key: :uid
55
belongs_to :node, foreign_key: :nid
66

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

99
validates :uid, presence: true
1010
validates :photo, presence: true, unless: :remote_url_provided?

config/initializers/paperclip.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@
88
csv: ['application/octet-stream', 'text/plain']
99
}
1010
Paperclip::DataUriAdapter.register
11+
Paperclip::Attachment.default_options[:storage] = :fog
12+
Paperclip::Attachment.default_options[:fog_directory] = ENV["GOOGLE_STORAGE_BUCKET_NAME"] || ''
13+
Paperclip::Attachment.default_options[:path] = ":rails_root/public/system/public/system/:class/:attachment/:id_partition/:style/:filename"
14+
Paperclip::Attachment.default_options[:fog_credentials] = {
15+
provider: ENV["FOG_PROVIDER"] || "Local",
16+
local_root: "#{Rails.root}/public",
17+
google_project: 'public-lab' ,
18+
google_json_key_location: ENV["GOOGLE_JSON_KEY_FILE"] || ''
19+
}
20+
Paperclip::Attachment.default_options[:fog_host] = ""

containers/docker-compose-production.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ services:
5454
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
5555
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
5656
- TWEET_SEARCH=${TWEET_SEARCH}
57+
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
58+
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
59+
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
60+
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
61+
- FOG_PROVIDER=${FOG_PROVIDER}
5762
volumes:
5863
- ..:/app
5964
- /etc/passwd:/etc/passwd:ro

containers/docker-compose-stable.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ services:
5353
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
5454
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
5555
- TWEET_SEARCH=${TWEET_SEARCH}
56+
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
57+
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
58+
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
59+
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
60+
- FOG_PROVIDER=${FOG_PROVIDER}
5661
volumes:
5762
- ..:/app
5863
- /etc/passwd:/etc/passwd:ro

containers/docker-compose-unstable.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ services:
5353
- TWITTER_ACCESS_TOKEN_SECRET=${TWITTER_ACCESS_TOKEN_SECRET}
5454
- WEBSITE_HOST_PATTERN=${WEBSITE_HOST_PATTERN}
5555
- TWEET_SEARCH=${TWEET_SEARCH}
56+
- GOOGLE_STORAGE_SECRET=${GOOGLE_STORAGE_SECRET}
57+
- GOOGLE_JSON_KEY_FILE=${GOOGLE_JSON_KEY_FILE}
58+
- GOOGLE_STORAGE_KEY=${GOOGLE_STORAGE_KEY}
59+
- GOOGLE_STORAGE_BUCKET_NAME=${GOOGLE_STORAGE_BUCKET_NAME}
60+
- FOG_PROVIDER=${FOG_PROVIDER}
5661
volumes:
5762
- ..:/app
5863
- /etc/passwd:/etc/passwd:ro

0 commit comments

Comments
 (0)