railties 7.1.3.4 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +128 -775
  3. data/lib/minitest/rails_plugin.rb +6 -3
  4. data/lib/rails/all.rb +1 -3
  5. data/lib/rails/api/task.rb +6 -4
  6. data/lib/rails/application/bootstrap.rb +5 -7
  7. data/lib/rails/application/configuration.rb +81 -43
  8. data/lib/rails/application/default_middleware_stack.rb +4 -0
  9. data/lib/rails/application/dummy_config.rb +2 -2
  10. data/lib/rails/application/finisher.rb +9 -3
  11. data/lib/rails/application/routes_reloader.rb +16 -2
  12. data/lib/rails/application.rb +27 -86
  13. data/lib/rails/backtrace_cleaner.rb +19 -4
  14. data/lib/rails/cli.rb +0 -1
  15. data/lib/rails/code_statistics.rb +128 -86
  16. data/lib/rails/code_statistics_calculator.rb +78 -76
  17. data/lib/rails/command/helpers/editor.rb +1 -1
  18. data/lib/rails/command.rb +0 -6
  19. data/lib/rails/commands/app/update_command.rb +94 -0
  20. data/lib/rails/commands/boot/boot_command.rb +14 -0
  21. data/lib/rails/commands/console/console_command.rb +2 -21
  22. data/lib/rails/commands/console/irb_console.rb +128 -0
  23. data/lib/rails/commands/credentials/USAGE +4 -4
  24. data/lib/rails/commands/credentials/credentials_command.rb +7 -3
  25. data/lib/rails/commands/dbconsole/dbconsole_command.rb +21 -30
  26. data/lib/rails/commands/dev/dev_command.rb +1 -1
  27. data/lib/rails/commands/devcontainer/devcontainer_command.rb +40 -0
  28. data/lib/rails/commands/rake/rake_command.rb +1 -1
  29. data/lib/rails/commands/runner/runner_command.rb +14 -3
  30. data/lib/rails/commands/server/server_command.rb +5 -3
  31. data/lib/rails/commands/stats/stats_command.rb +19 -0
  32. data/lib/rails/commands/test/test_command.rb +2 -0
  33. data/lib/rails/configuration.rb +10 -1
  34. data/lib/rails/console/methods.rb +7 -0
  35. data/lib/rails/dev_caching.rb +2 -2
  36. data/lib/rails/engine/configuration.rb +3 -1
  37. data/lib/rails/engine/lazy_route_set.rb +114 -0
  38. data/lib/rails/engine.rb +16 -12
  39. data/lib/rails/gem_version.rb +4 -4
  40. data/lib/rails/generators/actions.rb +3 -3
  41. data/lib/rails/generators/app_base.rb +115 -68
  42. data/lib/rails/generators/base.rb +1 -1
  43. data/lib/rails/generators/database.rb +263 -71
  44. data/lib/rails/generators/erb/authentication/authentication_generator.rb +15 -0
  45. data/lib/rails/generators/erb/authentication/templates/app/views/passwords/edit.html.erb +9 -0
  46. data/lib/rails/generators/erb/authentication/templates/app/views/passwords/new.html.erb +8 -0
  47. data/lib/rails/generators/erb/authentication/templates/app/views/sessions/new.html.erb +11 -0
  48. data/lib/rails/generators/erb/scaffold/templates/edit.html.erb.tt +2 -0
  49. data/lib/rails/generators/erb/scaffold/templates/index.html.erb.tt +2 -0
  50. data/lib/rails/generators/erb/scaffold/templates/new.html.erb.tt +2 -0
  51. data/lib/rails/generators/generated_attribute.rb +42 -12
  52. data/lib/rails/generators/migration.rb +3 -3
  53. data/lib/rails/generators/rails/app/app_generator.rb +75 -54
  54. data/lib/rails/generators/rails/app/templates/Dockerfile.tt +33 -17
  55. data/lib/rails/generators/rails/app/templates/Gemfile.tt +38 -23
  56. data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css.tt +6 -11
  57. data/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +4 -0
  58. data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +17 -3
  59. data/lib/rails/generators/rails/app/templates/app/views/pwa/manifest.json.erb.tt +22 -0
  60. data/lib/rails/generators/rails/app/templates/app/views/pwa/service-worker.js +26 -0
  61. data/lib/rails/generators/rails/app/templates/bin/brakeman.tt +6 -0
  62. data/lib/rails/generators/rails/app/templates/bin/dev.tt +1 -0
  63. data/lib/rails/generators/rails/app/templates/bin/rubocop.tt +7 -0
  64. data/lib/rails/generators/rails/app/templates/bin/setup.tt +6 -5
  65. data/lib/rails/generators/rails/app/templates/bin/thrust.tt +4 -0
  66. data/lib/rails/generators/rails/app/templates/config/application.rb.tt +1 -1
  67. data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml.tt +26 -3
  68. data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml.tt +30 -0
  69. data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml.tt +47 -0
  70. data/lib/rails/generators/rails/app/templates/config/databases/trilogy.yml.tt +26 -3
  71. data/lib/rails/generators/rails/app/templates/config/deploy.yml.tt +128 -0
  72. data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +22 -26
  73. data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +36 -48
  74. data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +7 -18
  75. data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +0 -7
  76. data/lib/rails/generators/rails/app/templates/config/initializers/filter_parameter_logging.rb.tt +1 -1
  77. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_8_0.rb.tt +30 -0
  78. data/lib/rails/generators/rails/app/templates/config/puma.rb.tt +35 -27
  79. data/lib/rails/generators/rails/app/templates/config/routes.rb.tt +6 -0
  80. data/lib/rails/generators/rails/app/templates/docker-entrypoint.tt +7 -1
  81. data/lib/rails/generators/rails/app/templates/dockerignore.tt +20 -2
  82. data/lib/rails/generators/rails/app/templates/github/ci.yml.tt +144 -0
  83. data/lib/rails/generators/rails/app/templates/github/dependabot.yml +12 -0
  84. data/lib/rails/generators/rails/app/templates/gitignore.tt +4 -5
  85. data/lib/rails/generators/rails/app/templates/kamal-secrets.tt +17 -0
  86. data/lib/rails/generators/rails/app/templates/public/400.html +114 -0
  87. data/lib/rails/generators/rails/app/templates/public/404.html +113 -66
  88. data/lib/rails/generators/rails/app/templates/public/406-unsupported-browser.html +114 -0
  89. data/lib/rails/generators/rails/app/templates/public/422.html +113 -66
  90. data/lib/rails/generators/rails/app/templates/public/500.html +113 -65
  91. data/lib/rails/generators/rails/app/templates/public/icon.png +0 -0
  92. data/lib/rails/generators/rails/app/templates/public/icon.svg +3 -0
  93. data/lib/rails/generators/rails/app/templates/rubocop.yml.tt +8 -0
  94. data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb.tt +1 -1
  95. data/lib/rails/generators/rails/authentication/USAGE +6 -0
  96. data/lib/rails/generators/rails/authentication/authentication_generator.rb +58 -0
  97. data/lib/rails/generators/rails/authentication/templates/app/channels/application_cable/connection.rb.tt +16 -0
  98. data/lib/rails/generators/rails/authentication/templates/app/controllers/concerns/authentication.rb.tt +52 -0
  99. data/lib/rails/generators/rails/authentication/templates/app/controllers/passwords_controller.rb.tt +33 -0
  100. data/lib/rails/generators/rails/authentication/templates/app/controllers/sessions_controller.rb.tt +21 -0
  101. data/lib/rails/generators/rails/authentication/templates/app/mailers/passwords_mailer.rb.tt +6 -0
  102. data/lib/rails/generators/rails/authentication/templates/app/models/current.rb.tt +4 -0
  103. data/lib/rails/generators/rails/authentication/templates/app/models/session.rb.tt +3 -0
  104. data/lib/rails/generators/rails/authentication/templates/app/models/user.rb.tt +6 -0
  105. data/lib/rails/generators/rails/authentication/templates/app/views/passwords_mailer/reset.html.erb.tt +4 -0
  106. data/lib/rails/generators/rails/authentication/templates/app/views/passwords_mailer/reset.text.erb.tt +2 -0
  107. data/lib/rails/generators/rails/authentication/templates/test/mailers/previews/passwords_mailer_preview.rb.tt +7 -0
  108. data/lib/rails/generators/rails/controller/controller_generator.rb +1 -1
  109. data/lib/rails/generators/rails/credentials/templates/credentials.yml.tt +4 -0
  110. data/lib/rails/generators/rails/db/system/change/change_generator.rb +132 -21
  111. data/lib/rails/generators/rails/devcontainer/devcontainer_generator.rb +176 -0
  112. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/Dockerfile.tt +3 -0
  113. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/compose.yaml.tt +47 -0
  114. data/lib/rails/generators/rails/devcontainer/templates/devcontainer/devcontainer.json.tt +37 -0
  115. data/lib/rails/generators/rails/migration/migration_generator.rb +4 -0
  116. data/lib/rails/generators/rails/plugin/plugin_generator.rb +47 -16
  117. data/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +2 -2
  118. data/lib/rails/generators/rails/plugin/templates/Gemfile.tt +6 -2
  119. data/lib/rails/generators/rails/plugin/templates/app/views/layouts/%namespaced_name%/application.html.erb.tt +2 -0
  120. data/lib/rails/generators/rails/plugin/templates/bin/rubocop.tt +7 -0
  121. data/lib/rails/generators/rails/plugin/templates/github/ci.yml.tt +103 -0
  122. data/lib/rails/generators/rails/plugin/templates/github/dependabot.yml +12 -0
  123. data/lib/rails/generators/rails/plugin/templates/rubocop.yml.tt +8 -0
  124. data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb.tt +1 -1
  125. data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb.tt +2 -2
  126. data/lib/rails/generators/rails/scaffold_controller/templates/api_controller.rb.tt +2 -2
  127. data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +3 -3
  128. data/lib/rails/generators/rails/script/USAGE +18 -0
  129. data/lib/rails/generators/rails/script/script_generator.rb +18 -0
  130. data/lib/rails/generators/rails/script/templates/script.rb.tt +3 -0
  131. data/lib/rails/generators/test_unit/authentication/authentication_generator.rb +14 -0
  132. data/lib/rails/generators/test_unit/authentication/templates/test/fixtures/users.yml.tt +9 -0
  133. data/lib/rails/generators/test_unit/authentication/templates/test/models/user_test.rb.tt +7 -0
  134. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb.tt +6 -4
  135. data/lib/rails/generators/test_unit/mailer/templates/preview.rb.tt +3 -2
  136. data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +15 -1
  137. data/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb.tt +2 -2
  138. data/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb.tt +2 -2
  139. data/lib/rails/generators/test_unit/scaffold/templates/system_test.rb.tt +2 -0
  140. data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb.tt +1 -1
  141. data/lib/rails/generators/testing/assertions.rb +20 -0
  142. data/lib/rails/generators/testing/behavior.rb +7 -6
  143. data/lib/rails/generators.rb +7 -2
  144. data/lib/rails/health_controller.rb +1 -1
  145. data/lib/rails/info.rb +2 -2
  146. data/lib/rails/info_controller.rb +10 -2
  147. data/lib/rails/mailers_controller.rb +14 -1
  148. data/lib/rails/paths.rb +2 -2
  149. data/lib/rails/pwa_controller.rb +15 -0
  150. data/lib/rails/rack/logger.rb +15 -7
  151. data/lib/rails/rack/silence_request.rb +33 -0
  152. data/lib/rails/rack.rb +1 -0
  153. data/lib/rails/railtie/configurable.rb +2 -2
  154. data/lib/rails/railtie.rb +15 -16
  155. data/lib/rails/source_annotation_extractor.rb +31 -14
  156. data/lib/rails/tasks/framework.rake +0 -26
  157. data/lib/rails/tasks/statistics.rake +13 -28
  158. data/lib/rails/tasks/tmp.rake +1 -1
  159. data/lib/rails/templates/layouts/application.html.erb +1 -1
  160. data/lib/rails/templates/rails/info/notes.html.erb +65 -0
  161. data/lib/rails/templates/rails/mailers/email.html.erb +12 -8
  162. data/lib/rails/templates/rails/welcome/index.html.erb +4 -2
  163. data/lib/rails/test_help.rb +2 -4
  164. data/lib/rails/test_unit/reporter.rb +8 -2
  165. data/lib/rails/test_unit/runner.rb +27 -2
  166. data/lib/rails/test_unit/test_parser.rb +48 -0
  167. data/lib/rails.rb +7 -4
  168. metadata +77 -45
  169. data/lib/rails/app_updater.rb +0 -40
  170. data/lib/rails/commands/secrets/USAGE +0 -61
  171. data/lib/rails/commands/secrets/secrets_command.rb +0 -47
  172. data/lib/rails/console/app.rb +0 -35
  173. data/lib/rails/console/helpers.rb +0 -19
  174. data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
  175. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/channel.rb.tt +0 -4
  176. data/lib/rails/generators/rails/app/templates/app/channels/application_cable/connection.rb.tt +0 -4
  177. data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml.tt +0 -68
  178. data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml.tt +0 -54
  179. data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml.tt +0 -70
  180. data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml.tt +0 -24
  181. data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml.tt +0 -62
  182. data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml.tt +0 -53
  183. data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_1.rb.tt +0 -284
  184. data/lib/rails/generators/rails/app/templates/config/initializers/permissions_policy.rb.tt +0 -13
  185. data/lib/rails/generators/rails/app/templates/public/apple-touch-icon-precomposed.png +0 -0
  186. data/lib/rails/generators/rails/app/templates/public/apple-touch-icon.png +0 -0
  187. data/lib/rails/generators/rails/app/templates/public/favicon.ico +0 -0
  188. data/lib/rails/generators/rails/app/templates/test/channels/application_cable/connection_test.rb.tt +0 -13
  189. data/lib/rails/generators/rails/plugin/templates/rails/dummy_manifest.js.tt +0 -10
  190. data/lib/rails/generators/rails/plugin/templates/rails/engine_manifest.js.tt +0 -6
  191. data/lib/rails/generators/rails/plugin/templates/rails/javascripts.js.tt +0 -17
  192. data/lib/rails/ruby_version_check.rb +0 -17
  193. data/lib/rails/secrets.rb +0 -110
