1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Config: Get environment from RAILS_ENV, too (#2022)

- as well as from RACK_ENV
  - this is part of the effort to bring the configuration defaults from
    the puma-heroku plugin to Puma
This commit is contained in:
Olle Jonsson 2019-11-11 06:10:02 +01:00 committed by Nate Berkopec
parent 39d16fadaf
commit 629b7adab8
7 changed files with 31 additions and 8 deletions

View file

@ -2,6 +2,7 @@
* Features
* Add pumactl `thread-backtraces` command to print thread backtraces (#2053)
* Configuration: `environment` is read from `RAILS_ENV`, if `RACK_ENV` can't be found (#2022)
* Bugfixes
* Your bugfix goes here (#Github Number)
@ -12,8 +13,10 @@
* Features
* Strip whitespace at end of HTTP headers (#2010)
* Optimize HTTP parser for JRuby (#2012)
* Add SSL support for the control app (#2046)
* Add SSL support for the control app and cli (#2046, #2052)
* Bugfixes
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
* Fix pumactl defaulting puma to development if an environment was not specified (#2035)

View file

@ -220,7 +220,7 @@ You can also provide a configuration file with the `-C` (or `--config`) flag:
$ puma -C /path/to/config
```
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, Puma looks for configuration at `config/puma/<environment_name>.rb`.
If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.
If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
@ -275,7 +275,7 @@ reliability in production environments:
## Community Plugins
* [puma-heroku](https://github.com/evanphx/puma-heroku) — default Puma configuration for running on Heroku
* [puma-heroku](https://github.com/puma/puma-heroku) — default Puma configuration for running on Heroku
* [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
* [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
* [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog

View file

@ -182,7 +182,7 @@ module Puma
:worker_shutdown_timeout => DefaultWorkerShutdownTimeout,
:remote_address => :socket,
:tag => method(:infer_tag),
:environment => -> { ENV['RACK_ENV'] || "development" },
:environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" },
:rackup => DefaultRackup,
:logger => STDOUT,
:persistent_timeout => Const::PERSISTENT_TIMEOUT,

View file

@ -23,7 +23,7 @@ module Puma
@control_auth_token = nil
@config_file = nil
@command = nil
@environment = ENV['RACK_ENV']
@environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
@argv = argv.dup
@stdout = stdout

View file

@ -384,11 +384,22 @@ class TestCLI < Minitest::Test
assert_equal %w[a b], extra_dependencies
end
def test_environment
def test_environment_rack_env
ENV.delete 'RACK_ENV'
Puma::CLI.new ["--environment", @environment]
assert_equal ENV['RACK_ENV'], @environment
assert_equal @environment, ENV['RACK_ENV']
end
def test_environment_rails_env
ENV.delete 'RACK_ENV'
ENV['RAILS_ENV'] = @environment
Puma::CLI.new []
assert_equal @environment, ENV['RACK_ENV']
ENV.delete 'RAILS_ENV'
end
end

View file

@ -230,6 +230,15 @@ class TestConfigFileWithFakeEnv < TestConfigFileBase
end
end
def test_config_files_with_rails_env
with_env('RAILS_ENV' => 'fake-env', 'RACK_ENV' => nil) do
conf = Puma::Configuration.new do
end
assert_equal ['config/puma/fake-env.rb'], conf.config_files
end
end
def test_config_files_with_specified_environment
conf = Puma::Configuration.new do
end

View file

@ -53,7 +53,7 @@ class TestPumaControlCli < TestConfigFileBase
end
def test_environment_without_rack_env
with_env("RACK_ENV" => nil) do
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
control_cli = Puma::ControlCLI.new ["halt"]
assert_nil control_cli.instance_variable_get("@environment")
@ -95,7 +95,7 @@ class TestPumaControlCli < TestConfigFileBase
puma_config_file = "config/puma.rb"
development_config_file = "config/puma/development.rb"
with_env("RACK_ENV" => nil) do
with_env("RACK_ENV" => nil, 'RAILS_ENV' => nil) do
with_config_file(puma_config_file, port) do
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")