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 * Features
* Add pumactl `thread-backtraces` command to print thread backtraces (#2053) * 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 * Bugfixes
* Your bugfix goes here (#Github Number) * Your bugfix goes here (#Github Number)
@ -12,8 +13,10 @@
* Features * Features
* Strip whitespace at end of HTTP headers (#2010) * Strip whitespace at end of HTTP headers (#2010)
* Optimize HTTP parser for JRuby (#2012) * 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) * Add SSL support for the control app and cli (#2046, #2052)
* Bugfixes * Bugfixes
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564) * 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) * 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 $ 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: 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 ## 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-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-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 * [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, :worker_shutdown_timeout => DefaultWorkerShutdownTimeout,
:remote_address => :socket, :remote_address => :socket,
:tag => method(:infer_tag), :tag => method(:infer_tag),
:environment => -> { ENV['RACK_ENV'] || "development" }, :environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" },
:rackup => DefaultRackup, :rackup => DefaultRackup,
:logger => STDOUT, :logger => STDOUT,
:persistent_timeout => Const::PERSISTENT_TIMEOUT, :persistent_timeout => Const::PERSISTENT_TIMEOUT,

View file

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

View file

@ -384,11 +384,22 @@ class TestCLI < Minitest::Test
assert_equal %w[a b], extra_dependencies assert_equal %w[a b], extra_dependencies
end end
def test_environment def test_environment_rack_env
ENV.delete 'RACK_ENV' ENV.delete 'RACK_ENV'
Puma::CLI.new ["--environment", @environment] 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
end end

View file

@ -230,6 +230,15 @@ class TestConfigFileWithFakeEnv < TestConfigFileBase
end end
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 def test_config_files_with_specified_environment
conf = Puma::Configuration.new do conf = Puma::Configuration.new do
end end

View file

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