@@ -1,6 +1,5 @@
1
1
  require "fileutils"
2
2
 
3
- # path to your application root.
4
3
  APP_ROOT = File.expand_path("..", __dir__)
5
4
 
6
5
  def system!(*args)
@@ -13,12 +12,11 @@ FileUtils.chdir APP_ROOT do
13
12
  # Add necessary setup steps to this file.
14
13
 
15
14
  puts "== Installing dependencies =="
16
- system! "gem install bundler --conservative"
17
15
  system("bundle check") || system!("bundle install")
18
16
  <% if using_node? -%>
19
17
 
20
18
  # Install JavaScript dependencies
21
- system("yarn check --check-files") || system!("yarn install")
19
+ system("yarn install --check-files")
22
20
  <% elsif using_bun? -%>
23
21
 
24
22
  # Install JavaScript dependencies
@@ -38,6 +36,9 @@ FileUtils.chdir APP_ROOT do
38
36
  puts "\n== Removing old logs and tempfiles =="
39
37
  system! "bin/rails log:clear tmp:clear"
40
38
 
41
- puts "\n== Restarting application server =="
42
- system! "bin/rails restart"
39
+ unless ARGV.include?("--skip-server")
40
+ puts "\n== Starting development server =="
41
+ STDOUT.flush # flush the output before exec(2) so that it displays
42
+ exec "bin/dev"
43
+ end
43
44
  end
