Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinkelly committed Nov 22, 2024
1 parent 93bfd00 commit ce9f9f7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 72 deletions.
11 changes: 0 additions & 11 deletions variants/backend-base/Gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ gem "sentry-rails"
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
# gem "solid_cache"
# gem "solid_queue"
# gem "solid_cable"

# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
gem "kamal", require: false

gem "rack-canonical-host"

# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
Expand All @@ -43,9 +35,6 @@ gem "stimulus-rails"
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
# gem "thruster", require: false

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

Expand Down
116 changes: 55 additions & 61 deletions variants/backend-base/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,66 +36,60 @@
'ENV.fetch("RAILS_LOG_LEVEL", "info")',
'ENV.fetch("RAILS_LOG_LEVEL", ENV.fetch("LOG_LEVEL", "info"))'

# insert_into_file "config/environments/production.rb",
# after: /.*config\.public_file_server\.enabled.*\n/ do
# <<~'RUBY'

# # Ensure that Rails sets appropriate caching headers on static assets if
# # Rails is serving static assets in production e.g. on Heroku
# #
# # Overview of Cache-control values:
# #
# # max-age=<seconds>
# # The maximum amount of time a resource is considered fresh.
# #
# # s-maxage=<seconds>
# # Overrides max-age or the Expires header, but only for shared
# # caches (e.g., proxies). Ignored by private caches.
# #
# # More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
# #
# # Our Cache-Control header:
# #
# # * It tells all caches (both proxies like Cloudflare and the users web
# # browser) that the asset can be cached.
# # * It tells shared caches (e.g. Cloudflare) that they can cache it for 365 days
# # * It tells browsers that they should cache for 365 days
# #
# # Cloudflare will respect s-maxage if it is set so change that value if you
# # want Cloudflare to cache differently than then browser.
# #
# config.public_file_server.headers = {
# "Cache-Control" => "public, s-maxage=#{365.days.seconds}, max-age=#{365.days.seconds}"
# }

# #########################

# # Rails 8 default:
# # config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
# TODO: https://github.com/ackama/rails-template/issues/569
insert_into_file "config/environments/production.rb",
after: /.*config\.public_file_server\.enabled.*\n/ do
<<~'RUBY'
# RUBY
# end
# Ensure that Rails sets appropriate caching headers on static assets if
# Rails is serving static assets in production e.g. on Heroku
#
# Overview of Cache-control values:
#
# max-age=<seconds>
# The maximum amount of time a resource is considered fresh.
#
# s-maxage=<seconds>
# Overrides max-age or the Expires header, but only for shared
# caches (e.g., proxies). Ignored by private caches.
#
# More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
#
# Our Cache-Control header:
#
# * It tells all caches (both proxies like Cloudflare and the users web
# browser) that the asset can be cached.
# * It tells shared caches (e.g. Cloudflare) that they can cache it for 365 days
# * It tells browsers that they should cache for 365 days
#
# Cloudflare will respect s-maxage if it is set so change that value if you
# want Cloudflare to cache differently than then browser.
#
config.public_file_server.headers = {
"Cache-Control" => "public, s-maxage=#{365.days.seconds}, max-age=#{365.days.seconds}"
}
RUBY
end

# TODO: this won't match anything because 8 uses solid_cache
# insert_into_file "config/environments/production.rb",
# after: /.*config.cache_store = :mem_cache_store\n/ do
# <<~RUBY
# if ENV.fetch("RAILS_CACHE_REDIS_URL", nil)
# config.cache_store = :redis_cache_store, {
# url: ENV.fetch("RAILS_CACHE_REDIS_URL"),
# ##
# # Configuring a connection pool for Redis as Rails cache is documented in:
# #
# # * https://edgeguides.rubyonrails.org/caching_with_rails.html#connection-pool-options
# #
# # but some more details are available in:
# #
# # * https://github.com/rails/rails/blob/a5d1628c79ab89dfae57ec1e1aeca467e29de188/activesupport/lib/active_support/cache.rb#L168-L173
# # * https://github.com/rails/rails/blob/9b4aef4be3dc58eb08f694387857b52be8050954/activesupport/lib/active_support/cache/redis_cache_store.rb#L185-L192
# #
# pool_size: Integer(ENV.fetch("RAILS_MAX_THREADS", 5)), # number of connections **per puma process**
# pool_timeout: 5 # num seconds to wait for a connection
# }
# end
# RUBY
# end
insert_into_file "config/environments/production.rb",
after: /.*config.cache_store = :mem_cache_store\n/ do
<<~RUBY
if ENV.fetch("RAILS_CACHE_REDIS_URL", nil)
config.cache_store = :redis_cache_store, {
url: ENV.fetch("RAILS_CACHE_REDIS_URL"),
##
# Configuring a connection pool for Redis as Rails cache is documented in:
#
# * https://edgeguides.rubyonrails.org/caching_with_rails.html#connection-pool-options
#
# but some more details are available in:
#
# * https://github.com/rails/rails/blob/a5d1628c79ab89dfae57ec1e1aeca467e29de188/activesupport/lib/active_support/cache.rb#L168-L173
# * https://github.com/rails/rails/blob/9b4aef4be3dc58eb08f694387857b52be8050954/activesupport/lib/active_support/cache/redis_cache_store.rb#L185-L192
#
pool_size: Integer(ENV.fetch("RAILS_MAX_THREADS", 5)), # number of connections **per puma process**
pool_timeout: 5 # num seconds to wait for a connection
}
end
RUBY
end

0 comments on commit ce9f9f7

Please sign in to comment.