Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check puma config environment file on control_cli #1885

Merged
merged 1 commit into from Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/puma/control_cli.rb
Expand Up @@ -22,6 +22,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@control_auth_token = nil
@config_file = nil
@command = nil
@environment = ENV['RACK_ENV'] || "development"

@argv = argv.dup
@stdout = stdout
Expand Down Expand Up @@ -59,6 +60,11 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@config_file = arg
end

o.on "-e", "--environment ENVIRONMENT",
"The environment to run the Rack app on (default development)" do |arg|
@environment = arg
end

o.on_tail("-H", "--help", "Show this message") do
@stdout.puts o
exit
Expand All @@ -76,8 +82,10 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@command = argv.shift

unless @config_file == '-'
if @config_file.nil? and File.exist?('config/puma.rb')
@config_file = 'config/puma.rb'
if @config_file.nil?
@config_file = %W(config/puma/#{@environment}.rb config/puma.rb).find do |f|
File.exist?(f)
end
end

if @config_file
Expand Down Expand Up @@ -258,6 +266,7 @@ def start
run_args += ["--control-url", @control_url] if @control_url
run_args += ["--control-token", @control_auth_token] if @control_auth_token
run_args += ["-C", @config_file] if @config_file
run_args += ["-e", @environment] if @environment

events = Puma::Events.new @stdout, @stderr

Expand Down
31 changes: 31 additions & 0 deletions test/test_pumactl.rb
Expand Up @@ -29,6 +29,37 @@ def test_config_file
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
end

def test_environment
ENV.delete 'RACK_ENV' # remove from travis
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "development", control_cli.instance_variable_get("@environment")
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
assert_equal "test", control_cli.instance_variable_get("@environment")
end

def test_config_file_exist
ENV.delete 'RACK_ENV' # remove from travis
port = 6001
Dir.mktmpdir do |d|
Dir.chdir(d) do
FileUtils.mkdir("config")
File.open("config/puma.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "config/puma.rb",
control_cli.instance_variable_get("@config_file")
end
end
Dir.mktmpdir do |d|
Dir.chdir(d) do
FileUtils.mkdir_p("config/puma")
File.open("config/puma/development.rb", "w") { |f| f << "port #{port}" }
control_cli = Puma::ControlCLI.new ["halt"]
assert_equal "config/puma/development.rb",
control_cli.instance_variable_get("@config_file")
end
end
end

def test_control_no_token
opts = [
"--config-file", "test/config/control_no_token.rb",
Expand Down