@@ -0,0 +1,4 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ load Gem.bin_path("thruster", "thrust")
@@ -18,7 +18,7 @@ module <%= app_const_base %>
18
18
  # Please, add to the `ignore` list any other `lib` subdirectories that do
19
19
  # not contain `.rb` files, or that should not be reloaded or eager loaded.
20
20
  # Common ones are `templates`, `generators`, or `middleware`, for example.
21
- config.autoload_lib(ignore: %w(assets tasks))
21
+ config.autoload_lib(ignore: %w[assets tasks])
22
22
 
23
23
  # Configuration for the application, engines, and railties goes here.
24
24
  #
@@ -15,10 +15,10 @@ default: &default
15
15
  pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
16
16
  username: root
17
17
  password:
18
- <% if mysql_socket -%>
19
- socket: <%= mysql_socket %>
18
+ <% if database.socket -%>
19
+ socket: <%= database.socket %>
20
20
  <% else -%>
21
- host: localhost
21
+ host: <%%= ENV.fetch("DB_HOST") { "<%= database.host %>" } %>
22
22
  <% end -%>
23
23
 
24
24
  development:
@@ -52,8 +52,31 @@ test:
52
52
  # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
53
53
  # for a full overview on how database connection configuration can be specified.
54
54
  #
55
+ <%- if options.skip_solid? -%>
55
56
  production:
