Skip to content

Commit 80ede20

Browse files
ykztshiyuki2578
authored andcommitted
Add config of multipart threshold for S3 (mastodon#11924)
1 parent f58df22 commit 80ede20

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.env.production.sample

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ SMTP_FROM_ADDRESS=notifications@example.com
115115
# S3_ENDPOINT=
116116
# S3_SIGNATURE_VERSION=
117117

118+
# Google Cloud Storage (optional)
119+
# Use S3 compatible API. Since GCS does not support Multipart Upload,
120+
# increase the value of S3_MULTIPART_THRESHOLD to disable Multipart Upload.
121+
# The attachment host must allow cross origin request - see the description
122+
# above.
123+
# S3_ENABLED=true
124+
# AWS_ACCESS_KEY_ID=
125+
# AWS_SECRET_ACCESS_KEY=
126+
# S3_REGION=
127+
# S3_PROTOCOL=https
128+
# S3_HOSTNAME=storage.googleapis.com
129+
# S3_ENDPOINT=https://storage.googleapis.com
130+
# S3_MULTIPART_THRESHOLD=52428801 # 50.megabytes
131+
118132
# Swift (optional)
119133
# The attachment host must allow cross origin request - see the description
120134
# above.

config/initializers/paperclip.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
s3_protocol: s3_protocol,
2626
s3_host_name: s3_hostname,
2727
s3_headers: {
28+
'X-Amz-Multipart-Threshold' => ENV.fetch('S3_MULTIPART_THRESHOLD') { 15.megabytes },
2829
'Cache-Control' => 'public, max-age=315576000, immutable',
2930
},
3031
s3_permissions: ENV.fetch('S3_PERMISSION') { 'public-read' },

lib/tasks/mastodon.rake

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ namespace :mastodon do
135135
prompt.say "\n"
136136

137137
if prompt.yes?('Do you want to store uploaded files on the cloud?', default: false)
138-
case prompt.select('Provider', ['Amazon S3', 'Wasabi', 'Minio'])
138+
case prompt.select('Provider', ['Amazon S3', 'Wasabi', 'Minio', 'Google Cloud Storage'])
139139
when 'Amazon S3'
140140
env['S3_ENABLED'] = 'true'
141141
env['S3_PROTOCOL'] = 'https'
@@ -217,6 +217,34 @@ namespace :mastodon do
217217
q.required true
218218
q.modify :strip
219219
end
220+
when 'Google Cloud Storage'
221+
env['S3_ENABLED'] = 'true'
222+
env['S3_PROTOCOL'] = 'https'
223+
env['S3_HOSTNAME'] = 'storage.googleapis.com'
224+
env['S3_ENDPOINT'] = 'https://storage.googleapis.com'
225+
env['S3_MULTIPART_THRESHOLD'] = 50.megabytes
226+
227+
env['S3_BUCKET'] = prompt.ask('GCS bucket name:') do |q|
228+
q.required true
229+
q.default "files.#{env['LOCAL_DOMAIN']}"
230+
q.modify :strip
231+
end
232+
233+
env['S3_REGION'] = prompt.ask('GCS region:') do |q|
234+
q.required true
235+
q.default 'us-west1'
236+
q.modify :strip
237+
end
238+
239+
env['AWS_ACCESS_KEY_ID'] = prompt.ask('GCS access key:') do |q|
240+
q.required true
241+
q.modify :strip
242+
end
243+
244+
env['AWS_SECRET_ACCESS_KEY'] = prompt.ask('GCS secret key:') do |q|
245+
q.required true
246+
q.modify :strip
247+
end
220248
end
221249

222250
if prompt.yes?('Do you want to access the uploaded files from your own domain?')

0 commit comments

Comments
 (0)