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

Add Puma to dependencies #214

Merged
merged 1 commit into from
Oct 26, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- Add Puma to dependencies ([#214](https://github.com/alphagov/govuk_app_config/pull/214)).

# 4.0.1

- Update Content Security Policy with new klick2contact.com subdomain ([#213](https://github.com/alphagov/govuk_app_config/pull/213)).
Expand Down
1 change: 1 addition & 0 deletions govuk_app_config.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
spec.require_paths = %w[lib]

spec.add_dependency "logstasher", ">= 1.2.2", "< 2.2.0"
spec.add_dependency "puma", "~> 5.0"
spec.add_dependency "sentry-rails", "~> 4.5.0"
spec.add_dependency "sentry-ruby", "~> 4.5.0"
spec.add_dependency "statsd-ruby", "~> 1.5.0"
Expand Down
37 changes: 37 additions & 0 deletions lib/govuk_app_config/govuk_puma.rb
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