56
57
  <<: *default
57
58
  database: <%= app_name %>_production
58
59
  username: <%= app_name %>
59
60
  password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
61
+ <%- else -%>
62
+ production:
63
+ primary: &primary_production
64
+ <<: *default
65
+ database: <%= app_name %>_production
66
+ username: <%= app_name %>
67
+ password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
68
+ cache:
69
+ <<: *primary_production
70
+ database: <%= app_name %>_production_cache
71
+ migrations_paths: db/cache_migrate
72
+ queue:
73
+ <<: *primary_production
74
+ database: <%= app_name %>_production_queue
75
+ migrations_paths: db/queue_migrate
76
+ <%- unless options.skip_action_cable? -%>
77
+ cable:
78
+ <<: *primary_production
79
+ database: <%= app_name %>_production_cable
80
+ migrations_paths: db/cable_migrate
81
+ <%- end -%>
82
+ <%- end -%>
@@ -18,6 +18,13 @@ default: &default
18
18
  # For details on connection pooling, see Rails configuration guide
19
19
  # https://guides.rubyonrails.org/configuring.html#database-pooling
20
20
  pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
21
+ <% if devcontainer? -%>
22
+ <%% if ENV["DB_HOST"] %>
23
+ host: <%%= ENV["DB_HOST"] %>
24
+ username: postgres
25
+ password: postgres
26
+ <%% end %>
27
+ <% end %>
21
28
 
22
29
  development:
23
30
  <<: *default
@@ -77,8 +84,31 @@ test:
77
84
  # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
78
85
  # for a full overview on how database connection configuration can be specified.
79
86
  #
87
+ <%- if options.skip_solid? -%>
80
88
  production:
81
89
  <<: *default
82
90
  database: <%= app_name %>_production
83
91
  username: <%= app_name %>
84
92
  password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
93
+ <%- else -%>
94
+ production:
95
+ primary: &primary_production
96
+ <<: *default
97
+ database: <%= app_name %>_production
98
+ username: <%= app_name %>
99
+ password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
100
+ cache:
101
+ <<: *primary_production
102
+ database: <%= app_name %>_production_cache
103
+ migrations_paths: db/cache_migrate
104
+ queue:
105
+ <<: *primary_production
106
+ database: <%= app_name %>_production_queue
107
+ migrations_paths: db/queue_migrate
108
+ <%- unless options.skip_action_cable? -%>
109
+ cable:
110
+ <<: *primary_production
111
+ database: <%= app_name %>_production_cable
112
+ migrations_paths: db/cable_migrate
113
+ <%- end -%>
114
+ <%- end -%>
@@ -20,6 +20,53 @@ test:
20
20
  <<: *default
21
21
  database: storage/test.sqlite3
22
22
 
23
+
24
+ <%- if options.skip_kamal? -%>
25
+ # SQLite3 write its data on the local filesystem, as such it requires
26
+ # persistent disks. If you are deploying to a managed service, you should
27
+ # make sure it provides disk persistence, as many don't.
28
+ #
29
+ # Similarly, if you deploy your application as a Docker container, you must
30
+ # ensure the database is located in a persisted volume.
31
+ <%- if options.skip_solid? -%>
32
+ production:
33
+ <<: *default
34
+ # database: path/to/persistent/storage/production.sqlite3
35
+ <%- else -%>
36
+ production:
37
+ primary:
38
+ <<: *default
39
+ # database: path/to/persistent/storage/production.sqlite3
40
+ cache:
41
+ <<: *default
42
+ # database: path/to/persistent/storage/production_cache.sqlite3
43
+ migrations_paths: db/cache_migrate
44
+ <%- end -%>
45
+ <%- else -%>
46
+ # Store production database in the storage/ directory, which by default
47
+ # is mounted as a persistent Docker volume in config/deploy.yml.
48
+ <%- if options.skip_solid? -%>
23
49
  production:
