File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * Add ENV[ "SECRET_KEY_BASE_DUMMY"] for starting production environment with a generated secret base key,
2+ which can be used to run tasks like ` assets:precompile ` without making the RAILS_MASTER_KEY available
3+ to the build process.
4+
5+ Dockerfile layer example:
6+
7+ ```
8+ RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
9+ ```
10+
11+ *DHH*
12+
113* Show descriptions for all commands in Rails help
214
315 When calling `rails help` most commands missed their description. We now
Original file line number Diff line number Diff line change @@ -461,11 +461,17 @@ def secrets
461461 # In development and test, this is randomly generated and stored in a
462462 # temporary file in <tt>tmp/development_secret.txt</tt>.
463463 #
464+ # You can also set <tt>ENV["SECRET_KEY_BASE_DUMMY"]</tt> to trigger the use of a randomly generated
465+ # secret_key_base that's stored in a temporary file. This is useful when precompiling assets for
466+ # production as part of a build step that otherwise does not need access to the production secrets.
467+ #
468+ # Dockerfile example: <tt>RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile</tt>.
469+ #
464470 # In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
465471 # then +credentials.secret_key_base+, and finally +secrets.secret_key_base+. For most applications,
466472 # the correct place to store it is in the encrypted credentials file.
467473 def secret_key_base
468- if Rails . env . development? || Rails . env . test?
474+ if Rails . env . development? || Rails . env . test? || ENV [ "SECRET_KEY_BASE_DUMMY" ]
469475 secrets . secret_key_base ||= generate_development_secret
470476 else
471477 validate_secret_key_base (
Original file line number Diff line number Diff line change @@ -762,6 +762,20 @@ def index
762762 assert_match ( /Missing `secret_key_base`./ , error . message )
763763 end
764764
765+ test "dont raise in production when dummy secret_key_base is used" do
766+ ENV [ "SECRET_KEY_BASE_DUMMY" ] = "1"
767+
768+ app_file "config/initializers/secret_token.rb" , <<-RUBY
769+ Rails.application.credentials.secret_key_base = nil
770+ RUBY
771+
772+ assert_nothing_raised do
773+ app "production"
774+ end
775+ ensure
776+ ENV [ "SECRET_KEY_BASE_DUMMY" ] = nil
777+ end
778+
765779 test "raise when secret_key_base is not a type of string" do
766780 add_to_config <<-RUBY
767781 Rails.application.credentials.secret_key_base = 123
You can’t perform that action at this time.
0 commit comments