aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-31 15:57:37 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-31 15:57:37 -0500
commit90a8e0698db59d2f4ba137ea11c21783d6f9c66a (patch)
treec7e4f0683a3949808bad4daa1e4feafd31bc800c
parent54663f55efd93c5e4f649fd1ad2833a853261507 (diff)
downloadrails-90a8e0698db59d2f4ba137ea11c21783d6f9c66a.tar.gz
rails-90a8e0698db59d2f4ba137ea11c21783d6f9c66a.tar.bz2
rails-90a8e0698db59d2f4ba137ea11c21783d6f9c66a.zip
Use config/storage.yml as part of the skeleton and loading
-rw-r--r--activestorage/README.md2
-rw-r--r--activestorage/config/storage_services.yml34
-rw-r--r--activestorage/lib/active_storage/engine.rb2
-rw-r--r--activestorage/lib/active_storage/service.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb11
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/storage.yml34
-rw-r--r--railties/test/generators/app_generator_test.rb2
9 files changed, 48 insertions, 43 deletions
diff --git a/activestorage/README.md b/activestorage/README.md
index 4a5f03233d..e8ab3b4633 100644
--- a/activestorage/README.md
+++ b/activestorage/README.md
@@ -91,7 +91,7 @@ Variation of image attachment:
2. Add `require "active_storage"` to config/application.rb, after `require "rails/all"` line.
3. Run `rails activestorage:install` to create needed directories, migrations, and configuration.
4. Configure the storage service in `config/environments/*` with `config.active_storage.service = :local`
- that references the services configured in `config/storage_services.yml`.
+ that references the services configured in `config/storage.yml`.
5. Optional: Add `gem "aws-sdk", "~> 2"` to your Gemfile if you want to use AWS S3.
6. Optional: Add `gem "google-cloud-storage", "~> 1.3"` to your Gemfile if you want to use Google Cloud Storage.
7. Optional: Add `gem "mini_magick"` to your Gemfile if you want to use variants.
diff --git a/activestorage/config/storage_services.yml b/activestorage/config/storage_services.yml
deleted file mode 100644
index 057e15e74d..0000000000
--- a/activestorage/config/storage_services.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-test:
- service: Disk
- root: <%= Rails.root.join("tmp/storage") %>
-
-local:
- service: Disk
- root: <%= Rails.root.join("storage") %>
-
-# Use rails secrets:edit to set the AWS secrets (as shared:aws:access_key_id|secret_access_key)
-amazon:
- service: S3
- access_key_id: <%= Rails.application.secrets.dig(:aws, :access_key_id) %>
- secret_access_key: <%= Rails.application.secrets.dig(:aws, :secret_access_key) %>
- region: us-east-1
- bucket: your_own_bucket
-
-# Remember not to checkin your GCS keyfile to a repository
-google:
- service: GCS
- project: your_project
- keyfile: <%= Rails.root.join("path/to/gcs.keyfile") %>
- bucket: your_own_bucket
-
-microsoft:
- service: Azure
- path: your_azure_storage_path
- storage_account_name: your_account_name
- storage_access_key: <%= Rails.application.secrets.azure[:secret_access_key] %>
- container: your_container_name
-
-mirror:
- service: Mirror
- primary: local
- mirrors: [ amazon, google ]
diff --git a/activestorage/lib/active_storage/engine.rb b/activestorage/lib/active_storage/engine.rb
index 71861b84ae..d1f05986ba 100644
--- a/activestorage/lib/active_storage/engine.rb
+++ b/activestorage/lib/active_storage/engine.rb
@@ -31,7 +31,7 @@ module ActiveStorage
initializer "active_storage.services" do
config.after_initialize do |app|
if config_choice = app.config.active_storage.service
- config_file = Pathname.new(Rails.root.join("config/storage_services.yml"))
+ config_file = Pathname.new(Rails.root.join("config/storage.yml"))
raise("Couldn't find Active Storage configuration in #{config_file}") unless config_file.exist?
require "yaml"
diff --git a/activestorage/lib/active_storage/service.rb b/activestorage/lib/active_storage/service.rb
index b648c51823..7559fd0e2b 100644
--- a/activestorage/lib/active_storage/service.rb
+++ b/activestorage/lib/active_storage/service.rb
@@ -10,7 +10,7 @@ require "active_storage/log_subscriber"
# * +Mirror+, to be able to use several services to manage attachments.
#
# Inside a Rails application, you can set-up your services through the
-# generated <tt>config/storage_services.yml</tt> file and reference one
+# generated <tt>config/storage.yml</tt> file and reference one
# of the aforementioned constant under the +service+ key. For example:
#
# local:
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 507099ef57..dc7e243f7b 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -122,9 +122,10 @@ module Rails
def config_when_updating
cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
- action_cable_config_exist = File.exist?("config/cable.yml")
- rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
- assets_config_exist = File.exist?("config/initializers/assets.rb")
+ action_cable_config_exist = File.exist?("config/cable.yml")
+ active_storage_config_exist = File.exist?("config/storage.yml")
+ rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
+ assets_config_exist = File.exist?("config/initializers/assets.rb")
config
@@ -136,6 +137,10 @@ module Rails
template "config/cable.yml"
end
+ if !active_storage_config_exist
+ template "config/storage.yml"
+ end
+
unless rack_cors_config_exist
remove_file "config/initializers/cors.rb"
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 825c4ba061..d69769f631 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -27,7 +27,7 @@ Rails.application.configure do
config.cache_store = :null_store
end
- # Store uploaded files on the local file system (see config/storage_services.yml for options)
+ # Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
<%- unless options.skip_action_mailer? -%>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 24888c082f..5b16ada442 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -45,7 +45,7 @@ Rails.application.configure do
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
- # Store uploaded files on the local file system (see config/storage_services.yml for options)
+ # Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
<%- unless options[:skip_action_cable] -%>
# Mount Action Cable outside main process or domain
diff --git a/railties/lib/rails/generators/rails/app/templates/config/storage.yml b/railties/lib/rails/generators/rails/app/templates/config/storage.yml
new file mode 100644
index 0000000000..90cd00d4a6
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/config/storage.yml
@@ -0,0 +1,34 @@
+test:
+ service: Disk
+ root: <%= Rails.root.join("tmp/storage") %>
+
+local:
+ service: Disk
+ root: <%= Rails.root.join("storage") %>
+
+# Use rails secrets:edit to set the AWS secrets (as shared:aws:access_key_id|secret_access_key)
+# amazon:
+# service: S3
+# access_key_id: <%= Rails.application.secrets.dig(:aws, :access_key_id) %>
+# secret_access_key: <%= Rails.application.secrets.dig(:aws, :secret_access_key) %>
+# region: us-east-1
+# bucket: your_own_bucket
+
+# Remember not to checkin your GCS keyfile to a repository
+# google:
+# service: GCS
+# project: your_project
+# keyfile: <%= Rails.root.join("path/to/gcs.keyfile") %>
+# bucket: your_own_bucket
+
+# microsoft:
+# service: Azure
+# path: your_azure_storage_path
+# storage_account_name: your_account_name
+# storage_access_key: <%= Rails.application.secrets.dig(:azure, :secret_access_key) %>
+# container: your_container_name
+
+# mirror:
+# service: Mirror
+# primary: local
+# mirrors: [ amazon, google, microsoft ]
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 78f4e38bec..fe5d302f3c 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -64,7 +64,7 @@ DEFAULT_APP_FILES = %w(
config/routes.rb
config/secrets.yml
config/spring.rb
- config/storage_services.yml
+ config/storage.yml
db
db/seeds.rb
lib