24
50
  <<: *default
25
51
  database: storage/production.sqlite3
52
+ <%- else -%>
53
+ production:
54
+ primary:
55
+ <<: *default
56
+ database: storage/production.sqlite3
57
+ cache:
58
+ <<: *default
59
+ database: storage/production_cache.sqlite3
60
+ migrations_paths: db/cache_migrate
61
+ queue:
62
+ <<: *default
63
+ database: storage/production_queue.sqlite3
64
+ migrations_paths: db/queue_migrate
65
+ <%- unless options.skip_action_cable? -%>
66
+ cable:
67
+ <<: *default
68
+ database: storage/production_cable.sqlite3
69
+ migrations_paths: db/cable_migrate
70
+ <%- end -%>
71
+ <%- end -%>
72
+ <%- end -%>
@@ -15,10 +15,10 @@ default: &default
15
15
  pool: <%%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
16
16
  username: root
17
17
  password:
18
- <% if mysql_socket -%>
19
- socket: <%= mysql_socket %>
18
+ <% if database.socket -%>
19
+ socket: <%= database.socket %>
20
20
  <% else -%>
21
- host: localhost
21
+ host: <%%= ENV.fetch("DB_HOST") { "<%= database.host %>" } %>
22
22
  <% end -%>
23
23
 
24
24
  development:
@@ -52,8 +52,31 @@ test:
52
52
  # Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
53
53
  # for a full overview on how database connection configuration can be specified.
54
54
  #
55
+ <%- if options.skip_solid? -%>
55
56
  production:
56
57
  <<: *default
57
58
  database: <%= app_name %>_production
58
59
  username: <%= app_name %>
59
60
  password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
61
+ <%- else -%>
62
+ production:
63
+ primary: &primary_production
64
+ <<: *default
65
+ database: <%= app_name %>_production
66
+ username: <%= app_name %>
67
+ password: <%%= ENV["<%= app_name.upcase %>_DATABASE_PASSWORD"] %>
68
+ cache:
69
+ <<: *primary_production
70
+ database: <%= app_name %>_production_cache
71
+ migrations_paths: db/cache_migrate
72
+ queue:
73
+ <<: *primary_production
74
+ database: <%= app_name %>_production_queue
75
+ migrations_paths: db/queue_migrate
76
+ <%- unless options.skip_action_cable? -%>
77
+ cable:
78
+ <<: *primary_production
79
+ database: <%= app_name %>_production_cable
80
+ migrations_paths: db/cable_migrate
81
+ <%- end -%>
82
+ <%- end -%>
@@ -0,0 +1,128 @@
1
+ # Name of your application. Used to uniquely configure containers.
2
+ service: <%= app_name %>
3
+
4
+ # Name of the container image.
5
+ image: your-user/<%= app_name %>
6
+
7
+ # Deploy to these servers.
8
+ servers:
9
+ web:
10
+ - 192.168.0.1
11
+ # job:
12
+ # hosts:
13
+ # - 192.168.0.1
14
+ # cmd: bin/jobs
15
+
16
+ # Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server.
17
+ # Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer.
18
+ #
19
+ # Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption.
20
+ proxy:
21
+ ssl: true
22
+ host: app.example.com
23
+
24
+ # Credentials for your image host.
25
+ registry:
26
+ # Specify the registry server, if you're not using Docker Hub
27
+ # server: registry.digitalocean.com / ghcr.io / ...
28
+ username: your-user
29
+
30
+ # Always use an access token rather than real password when possible.
31
+ password:
32
+ - KAMAL_REGISTRY_PASSWORD
33
+
34
+ # Inject ENV variables into containers (secrets come from .kamal/secrets).
35
+ env:
36
+ secret:
37
+ - RAILS_MASTER_KEY
38
+ <% if skip_solid? -%>
39
+ # clear:
40
+ # # Set number of cores available to the application on each server (default: 1).
41
+ # WEB_CONCURRENCY: 2
42
+
43
+ # # Match this to any external database server to configure Active Record correctly
44
+ # DB_HOST: 192.168.0.2
45
+
46
+ # # Log everything from Rails
47
+ # RAILS_LOG_LEVEL: debug
48
+ <% else -%>
49
+ clear:
50
+ # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs.
51
+ # When you start using multiple servers, you should split out job processing to a dedicated machine.
52
+ SOLID_QUEUE_IN_PUMA: true
53
+
54
+ # Set number of processes dedicated to Solid Queue (default: 1)
55
+ # JOB_CONCURRENCY: 3
56
+
57
+ # Set number of cores available to the application on each server (default: 1).
58
+ # WEB_CONCURRENCY: 2
59
+
60
+ # Match this to any external database server to configure Active Record correctly
61
+ # Use <%= app_name %>-db for a db accessory server on same machine via local kamal docker network.
62
+ # DB_HOST: 192.168.0.2
63
+
64
+ # Log everything from Rails
65
+ # RAILS_LOG_LEVEL: debug
66
+ <% end -%>
67
+
68
+ # Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation:
69
+ # "bin/kamal logs -r job" will tail logs from the first server in the job section.
70
+ aliases:
71
+ console: app exec --interactive --reuse "bin/rails console"
72
+ shell: app exec --interactive --reuse "bash"
73
+ logs: app logs -f
74
+ dbc: app exec --interactive --reuse "bin/rails dbconsole"
75
+
76
+ <% unless skip_storage? %>
77
+ # Use a persistent storage volume for sqlite database files and local Active Storage files.
78
+ # Recommended to change this to a mounted volume path that is backed up off server.
79
+ volumes:
80
+ - "<%= app_name %>_storage:/rails/storage"
81
+
82
+ <% end %>
83
+ # Bridge fingerprinted assets, like JS and CSS, between versions to avoid
84
+ # hitting 404 on in-flight requests. Combines all files from new and old
85
+ # version inside the asset_path.
86
+ asset_path: /rails/public/assets
87
+
88
+ # Configure the image builder.
89
+ builder:
90
+ arch: amd64
91
+
92
+ # # Build image via remote server (useful for faster amd64 builds on arm64 computers)
93
+ # remote: ssh://docker@docker-builder-server
94
+ #
95
+ # # Pass arguments and secrets to the Docker build process
96
+ # args:
97
+ # RUBY_VERSION: <%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" %>
98
+ # secrets:
99
+ # - GITHUB_TOKEN
100
+ # - RAILS_MASTER_KEY
101
+
102
+ # Use a different ssh user than root
103
+ # ssh:
104
+ # user: app
105
+
106
+ # Use accessory services (secrets come from .kamal/secrets).
107
+ # accessories:
108
+ # db:
109
+ # image: mysql:8.0
110
+ # host: 192.168.0.2
111
+ # # Change to 3306 to expose port to the world instead of just local network.
112
+ # port: "127.0.0.1:3306:3306"
113
+ # env:
114
+ # clear:
115
+ # MYSQL_ROOT_HOST: '%'
116
+ # secret:
117
+ # - MYSQL_ROOT_PASSWORD
118
+ # files:
119
+ # - config/mysql/production.cnf:/etc/mysql/my.cnf
120
+ # - db/production.sql:/docker-entrypoint-initdb.d/setup.sql
121
+ # directories:
122
+ # - data:/var/lib/mysql
123
+ # redis:
124
+ # image: redis:7.0
125
+ # host: 192.168.0.2
126
+ # port: 6379
127
+ # directories:
128
+ # - data:/data
@@ -3,9 +3,7 @@ require "active_support/core_ext/integer/time"
3
3
  Rails.application.configure do
