Skip to content

Commit e5c7311

Browse files
committed
Allow customization of ActiveStorage storage
In the production environment, an alternative S3-compatible storage provider can be configured. Related to #2104
1 parent a7e80e5 commit e5c7311

File tree

8 files changed

+51
-37
lines changed

8 files changed

+51
-37
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
run: |
6565
cp config/action_mailer.yml.ci config/action_mailer.yml
6666
cp config/content_security_policy.yml.ci config/content_security_policy.yml
67+
cp config/storage.yml.ci config/storage.yml
6768
cp config/database.yml.ci config/database.yml
6869
cp config/mnemosyne.yml.ci config/mnemosyne.yml
6970

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
/config/mnemosyne.yml
4444
/config/settings.local.yml
4545
/config/settings/*.local.yml
46+
/config/storage.yml
4647
/config/environments/*.local.yml
4748

4849
# Ignore temporary files

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source 'https://rubygems.org'
44

55
gem 'acts-as-taggable-on'
6+
gem 'aws-sdk-s3', require: false
67
gem 'bcrypt'
78
gem 'bootsnap', require: false
89
gem 'bootstrap-will_paginate'

Gemfile.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ GEM
8383
public_suffix (>= 2.0.2, < 7.0)
8484
amq-protocol (2.3.4)
8585
ast (2.4.3)
86+
aws-eventstream (1.4.0)
87+
aws-partitions (1.1147.0)
88+
aws-sdk-core (3.229.0)
89+
aws-eventstream (~> 1, >= 1.3.0)
90+
aws-partitions (~> 1, >= 1.992.0)
91+
aws-sigv4 (~> 1.9)
92+
base64
93+
bigdecimal
94+
jmespath (~> 1, >= 1.6.1)
95+
logger
96+
aws-sdk-kms (1.110.0)
97+
aws-sdk-core (~> 3, >= 3.228.0)
98+
aws-sigv4 (~> 1.5)
99+
aws-sdk-s3 (1.196.1)
100+
aws-sdk-core (~> 3, >= 3.228.0)
101+
aws-sdk-kms (~> 1)
102+
aws-sigv4 (~> 1.5)
103+
aws-sigv4 (1.12.1)
104+
aws-eventstream (~> 1, >= 1.0.2)
86105
base64 (0.3.0)
87106
bcrypt (3.1.20)
88107
benchmark (0.4.1)
@@ -222,6 +241,7 @@ GEM
222241
jbuilder (2.14.1)
223242
actionview (>= 7.0.0)
224243
activesupport (>= 7.0.0)
244+
jmespath (1.6.2)
225245
jquery-rails (4.6.0)
226246
rails-dom-testing (>= 1, < 3)
227247
railties (>= 4.2.0)
@@ -647,7 +667,6 @@ PLATFORMS
647667
arm-linux-gnu
648668
arm-linux-musl
649669
arm64-darwin
650-
ruby
651670
x86-linux-gnu
652671
x86-linux-musl
653672
x86_64-darwin
@@ -656,6 +675,7 @@ PLATFORMS
656675

657676
DEPENDENCIES
658677
acts-as-taggable-on
678+
aws-sdk-s3
659679
bcrypt
660680
better_errors
661681
binding_of_caller
@@ -754,6 +774,12 @@ CHECKSUMS
754774
addressable (2.8.7) sha256=462986537cf3735ab5f3c0f557f14155d778f4b43ea4f485a9deb9c8f7c58232
755775
amq-protocol (2.3.4) sha256=98be5b9244e28dc66acc8351a254dbf45d996c5a0b7d49ab3ff8b72b0d2e6308
756776
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
777+
aws-eventstream (1.4.0)
778+
aws-partitions (1.1147.0)
779+
aws-sdk-core (3.229.0)
780+
aws-sdk-kms (1.110.0)
781+
aws-sdk-s3 (1.196.1)
782+
aws-sigv4 (1.12.1)
757783
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
758784
bcrypt (3.1.20) sha256=8410f8c7b3ed54a3c00cd2456bf13917d695117f033218e2483b2e40b0784099
759785
benchmark (0.4.1) sha256=d4ef40037bba27f03b28013e219b950b82bace296549ec15a78016552f8d2cce
@@ -825,6 +851,7 @@ CHECKSUMS
825851
irb (1.15.2) sha256=222f32952e278da34b58ffe45e8634bf4afc2dc7aa9da23fed67e581aa50fdba
826852
iso-639 (0.3.8) sha256=48b8104a4b55367fda347609e36ef8eeb3a0b4d048b36365371c274958be7535
827853
jbuilder (2.14.1) sha256=4eb26376ff60ef100cb4fd6fd7533cd271f9998327e86adf20fd8c0e69fabb42
854+
jmespath (1.6.2)
828855
jquery-rails (4.6.0) sha256=3c4e6bf47274340b44d836b8aa1b5472c6d451e2739af5ec094421f39025a7e2
829856
js-routes (2.3.5) sha256=8279fd3be49916309dfeaee546d659b97986e3edbb47332902e688992b143a4d
830857
json (2.13.2) sha256=02e1f118d434c6b230a64ffa5c8dee07e3ec96244335c392eaed39e1199dbb68

config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
5050
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
5151

52-
# Store uploaded files on the local file system (see config/storage.yml for options).
53-
config.active_storage.service = :local
52+
# Store uploaded files on the local file system by default (see config/storage.yml for options).
53+
config.active_storage.service = ENV.fetch('ACTIVE_STORAGE_SERVICE', :local)
5454

5555
# Mount Action Cable outside main process or domain.
5656
# config.action_cable.mount_path = nil

config/storage.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

config/storage.yml.ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test:
2+
service: Disk
3+
root: <%= Rails.root.join("tmp/storage") %>

config/storage.yml.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test:
2+
service: Disk
3+
root: <%= Rails.root.join("tmp/storage") %>
4+
5+
local:
6+
service: Disk
7+
root: <%= Rails.root.join("storage") %>
8+
9+
# Local storage is used by default. To use another storage provider in production,
10+
# please set ACTIVE_STORAGE_SERVICE=aws and the corresponding configuration.
11+
# The aws-sdk-s3 GEM is included to support S3-compatible providers.
12+
#
13+
# aws:
14+
# service: S3
15+
# ...

0 commit comments

Comments
 (0)