diff --git a/variants/backend-base/Gemfile.tt b/variants/backend-base/Gemfile.tt index 886da35d..b861dab1 100644 --- a/variants/backend-base/Gemfile.tt +++ b/variants/backend-base/Gemfile.tt @@ -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] @@ -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" diff --git a/variants/backend-base/config/environments/production.rb b/variants/backend-base/config/environments/production.rb index c85d06f8..917d9b07 100644 --- a/variants/backend-base/config/environments/production.rb +++ b/variants/backend-base/config/environments/production.rb @@ -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= -# # The maximum amount of time a resource is considered fresh. -# # -# # s-maxage= -# # 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= + # The maximum amount of time a resource is considered fresh. + # + # s-maxage= + # 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