4
4
  # Settings specified here will take precedence over those in config/application.rb.
5
5
 
6
- # In the development environment your application's code is reloaded any time
7
- # it changes. This slows down response time but is perfect for development
8
- # since you don't have to restart the web server when you make code changes.
6
+ # Make code changes take effect immediately without server restart.
9
7
  config.enable_reloading = true
10
8
 
11
9
  # Do not eager load code on boot.
@@ -14,26 +12,23 @@ Rails.application.configure do
14
12
  # Show full error reports.
15
13
  config.consider_all_requests_local = true
16
14
 
17
- # Enable server timing
15
+ # Enable server timing.
18
16
  config.server_timing = true
19
17
 
20
- # Enable/disable caching. By default caching is disabled.
21
- # Run rails dev:cache to toggle caching.
18
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
19
+ # Run rails dev:cache to toggle Action Controller caching.
22
20
  if Rails.root.join("tmp/caching-dev.txt").exist?
23
21
  <%- unless options.api? -%>
24
22
  config.action_controller.perform_caching = true
25
23
  config.action_controller.enable_fragment_cache_logging = true
26
-
27
24
  <%- end -%>
28
- config.cache_store = :memory_store
29
- config.public_file_server.headers = {
30
- "Cache-Control" => "public, max-age=#{2.days.to_i}"
31
- }
25
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" }
32
26
  else
33
27
  config.action_controller.perform_caching = false
34
-
35
- config.cache_store = :null_store
36
28
  end
29
+
30
+ # Change to :null_store to avoid any caching.
31
+ config.cache_store = :memory_store
37
32
  <%- unless skip_active_storage? -%>
38
33
 
39
34
  # Store uploaded files on the local file system (see config/storage.yml for options).
@@ -44,18 +39,16 @@ Rails.application.configure do
44
39
  # Don't care if the mailer can't send.
45
40
  config.action_mailer.raise_delivery_errors = false
46
41
 
42
+ # Make template changes take effect immediately.
47
43
  config.action_mailer.perform_caching = false
44
+
45
+ # Set localhost to be used by links generated in mailer templates.
46
+ config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
48
47
  <%- end -%>
49
48
 
50
49
  # Print deprecation notices to the Rails logger.
51
50
  config.active_support.deprecation = :log
52
51
 
53
- # Raise exceptions for disallowed deprecations.
54
- config.active_support.disallowed_deprecation = :raise
55
-
56
- # Tell Active Support which deprecation messages to disallow.
57
- config.active_support.disallowed_deprecation_warnings = []
58
-
59
52
  <%- unless options.skip_active_record? -%>
