From 95cb6e93e72d0cd8c7531ec87e78e92e9f8ece39 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 17 Mar 2022 11:20:28 +1100 Subject: [PATCH] Configure Active Storage We are re-using the same config used for Paperclip except for disk storage. Active Storage uses directory sharding on the local disk which means that we can't create blob entries that point to the existing Paperclip files. We will just copy them to the standard `storage/` directory. --- .gitignore | 1 + config/application.rb | 2 ++ config/environments/test.rb | 2 ++ config/storage.yml | 14 ++++++++++++++ 4 files changed, 19 insertions(+) create mode 100644 config/storage.yml diff --git a/.gitignore b/.gitignore index 6ec58bba6a..cba45b438d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ db/*.csv log/*.log log/*.log.lck log/*.log.* +/storage tmp/ .idea/* \#* diff --git a/config/application.rb b/config/application.rb index 05d695c191..7d88b45db8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -238,5 +238,7 @@ module Openfoodnetwork Rails.application.routes.default_url_options[:host] = ENV["SITE_URL"] Rails.autoloaders.main.ignore(Rails.root.join('app/webpacker')) + + config.active_storage.service = ENV["S3_BUCKET"].present? ? :amazon : :local end end diff --git a/config/environments/test.rb b/config/environments/test.rb index f85c7aab9e..71228c5e30 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -51,4 +51,6 @@ Openfoodnetwork::Application.configure do config.active_support.deprecation = :stderr config.active_job.queue_adapter = :test + + config.active_storage.service = :test end diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000000..fbac2cd79c --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,14 @@ +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +amazon: + service: S3 + access_key_id: <%= ENV["S3_ACCESS_KEY"] %> + secret_access_key: <%= ENV["S3_SECRET"] %> + bucket: <%= ENV["S3_BUCKET"] %> + region: <%= ENV.fetch("S3_REGION", "us-east-1") %>