Skip to content

Commit

Permalink
add google cloud images
Browse files Browse the repository at this point in the history
  • Loading branch information
dereke committed Nov 3, 2019
1 parent fcc5d10 commit 351fd6d
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/secrets

/public/packs
/public/packs-test
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gem 'bcrypt', '~> 3.1.7'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
gem 'devise'
gem 'google-cloud-storage', '~> 1.11', require: false
gem 'image_processing', '~> 1.2'
gem 'komponent', '>= 3.0.0.beta1'
gem 'pg'
Expand Down
49 changes: 49 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,49 @@ GEM
sexp_processor
concurrent-ruby (1.1.5)
crass (1.0.5)
declarative (0.0.10)
declarative-option (0.1.0)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
digest-crc (0.4.1)
erubi (1.9.0)
erubis (2.7.0)
faraday (0.17.0)
multipart-post (>= 1.2, < 3)
ffi (1.11.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-api-client (0.33.2)
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)
signet (~> 0.12)
google-cloud-core (1.4.1)
google-cloud-env (~> 1.0)
google-cloud-env (1.3.0)
faraday (~> 0.11)
google-cloud-storage (1.22.0)
addressable (~> 2.5)
digest-crc (~> 0.4)
google-api-client (~> 0.33)
google-cloud-core (~> 1.2)
googleauth (~> 0.9)
mini_mime (~> 1.0)
googleauth (0.10.0)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.12)
httpclient (2.8.3)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
image_processing (1.9.3)
Expand All @@ -100,6 +132,7 @@ GEM
jbuilder (2.9.1)
activesupport (>= 4.2.0)
json (2.2.0)
jwt (2.2.1)
komponent (3.0.0.beta1)
actionview (>= 5.0)
activesupport (>= 5.0)
Expand All @@ -116,17 +149,21 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
memoist (0.16.0)
method_source (0.9.2)
mimemagic (0.3.3)
mini_magick (4.9.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.12.2)
msgpack (1.3.1)
multi_json (1.14.1)
multipart-post (2.1.1)
nio4r (2.5.1)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
orm_adapter (0.5.0)
os (1.0.1)
parallel (1.17.0)
parser (2.6.4.0)
ast (~> 2.4.0)
Expand Down Expand Up @@ -178,10 +215,15 @@ GEM
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.6.0)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
require_all (2.0.0)
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
retriable (3.1.2)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand All @@ -203,6 +245,11 @@ GEM
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
sexp_processor (4.12.1)
signet (0.12.0)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand All @@ -221,6 +268,7 @@ GEM
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uber (0.1.0)
unicode-display_width (1.6.0)
warden (1.2.8)
rack (>= 2.0.6)
Expand Down Expand Up @@ -254,6 +302,7 @@ DEPENDENCIES
byebug
capybara (>= 2.15)
devise
google-cloud-storage (~> 1.11)
image_processing (~> 1.2)
jbuilder (~> 2.7)
komponent (>= 3.0.0.beta1)
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
config.active_storage.service = :google_dev

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
config.active_storage.service = :google_staging

# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
Expand Down
15 changes: 10 additions & 5 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ local:
# bucket: your_own_bucket

# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
google_staging:
service: GCS
project: your_project
credentials: <%= ENV['GOOGLE_APPLICATION_CREDENTIALS'].as_json %>
bucket: carbon-map-staging

google_dev:
service: GCS
project: carbon-map-dev
credentials: <%= Rails.root.join("config/secrets/google-carbon-map-dev.json") %>
bucket: carbon-map-dev
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
Expand Down
35 changes: 35 additions & 0 deletions lib/tasks/gcs.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

def cors(host)
[
{
"origin": [host],
"responseHeader": ["Content-Type", "Content-Md5"],
"method": ["PUT", "GET", "HEAD", "DELETE"],
"maxAgeSeconds": 3600
}
]
end

def update_cors(host, bucket)
File.write 'tmp/cors.json', cors(host).to_json
`gsutil cors set tmp/cors.json gs://#{bucket}`
end

require 'csv'

namespace :gcs do
desc 'Import taxonomy from csv'
task :dev do
update_cors('*', 'carbon-map-dev')
end

task :staging do
`heroku config:set GOOGLE_APPLICATION_CREDENTIALS="$(< config/secrets/google-carbon-map-staging.json)" -a carbon-map`
update_cors('https://carbon-map.herokuapp.com', 'carbon-map-staging')
end

task :production do
update_cors('https://<inert-url', 'carbon-map')
end
end

0 comments on commit 351fd6d

Please sign in to comment.