60
53
  # Raise an error on page load if there are pending migrations.
61
54
  config.active_record.migration_error = :page_load
@@ -63,28 +56,31 @@ Rails.application.configure do
63
56
  # Highlight code that triggered database queries in logs.
64
57
  config.active_record.verbose_query_logs = true
65
58
 
59
+ # Append comments with runtime information tags to SQL queries in logs.
60
+ config.active_record.query_log_tags_enabled = true
61
+
66
62
  <%- end -%>
67
63
  <%- unless options[:skip_active_job] -%>
68
64
  # Highlight code that enqueued background job in logs.
69
65
  config.active_job.verbose_enqueue_logs = true
70
66
 
71
67
  <%- end -%>
72
- <%- unless skip_sprockets? -%>
73
- # Suppress logger output for asset requests.
74
- config.assets.quiet = true
75
- <%- end -%>
76
-
77
68
  # Raises error for missing translations.
78
69
  # config.i18n.raise_on_missing_translations = true
79
70
 
80
71
  # Annotate rendered view with file names.
81
- # config.action_view.annotate_rendered_view_with_filenames = true
72
+ config.action_view.annotate_rendered_view_with_filenames = true
82
73
 
83
74
  <%- unless skip_action_cable? -%>
84
75
  # Uncomment if you wish to allow Action Cable access from any origin.
85
76
  # config.action_cable.disable_request_forgery_protection = true
86
77
 
87
78
  <%- end -%>
88
- # Raise error when a before_action's only/except options reference missing actions
79
+ # Raise error when a before_action's only/except options reference missing actions.
89
80
  config.action_controller.raise_on_missing_callback_actions = true
81
+ <%- unless skip_rubocop? -%>
82
+
83
+ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
84
+ # config.generators.apply_rubocop_autocorrect_after_generate!
85
+ <%- end -%>
90
86
  end
@@ -6,99 +6,86 @@ Rails.application.configure do
6
6
  # Code is not reloaded between requests.
7
7
  config.enable_reloading = false
8
8
 
9
- # Eager load code on boot. This eager loads most of Rails and
10
- # your application in memory, allowing both threaded web servers
11
- # and those relying on copy on write to perform better.
12
- # Rake tasks automatically ignore this option for performance.
9
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
13
10
  config.eager_load = true
14
11
 
15
- # Full error reports are disabled and caching is turned on.
12
+ # Full error reports are disabled.
16
13
  config.consider_all_requests_local = false
17
14
  <%- unless options.api? -%>
15
+
16
+ # Turn on fragment caching in view templates.
18
17
  config.action_controller.perform_caching = true
19
18
  <%- end -%>
20
19
 
21
- # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment
22
- # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).
23
- # config.require_master_key = true
24
-
25
- # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
26
- # config.public_file_server.enabled = false
27
-
28
- <%- unless skip_sprockets? -%>
29
- # Compress CSS using a preprocessor.
30
- # config.assets.css_compressor = :sass
20
+ # Cache assets for far-future expiry since they are all digest stamped.
21
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
31
22
 
32
- # Do not fall back to assets pipeline if a precompiled asset is missed.
33
- config.assets.compile = false
34
-
35
- <%- end -%>
36
23
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
37
24
  # config.asset_host = "http://assets.example.com"
38
25
 
39
- # Specifies the header that your server uses for sending files.
40
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
41
- # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
42
-
43
26
  <%- unless skip_active_storage? -%>
44
27
  # Store uploaded files on the local file system (see config/storage.yml for options).
45
28
  config.active_storage.service = :local
46
29
 
47
- <%- end -%>
48
- <%- unless skip_action_cable? -%>
49
- # Mount Action Cable outside main process or domain.
50
- # config.action_cable.mount_path = nil
51
- # config.action_cable.url = "wss://example.com/cable"
52
- # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
53
-
54
30
  <%- end -%>
55
31
  # Assume all access to the app is happening through a SSL-terminating reverse proxy.
56
- # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
57
- # config.assume_ssl = true
32
+ config.assume_ssl = true
58
33
 
59
34
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
60
35
  config.force_ssl = true
61
36
 
62
- # Log to STDOUT by default
63
- config.logger = ActiveSupport::Logger.new(STDOUT)
64
- .tap { |logger| logger.formatter = ::Logger::Formatter.new }
65
- .then { |logger| ActiveSupport::TaggedLogging.new(logger) }
37
+ # Skip http-to-https redirect for the default health check endpoint.
38
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
66
39
 
67
- # Prepend all log lines with the following tags.
40
+ # Log to STDOUT with the current request id as a default log tag.
68
41
  config.log_tags = [ :request_id ]
42
+ config.logger = ActiveSupport::TaggedLogging.logger(STDOUT)
69
43
 
70
- # "info" includes generic and useful information about system operation, but avoids logging too much
71
- # information to avoid inadvertent exposure of personally identifiable information (PII). If you
72
- # want to log everything, set the level to "debug".
44
+ # Change to "debug" to log everything (including potentially personally-identifiable information!)
73
45
  config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
74
46
 
