Commit Graph

14529 Commits

Author SHA1 Message Date
Sam Ruby
ff224e618b
Ensure Dockerfile installs commonly needed packages (#46953) 2023-01-10 21:47:20 +01:00
Sam Ruby
35ca0bede9
Dockerfile binfile fixups; primarily for Windows users (#46944)
* Dockerfile binfile fixups; primarily for Windows users

 * chmod +x
 * CRLF => LF
 * ruby.exe => ruby

If Rails new is run on a MacOS or Linux machine, no fixups are
required or emitted to the Dockerfile.

* attempt to placate rubocop

* use binstub
2023-01-10 14:38:40 +01:00
David Heinemeier Hansson
5c830a8a5c
Add a default health controller (#46936)
* Add a default health controller

Load balancers and uptime monitors all need a basic endpoint to tell whether the app is up. Here's a good starting point that'll work in many situations.

* Add CHANGELOG entry

* Add test for HealthController

* Account for new default route
2023-01-10 10:47:32 +01:00
fatkodima
83845c4d06 Fix schema cache dumping of virtual columns 2023-01-09 23:04:43 +02:00
Sam Ruby
9e6cb694dd
omit assets:precompile in Dockerfile for api only apps (#46938) 2023-01-09 20:23:05 +01:00
Alex Ghiculescu
16aaf7f62d
Run test:prepare before bin/rails test commands (#46664) 2023-01-09 20:22:27 +01:00
Sam Ruby
ecc7491bc5
Change dockerfile from using Node 19 to match dev environment (#46794)
* Change dockerfile from using Node 19 to match dev environment

This is accomplished via installing volta: https://volta.sh/.

Also:
  * decouple the installation of libvips from node
  * add installation of the node_modules by running yarn

This pull request is part one of many intended to add features
from fly.io's generated Dockerfiles that are of general interest
to Rails.  For the overall plan, see:
https://community.fly.io/t/preparations-for-rails-7-1/9512

I'm making these changes in stages so that I can get early feedback
and in so doing improve future pull requests.

This changes was tested by generating an new application with esbuild
and deploying it.

attn: @ddh

* switch to double quotes to placate Rubocop

* add some Dockerfile tests

* generate a .node-version file if using_node?

* remove this for now

* reduce the number of layers

also adopt some of the style conventions already in use in the
Dockerfile with respect to quoting and spacing.

* add changelog entry
2023-01-09 17:34:58 +01:00
zzak
ed65dfffc1 Add changelog for #46858 since it affects railties default middleware stack 2023-01-09 09:34:21 +09:00
Jonathan Hefner
70a67b9ddc Revise Rails::Application#encrypted doc [ci-skip] 2023-01-08 15:47:31 -06:00
Jonathan Hefner
8641197b54 Revise Rails::Application#credentials doc [ci-skip] 2023-01-08 15:47:31 -06:00
Hartley McGuire
27ddfa1045
Allow setting config.hosts to single IPAddr
This was broken in 0019dea and partially fixed for setting config.hosts
to a nil value in 56ecea0.

However, since HostAuthorization coerces the hosts param to an array to
allow a single String or IPAddr as a valid value, the check should do
the same.
2023-01-07 11:23:39 -05:00
Stan Lo
56ecea0d4d
Allow setting config.hosts to nil
Prior to #46858, uses can set `config.hosts = nil` to allow all hosts.
But now it causes `NoMethodError` because the check uses only `empty?`.

Given that the HostAuthorization itself allows taking `nil` as hosts,
I think this breaking change is not intentional. Therefore this commit
fixes the issue by also checking if the value is `nil`.
2023-01-07 14:33:35 +00:00
zzak
78507d8352 Add changelog for #43487 2023-01-07 09:14:30 +09:00
zzak
911b3a468c Add changelog for #46838 2023-01-07 09:10:41 +09:00
zzak
4d245e0d56 Expand upon changelog for #46817 2023-01-07 09:05:31 +09:00
Jonathan Hefner
bb812db7c2
Merge pull request #46858 from skipkayhil/only-use-host-auth-if-config
Only use HostAuthorization if configured
2023-01-05 15:00:50 -06:00
Akira Matsuda
d247f491a4
Use cached instance of ruby_version
also, Gem::Version's comparater directly accepts a String since RubyGems 3.3.6
https://github.com/rubygems/rubygems/pull/5275
and Rails requires RubyGems >= 3.3.13 now, https://github.com/rails/rails/pull/46817
so we can just pass in "2.7.0" without wrapping with `Gem::Version.new`.
2023-01-06 02:12:07 +09:00
fatkodima
2e7f287627 Store correct environment in internal_metadata when run rails db:prepare 2023-01-05 00:00:11 +02:00
Hartley McGuire
0019dea961
Only use HostAuthorization if configured
Previously, HostAuthorization would be added to the middleware stack
whether or not config.hosts had any entries. While HostAuthorization
does check config.hosts before doing computationally expensive things,
its inclusion ends up being easily avoidable overhead on every request.
2023-01-03 18:42:31 -05:00
Greg Molnar
fad500b8c6
fix comparison type issue in puma.rb template (#46874)
* fix comparison type issue in puma.rb template

* Ensure integer

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-01-03 13:42:16 +01:00
Akira Matsuda
6287c109d3
Don't report broken absolute path when app_root is nil
When running tests that does not initialize rails (e.g. `rake test` under
active_model), it used to just cut off the leading "/" from absolte paths and
report something like

rails test Users/a_matsuda/rails/activemodel/test/cases/api_test.rb:40

that cannot be executed.
2023-01-03 12:05:21 +09:00
David Heinemeier Hansson
839ac1e70f
Use worker count equal to processor count in production (#46838) 2022-12-27 18:09:09 -08:00
David Heinemeier Hansson
afbde03801 Remove odd excess comment lines 2022-12-27 13:22:20 -08:00
Yasuo Honda
3aa32f2176 Bump required_rubygems_version to 3.3.13 or higher
https://github.com/rails/rails/pull/45979 relies on
https://github.com/rubygems/rubygems/pull/5486 which is included
in https://github.com/rubygems/rubygems/blob/master/CHANGELOG.md#3313--2022-05-04

- RubyGems 3.3.12` Gem.ruby_version` includes patch level
```ruby
$ gem -v
3.3.12
$ irb
irb(main):001:0> Gem.ruby_version
=> Gem::Version.new("3.1.3.p185")
```

- RubyGems 3.3.13` Gem.ruby_version` does not include patch level
```
$ gem -v
3.3.13
$ irb
irb(main):001:0> Gem.ruby_version
=> Gem::Version.new("3.1.3")
irb(main):002:0>
```

The current version 1.8.11 has been updated to use Ruby 1.9.3-p0
https://github.com/rails/rails/pull/4576
2022-12-24 10:46:41 +09:00
Akshay Birajdar
c312bb7e04 Prefer using new shorthand helper Rails.env.local? 2022-12-23 19:04:33 +05:30
Hartley McGuire
89c2c91ccd
Eager load Rails::BacktraceCleaner
Previously, Rails::BacktraceCleaner was both lazily required and
instantiated. While it would end up being loaded during initialization
for apps that use Active Record (due to active_record.backtrace_cleaner
initializer), it would not be loaded until the first request for those
that don't.

The solution is similar to daff36c, however ::Rails is not currently
in the list of eager_load_namespaces. Therefore simply requiring it
seems like the easiest solution.

The removed comment indicating the lazy require is necessary due to load
order dates back to the addition of Rails::BacktraceCleaner in f42c77f.
This predates the integration of Bundler and reorganization of framework
loading, so it is no longer accurate.
2022-12-23 01:13:10 -05:00
Akira Matsuda
66386d3b4c
Splat the tag names to avoid passing double arrays 2022-12-22 17:31:12 +09:00
David Heinemeier Hansson
0239401010 Stop recommending sassc-rails. Its been deprecated, and we have dartsass-rails now instead. 2022-12-21 14:44:46 +01:00
David Heinemeier Hansson
f8f2590725
Bundle test gems so this image can also be used for CI testing 2022-12-20 16:35:26 +01:00
David Heinemeier Hansson
513be3a3a6
Consistent no-period comments 2022-12-20 15:08:46 +01:00
David Heinemeier Hansson
2ea62b99c8
Run under bash to avoid syntax error in conditional 2022-12-20 15:07:24 +01:00
Nick Janetakis
0819a81fa3
Add CMD and refactor ENTRYPOINT in the Docker generator (#46778)
* Add CMD and refactor ENTRYPOINT

The CMD will run by default when you run the container without supplying
any arguments but you can choose to overwrite this at runtime by
doing: docker container run -it myapp rails c

The ENTRYPOINT will only create or migrate the database when the default
CMD is invoked. If you choose to run a different command such as the
rails console or a background worker process the db:prepare command
will not run.

* Remove extra space from ENTRYPOINT comment
2022-12-20 14:11:23 +01:00
Jonathan Hefner
90d1096708 Skip Docker-related files for plugin dummy apps
Follow-up to #46762.

Docker-related files are intended for production deployment, not
development.  Therefore, this commit prevents those files from being
generated for plugin dummy apps.
2022-12-19 16:12:27 -06:00
Nick Janetakis
e0ba620bab
Add additional ignored files to the .dockerignore template (#46772)
* Add additional ignored files

* Use forward slashes for all patterns
2022-12-19 17:32:44 +01:00
David Heinemeier Hansson
4f3af4a67f
Add default Dockerfiles (#46762) 2022-12-19 16:07:13 +01:00
Akira Matsuda
41c2c26dc6
Reuse the Array object passed from parent middleware
This patch reduces Array object allocations from some Rack middleware per each
request by reusing the Array object that wraps status, headers, and body
objects. This is a Rails version of the same improvements that has already been
pushed to Rack 3.0. https://github.com/rack/rack/pull/1887
2022-12-19 23:04:04 +09:00
Jonathan Hefner
aae4f911b5
Merge pull request #46767 from jonathanhefner/credentials-diff-enrollment-reminder
Remind of credentials diff enrollment on edit
2022-12-18 14:26:03 -06:00
Jonathan Hefner
8bb23e9e30 Remind of credentials diff enrollment on edit
When users create a new app or `git clone` an existing app, they may not
realize it is enrolled in decrypted diffing of credentials (or be aware
of the feature).

This commit adds a confirmation message when configuring the Git diff
driver for credentials, to serve as a reminder.  The message will be
shown when running `bin/rails credentials:edit` for the first time after
`rails new` or `git clone`.

This commit also silences the enrollment confirmation message when
creating a new app, to reduce noise.
2022-12-18 12:47:14 -06:00
Jonathan Hefner
6f6da759b0 Silence credentials generator in app generator
Follow-up to #45543.

In #45543, `CredentialsGenerator#add_credentials_file_silently` was
removed in favor of setting Thor's `quiet: true` option.  However, the
call to `CredentialsGenerator` in the app generator was not updated to
use `quiet: true`.
2022-12-18 10:48:04 -06:00
Jon Dufresne
aa81f67a9e Trim trailing whitespace from *.md files
Fixes the error:

    Run bin/check-changelogs ./rails
    ............F

    Offenses:

    ./rails/railties/CHANGELOG.md:4 Trailing whitespace detected.
2022-12-17 15:27:51 -08:00
David Heinemeier Hansson
a3e392f656
Allow assets:precompile to be run in a production build step without passing in RAILS_MASTER_KEY (#46760)
* Add ENV["SECRET_KEY_BASE_DUMMY"]

This is useful when precompiling assets for production as part of a build step that otherwise does not need access to the production secrets.

* Test SECRET_KEY_BASE_DUMMY
2022-12-17 20:53:30 +01:00
Jean Boussier
768a2c69c6
Merge pull request #46163 from p8/rails-help-with-command-descriptions
Add missing descriptions for additional commands in Rails help
2022-12-16 10:35:06 +01:00
Jonathan Hefner
93038baad7 Use routes.default_url_options in AC::Renderer env
When a host is not specified for an `ActionController::Renderer`'s env,
the host and related options will now be derived from the routes'
`default_url_options` and `ActionDispatch::Http::URL.secure_protocol`.

For example, with:

  ```ruby
  Rails.application.default_url_options = { host: "rubyonrails.org" }
  Rails.application.config.force_ssl = true
  ```

Before:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "http://example.org/blog"
  ```

After:

  ```ruby
  ApplicationController.renderer.render inline: "<%= blog_url %>"
  # => "https://rubyonrails.org/blog"
  ```

As a consequence, Action Text attachment URLs rendered in a background
job (a la Turbo Streams) will now use `Rails.application.default_url_options`.

Fixes #41795.
Fixes hotwired/turbo-rails#54.
Fixes hotwired/turbo-rails#155.
2022-12-15 16:22:07 -06:00
Petrik
f52b1ccd0d Show descriptions for all commands in Rails help
When calling `rails help` most commands missed their description. We now
show the same descriptions as shown in `rails -T`.

We can show the description after the command name and use some padding
to align the descriptions. Lines are truncated to the width of the
terminal.

Rails::Command had logic for printing help commands not in 'usage':
`print_commands`, `commands` and the `COMMANDS_IN_USAGE` constant. As
these methods were only used by Rails::Command::HelpCommand, they have
been moved HelpCommand.

This also changes the `printing_commands` methods on several classes.
Instead of returning just the commands, they return the commands
with the descriptions. As these are only used for printing help it does
not affect any other code.

Some commands (routes, credentials:diff, etc) show no description yet,
but these can be added later.
2022-12-15 21:09:58 +01:00
Adrianna Chang
0b5a705e1b Hide changes to before_committed! behaviour behind config
As of https://github.com/rails/rails/pull/46525, the behaviour around
before_committed! callbacks has changed: callbacks are run on every
enrolled record in a transaction, even multiple copies of the same record.
This is a significant change that apps should be able to opt into in order
to avoid unexpected issues.
2022-12-15 11:43:51 -05:00
Akira Matsuda
9c66072b97
Prefer Kernel#sprintf over String#%
String#% takes the arguments as an Array object when passing in multiple values,
which requires us to create an extra object.
2022-12-15 11:55:03 +09:00
Eileen M. Uchitelle
06e1ba3d88
Merge pull request #46720 from ghiculescu/parallel-test-issues
Parallelization test improvements
2022-12-14 09:01:24 -05:00
Alex Ghiculescu
72c949231b Parallelization test improvements
This fixes some issues I found while working on https://github.com/rails/rails/pull/46718

- Some of the tests in `test_runner_test.rb` generate a new test file, then run it. In some cases, the generated tests were failing. The calling test didn't expect this, but didn't fail despite that. So in this PR I have fixed the generated tests to always pass, and added `allow_failure: false` to enforce this.
- Added a missing test for when `PARALLEL_WORKERS=1`.
- Fixed a typo and removed some unnecessary wording in the docs.
2022-12-13 19:00:53 -06:00
Eileen M. Uchitelle
b94b9bd984
Merge pull request #46641 from ghiculescu/query-log-namespace
Query Logs: `namespaced_controller` tag should match `controller` format
2022-12-13 13:13:34 -05:00
Alex Ghiculescu
090d1acfe4 Query Logs: namespaced_controller tag should match controller format
Currently if you do this:

```ruby
config.active_record.query_log_tags = [:namespaced_controller]
```

A request that's processed by the `NameSpaced::UsersController` will log as `namespaced_controller='NameSpaced%3A%3AUsersController'`.

By contrast if you set the tag to `:controller` it would log as `controller='user'`, much nicer.

This PR makes the `:namespaced_controller` formatting more similar to `:controller` - it will now log as `namespaced_controller='name_spaced/users'`.
2022-12-12 10:31:00 -06:00