-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds Puma to govuk_app_template's dependencies, along with a config file defining sensible defaults (and trying to keep inline with Unicorn to a large degree). Puma will be used as the default webserver when apps are replatformed to Kubernetes; this commit enables that work to progress using a single source of truth for configuration and following the same practice as we currently use for managing Unicorn.
- Loading branch information
Karl Baker
committed
Oct 26, 2021
1 parent
2d6415f
commit 2df4bd6
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module GovukPuma | ||
def self.configure_rails(config) | ||
config.port ENV.fetch("PORT", 3000) | ||
|
||
config.environment ENV.fetch("RAILS_ENV", "development") | ||
|
||
if ENV["GOVUK_APP_LOGROOT"] | ||
config.stdout_redirect "#{ENV['GOVUK_APP_LOGROOT']}/app.out.log" "#{ENV['GOVUK_APP_LOGROOT']}/app.err.log" | ||
end | ||
|
||
# `worker_timeout` specifies how many seconds Puma will wait before terminating a worker. | ||
timeout = ENV.fetch("RAILS_ENV", "development") == "development" ? 3600 : 15 | ||
config.worker_timeout timeout | ||
|
||
# When changing the min/max threads for Puma, also consider changing ActiveRecord to match. | ||
max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) | ||
min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count) | ||
config.threads min_threads_count, max_threads_count | ||
|
||
# `workers` specifies the number of worker processes that Puma will fork. | ||
# The overall concurrency limit is worker count * max threads per worker. | ||
config.workers ENV.fetch("WEB_CONCURRENCY", 2) | ||
|
||
# `preload_app!` tells Puma to load application code before forking worker processes. | ||
# This reduces RAM wastage by making better use of copy-on-write. | ||
config.preload_app! | ||
|
||
config.before_fork do |_server| | ||
next unless ENV["GOVUK_APP_ROOT"] | ||
|
||
ENV["BUNDLE_GEMFILE"] = "#{ENV['GOVUK_APP_ROOT']}/Gemfile" | ||
end | ||
|
||
# Allow puma to be restarted by `rails restart` command. | ||
config.plugin :tmp_restart | ||
end | ||
end |