75
- # Use a different cache store in production.
47
+ # Prevent health checks from clogging up the logs.
48
+ config.silence_healthcheck_path = "/up"
49
+
50
+ # Don't log any deprecations.
51
+ config.active_support.report_deprecations = false
52
+
53
+ # Replace the default in-process memory cache store with a durable alternative.
76
54
  # config.cache_store = :mem_cache_store
77
55
 
78
56
  <%- unless options[:skip_active_job] -%>
79
- # Use a real queuing backend for Active Job (and separate queues per environment).
57
+ # Replace the default in-process and non-durable queuing backend for Active Job.
80
58
  # config.active_job.queue_adapter = :resque
81
- # config.active_job.queue_name_prefix = "<%= app_name %>_production"
82
59
 
83
60
  <%- end -%>
84
61
  <%- unless options.skip_action_mailer? -%>
85
- config.action_mailer.perform_caching = false
86
-
87
62
  # Ignore bad email addresses and do not raise email delivery errors.
88
63
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
89
64
  # config.action_mailer.raise_delivery_errors = false
90
65
 
66
+ # Set host to be used by links generated in mailer templates.
67
+ config.action_mailer.default_url_options = { host: "example.com" }
68
+
69
+ # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
70
+ # config.action_mailer.smtp_settings = {
71
+ # user_name: Rails.application.credentials.dig(:smtp, :user_name),
72
+ # password: Rails.application.credentials.dig(:smtp, :password),
73
+ # address: "smtp.example.com",
74
+ # port: 587,
75
+ # authentication: :plain
76
+ # }
77
+
91
78
  <%- end -%>
92
79
  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
93
80
  # the I18n.default_locale when a translation cannot be found).
94
81
  config.i18n.fallbacks = true
95
-
96
- # Don't log any deprecations.
97
- config.active_support.report_deprecations = false
98
82
  <%- unless options.skip_active_record? -%>
99
83
 
100
84
  # Do not dump schema after migrations.
101
85
  config.active_record.dump_schema_after_migration = false
86
+
87
+ # Only use :id for inspections in production.
88
+ config.active_record.attributes_for_inspect = [ :id ]
102
89
  <%- end -%>
103
90
 
104
91
  # Enable DNS rebinding protection and other `Host` header attacks.
@@ -106,6 +93,7 @@ Rails.application.configure do
106
93
  # "example.com", # Allow requests from example.com
107
94
  # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
108
95
  # ]
96
+ #
109
97
  # Skip DNS rebinding protection for the default health check endpoint.
110
98
  # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
111
99
  end
@@ -1,5 +1,3 @@
1
- require "active_support/core_ext/integer/time"
2
-
3
1
  # The test environment is used exclusively to run your application's
4
2
  # test suite. You never need to work with it otherwise. Remember that
5
3
  # your test database is "scratch space" for the test suite and is wiped
@@ -17,15 +15,11 @@ Rails.application.configure do
17
15
  # loading is working properly before deploying your code.
18
16
  config.eager_load = ENV["CI"].present?
19
17
 
20
- # Configure public file server for tests with Cache-Control for performance.
21
- config.public_file_server.enabled = true
22
- config.public_file_server.headers = {
23
- "Cache-Control" => "public, max-age=#{1.hour.to_i}"
24
- }
18
+ # Configure public file server for tests with cache-control for performance.
19
+ config.public_file_server.headers = { "cache-control" => "public, max-age=3600" }
25
20
 
26
- # Show full error reports and disable caching.
21
+ # Show full error reports.
27
22
  config.consider_all_requests_local = true
28
- config.action_controller.perform_caching = false
29
23
  config.cache_store = :null_store
30
24
 
31
25
  # Render exception templates for rescuable exceptions and raise for other exceptions.
@@ -40,29 +34,24 @@ Rails.application.configure do
40
34
 
41
35
  <%- end -%>
42
36
  <%- unless options.skip_action_mailer? -%>
43
- config.action_mailer.perform_caching = false
44
-
45
37
  # Tell Action Mailer not to deliver emails to the real world.
46
38
  # The :test delivery method accumulates sent emails in the
47
39
  # ActionMailer::Base.deliveries array.
48
40
  config.action_mailer.delivery_method = :test
49
41
 
42
+ # Set host to be used by links generated in mailer templates.
43
+ config.action_mailer.default_url_options = { host: "example.com" }
44
+
50
45
  <%- end -%>
51
46
  # Print deprecation notices to the stderr.
52
47
  config.active_support.deprecation = :stderr
53
48
 
54
- # Raise exceptions for disallowed deprecations.
55
- config.active_support.disallowed_deprecation = :raise
56
-
57
- # Tell Active Support which deprecation messages to disallow.
58
- config.active_support.disallowed_deprecation_warnings = []
59
-
60
49
  # Raises error for missing translations.
61
50
  # config.i18n.raise_on_missing_translations = true
62
51
 
63
52
  # Annotate rendered view with file names.
64
53
  # config.action_view.annotate_rendered_view_with_filenames = true
65
54
 
66
- # Raise error when a before_action's only/except options reference missing actions
55
+ # Raise error when a before_action's only/except options reference missing actions.
67
56
  config.action_controller.raise_on_missing_callback_actions = true
68
57
  end