File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed 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
+
1
13
* Show descriptions for all commands in Rails help
2
14
3
15
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
461
461
# In development and test, this is randomly generated and stored in a
462
462
# temporary file in <tt>tmp/development_secret.txt</tt>.
463
463
#
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
+ #
464
470
# In all other environments, we look for it first in <tt>ENV["SECRET_KEY_BASE"]</tt>,
465
471
# then +credentials.secret_key_base+, and finally +secrets.secret_key_base+. For most applications,
466
472
# the correct place to store it is in the encrypted credentials file.
467
473
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" ]
469
475
secrets . secret_key_base ||= generate_development_secret
470
476
else
471
477
validate_secret_key_base (
Original file line number Diff line number Diff line change @@ -762,6 +762,20 @@ def index
762
762
assert_match ( /Missing `secret_key_base`./ , error . message )
763
763
end
764
764
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
+
765
779
test "raise when secret_key_base is not a type of string" do
766
780
add_to_config <<-RUBY
767
781
Rails.application.credentials.secret_key_base = 123
You can’t perform that action at this time.
0 commit comments