Use fog with S3 when S3_BUCKET env var is set

This commit is contained in:
Marcin Kulik 2017-04-18 14:28:58 +02:00
parent 0e7bf6a5dc
commit ddca9db3e1
3 changed files with 21 additions and 11 deletions

View File

@ -7,3 +7,14 @@ SECRET_KEY_BASE=
DATABASE_URL=postgresql://postgres@postgres/postgres DATABASE_URL=postgresql://postgres@postgres/postgres
REDIS_URL=redis://redis:6379 REDIS_URL=redis://redis:6379
### File store
## By default we use local filesystem dir ("uploads" in app root dir).
## If you want to store uploaded recordings in S3 bucket instead,
## uncomment and set the following variables:
# AWS_ACCESS_KEY_ID=
# AWS_SECRET_ACCESS_KEY=
# S3_BUCKET=my-asciinema-bucket
# S3_REGION=us-east-1

View File

@ -4,10 +4,9 @@ module Asciinema
attribute :bugsnag_api_key, String attribute :bugsnag_api_key, String
attribute :aws_access_key_id, String attribute :aws_access_key_id, String
attribute :aws_bucket, String
attribute :aws_region, String
attribute :aws_secret_access_key, String attribute :aws_secret_access_key, String
attribute :carrierwave_storage, String, default: 'file' attribute :s3_bucket, String
attribute :s3_region, String
attribute :carrierwave_storage_dir_prefix, String, default: 'uploads/' attribute :carrierwave_storage_dir_prefix, String, default: 'uploads/'
attribute :google_analytics_id, String attribute :google_analytics_id, String
attribute :home_asciicast_id, Integer attribute :home_asciicast_id, Integer

View File

@ -1,16 +1,16 @@
CarrierWave.configure do |config| CarrierWave.configure do |config|
if CFG.carrierwave_storage == 'fog' if CFG.s3_bucket
config.storage = :fog config.storage = :fog
config.fog_directory = CFG.s3_bucket
config.fog_public = false
config.fog_credentials = { config.fog_credentials = {
:provider => 'AWS', provider: 'AWS',
:aws_access_key_id => CFG.aws_access_key_id, aws_access_key_id: CFG.aws_access_key_id,
:aws_secret_access_key => CFG.aws_secret_access_key, aws_secret_access_key: CFG.aws_secret_access_key,
:region => CFG.aws_region region: CFG.s3_region
} }
config.fog_directory = CFG.aws_bucket else
config.fog_public = false
elsif CFG.carrierwave_storage == 'file'
config.root = Rails.root config.root = Rails.root
end end
end end