aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-08 10:00:48 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-08 10:10:24 +0100
commit25ee6490e4e29a69b736ea95a2b198fcc7f98751 (patch)
treed0af905b76e0ba36447ddb8889da8d4422b3483c /config
parent7260bdfbee719a93ffe6752ff08c3a77bc198b2d (diff)
downloadoperum-25ee6490e4e29a69b736ea95a2b198fcc7f98751.tar.gz
operum-25ee6490e4e29a69b736ea95a2b198fcc7f98751.zip
Upgrade to Rails 8
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'config')
-rw-r--r--config/application.rb2
-rw-r--r--config/environments/development.rb41
-rw-r--r--config/environments/production.rb91
-rw-r--r--config/environments/test.rb25
-rw-r--r--config/initializers/assets.rb5
-rw-r--r--config/initializers/filter_parameter_logging.rb9
-rw-r--r--config/initializers/new_framework_defaults_8_0.rb33
-rw-r--r--config/puma.rb58
8 files changed, 133 insertions, 131 deletions
diff --git a/config/application.rb b/config/application.rb
index 1c5d017..a3d35c6 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -11,7 +11,7 @@ Bundler.require(*Rails.groups)
module Operum
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
- config.load_defaults 7.1
+ config.load_defaults 8.0
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 80e0587..2282e04 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -5,9 +5,7 @@ require 'active_support/core_ext/integer/time'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
- # In the development environment your application's code is reloaded any time
- # it changes. This slows down response time but is perfect for development
- # since you don't have to restart the web server when you make code changes.
+ # Make code changes take effect immediately without server restart.
config.enable_reloading = true
# Do not eager load code on boot.
@@ -16,22 +14,18 @@ Rails.application.configure do
# Show full error reports.
config.consider_all_requests_local = true
- # Enable server timing
+ # Enable server timing.
config.server_timing = true
- # Enable/disable caching. By default caching is disabled.
- # Run rails dev:cache to toggle caching.
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
+ # Run rails dev:cache to toggle Action Controller caching.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
- config.action_controller.enable_fragment_cache_logging = true
-
config.cache_store = :memory_store
- config.public_file_server.headers = {
- 'Cache-Control' => "public, max-age=#{2.days.to_i}"
- }
+ config.action_controller.enable_fragment_cache_logging = true
+ config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" }
else
config.action_controller.perform_caching = false
-
config.cache_store = :null_store
end
@@ -41,38 +35,39 @@ Rails.application.configure do
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
+ # Make template changes take effect immediately.
config.action_mailer.perform_caching = false
+ # Set localhost to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
+
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
- # Raise exceptions for disallowed deprecations.
- config.active_support.disallowed_deprecation = :raise
-
- # Tell Active Support which deprecation messages to disallow.
- config.active_support.disallowed_deprecation_warnings = []
-
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
+ # Append comments with runtime information tags to SQL queries in logs.
+ config.active_record.query_log_tags_enabled = true
+
# Highlight code that enqueued background job in logs.
config.active_job.verbose_enqueue_logs = true
- # Suppress logger output for asset requests.
- config.assets.quiet = true
-
# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true
# Annotate rendered view with file names.
- # config.action_view.annotate_rendered_view_with_filenames = true
+ config.action_view.annotate_rendered_view_with_filenames = true
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
- # Raise error when a before_action's only/except options reference missing actions
+ # Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
+
+ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
+ # config.generators.apply_rubocop_autocorrect_after_generate!
end
diff --git a/config/environments/production.rb b/config/environments/production.rb
index d148180..b4b55ce 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -8,99 +8,84 @@ Rails.application.configure do
# Code is not reloaded between requests.
config.enable_reloading = false
- # Eager load code on boot. This eager loads most of Rails and
- # your application in memory, allowing both threaded web servers
- # and those relying on copy on write to perform better.
- # Rake tasks automatically ignore this option for performance.
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
config.eager_load = true
- # Full error reports are disabled and caching is turned on.
+ # Full error reports are disabled.
config.consider_all_requests_local = false
- config.action_controller.perform_caching = true
-
- # Ensures that a master key has been made available in
- # ENV["RAILS_MASTER_KEY"], config/master.key, or an environment key such as
- # config/credentials/production.key. This key is used to decrypt credentials
- # (and other encrypted files).
- # config.require_master_key = true
-
- # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.
- # config.public_file_server.enabled = false
- # Compress CSS using a preprocessor.
- # config.assets.css_compressor = :sass
+ # Turn on fragment caching in view templates.
+ config.action_controller.perform_caching = true
- # Do not fall back to assets pipeline if a precompiled asset is missed.
- config.assets.compile = false
+ # Cache assets for far-future expiry since they are all digest stamped.
+ config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" }
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.asset_host = "http://assets.example.com"
- # Specifies the header that your server uses for sending files.
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
- # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
-
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
- # Mount Action Cable outside main process or domain.
- # config.action_cable.mount_path = nil
- # config.action_cable.url = "wss://example.com/cable"
- # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
-
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
- # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.
- # config.assume_ssl = true
+ config.assume_ssl = true
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
- # Log to STDOUT by default
- config.logger = ActiveSupport::Logger.new($stdout)
- .tap { |logger| logger.formatter = Logger::Formatter.new }
- .then { |logger| ActiveSupport::TaggedLogging.new(logger) }
+ # Skip http-to-https redirect for the default health check endpoint.
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
- # Prepend all log lines with the following tags.
+ # Log to STDOUT with the current request id as a default log tag.
config.log_tags = [:request_id]
+ config.logger = ActiveSupport::TaggedLogging.logger($stdout)
- # "info" includes generic and useful information about system operation, but
- # avoids logging too much information to avoid inadvertent exposure of
- # personally identifiable information (PII). If you want to log everything,
- # set the level to "debug".
+ # Change to "debug" to log everything (including potentially personally-identifiable information!)
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
- # Use a different cache store in production.
+ # Prevent health checks from clogging up the logs.
+ config.silence_healthcheck_path = '/up'
+
+ # Don't log any deprecations.
+ config.active_support.report_deprecations = false
+
+ # Replace the default in-process memory cache store with a durable alternative.
# config.cache_store = :mem_cache_store
- # Use a real queuing backend for Active Job (and separate queues per environment).
+ # Replace the default in-process and non-durable queuing backend for Active Job.
# config.active_job.queue_adapter = :resque
- # config.active_job.queue_name_prefix = "operum_production"
-
- config.action_mailer.perform_caching = false
- # Ignore bad email addresses and do not raise email delivery errors. Set this
- # to true and configure the email server for immediate delivery to raise
- # delivery errors.
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
+ # Set host to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: 'llibres.mssola.com' }
+
+ # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit.
+ # config.action_mailer.smtp_settings = {
+ # user_name: Rails.application.credentials.dig(:smtp, :user_name),
+ # password: Rails.application.credentials.dig(:smtp, :password),
+ # address: "smtp.example.com",
+ # port: 587,
+ # authentication: :plain
+ # }
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
- # Don't log any deprecations.
- config.active_support.report_deprecations = false
-
- # In our case having SQLite in production is actually just fine!
- config.active_record.sqlite3_production_warning = false
-
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
+ # Only use :id for inspections in production.
+ config.active_record.attributes_for_inspect = [:id]
+
# Enable DNS rebinding protection and other `Host` header attacks.
# config.hosts = [
# "example.com", # Allow requests from example.com
# /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
# ]
+ #
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index f1d2fb5..37fc1f7 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require 'active_support/core_ext/integer/time'
-
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
@@ -19,15 +17,11 @@ Rails.application.configure do
# loading is working properly before deploying your code.
config.eager_load = ENV['CI'].present?
- # Configure public file server for tests with Cache-Control for performance.
- config.public_file_server.enabled = true
- config.public_file_server.headers = {
- 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
- }
+ # Configure public file server for tests with cache-control for performance.
+ config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' }
- # Show full error reports and disable caching.
+ # Show full error reports.
config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
config.cache_store = :null_store
# Render exception templates for rescuable exceptions and raise for other exceptions.
@@ -39,28 +33,23 @@ Rails.application.configure do
# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test
- config.action_mailer.perform_caching = false
-
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
+ # Set host to be used by links generated in mailer templates.
+ config.action_mailer.default_url_options = { host: 'example.com' }
+
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
- # Raise exceptions for disallowed deprecations.
- config.active_support.disallowed_deprecation = :raise
-
- # Tell Active Support which deprecation messages to disallow.
- config.active_support.disallowed_deprecation_warnings = []
-
# Raises error for missing translations.
# config.i18n.raise_on_missing_translations = true
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
- # Raise error when a before_action's only/except options reference missing actions
+ # Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true
end
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index bcafccd..019d0bb 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -7,8 +7,3 @@ Rails.application.config.assets.version = '1.0'
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
-
-# Precompile additional assets.
-# application.js, application.css, and all non-JS/CSS in the app/assets
-# folder are already added.
-# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
index 7231487..a0fdfc4 100644
--- a/config/initializers/filter_parameter_logging.rb
+++ b/config/initializers/filter_parameter_logging.rb
@@ -2,10 +2,9 @@
# Be sure to restart your server when you modify this file.
-# Configure parameters to be partially matched (e.g. passw matches password) and
-# filtered from the log file. Use this to limit dissemination of sensitive
-# information. See the ActiveSupport::ParameterFilter documentation for
-# supported notations and behaviors.
+# Configure parameters to be partially matched (e.g. passw matches password) and filtered
+# from the log file. Use this to limit dissemination of sensitive information.
+# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
Rails.application.config.filter_parameters += %i[
- passw secret token _key crypt salt certificate otp ssn
+ passw email secret token _key crypt salt certificate otp ssn cvv cvc
]
diff --git a/config/initializers/new_framework_defaults_8_0.rb b/config/initializers/new_framework_defaults_8_0.rb
new file mode 100644
index 0000000..0ca4b07
--- /dev/null
+++ b/config/initializers/new_framework_defaults_8_0.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+# Be sure to restart your server when you modify this file.
+#
+# This file eases your Rails 8.0 framework defaults upgrade.
+#
+# Uncomment each configuration one by one to switch to the new default.
+# Once your application is ready to run with all new defaults, you can remove
+# this file and set the `config.load_defaults` to `8.0`.
+#
+# Read the Guide for Upgrading Ruby on Rails for more info on each option.
+# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html
+
+###
+# Specifies whether `to_time` methods preserve the UTC offset of their receivers or preserves
+# the timezone.
+# If set to `:zone`, `to_time` methods will use the timezone of their receivers.
+# If set to `:offset`, `to_time` methods will use the UTC offset.
+# If `false`, `to_time` methods will convert to the local system UTC offset instead.
+#++
+Rails.application.config.active_support.to_time_preserves_timezone = :zone
+
+###
+# When both `If-Modified-Since` and `If-None-Match` are provided by the client
+# only consider `If-None-Match` as specified by RFC 7232 Section 6.
+# If set to `false` both conditions need to be satisfied.
+#++
+Rails.application.config.action_dispatch.strict_freshness = true
+
+###
+# Set `Regexp.timeout` to `1`s by default to improve security over Regexp Denial-of-Service attacks.
+#++
+Regexp.timeout = 1
diff --git a/config/puma.rb b/config/puma.rb
index 7ed4157..d398337 100644
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -3,35 +3,41 @@
# This configuration file will be evaluated by Puma. The top-level methods that
# are invoked here are part of Puma's configuration DSL. For more information
# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
-
-# Puma can serve each request in a thread from an internal thread pool.
-# The `threads` method setting takes two numbers: a minimum and maximum.
-# Any libraries that use thread pools should be configured to match
-# the maximum value specified for Puma. Default is set to 5 threads for minimum
-# and maximum; this matches the default thread size of Active Record.
-max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
-min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count }
-threads min_threads_count, max_threads_count
-
-# Specifies that the worker count should equal the number of processors in production.
-if ENV['RAILS_ENV'] == 'production'
- require 'concurrent-ruby'
- worker_count = Integer(ENV.fetch('WEB_CONCURRENCY') { Concurrent.physical_processor_count })
- workers worker_count if worker_count > 1
-end
-
-# Specifies the `worker_timeout` threshold that Puma will use to wait before
-# terminating a worker in development environments.
-worker_timeout 3600 if ENV.fetch('RAILS_ENV', 'development') == 'development'
+#
+# Puma starts a configurable number of processes (workers) and each process
+# serves each request in a thread from an internal thread pool.
+#
+# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
+# should only set this value when you want to run 2 or more workers. The
+# default is already 1.
+#
+# The ideal number of threads per worker depends both on how much time the
+# application spends waiting for IO operations and on how much you wish to
+# prioritize throughput over latency.
+#
+# As a rule of thumb, increasing the number of threads will increase how much
+# traffic a given process can handle (throughput), but due to CRuby's
+# Global VM Lock (GVL) it has diminishing returns and will degrade the
+# response time (latency) of the application.
+#
+# The default is set to 3 threads as it's deemed a decent compromise between
+# throughput and latency for the average Rails application.
+#
+# Any libraries that use a connection pool or another resource pool should
+# be configured to provide at least as many connections as the number of
+# threads. This includes Active Record's `pool` parameter in `database.yml`.
+threads_count = ENV.fetch('RAILS_MAX_THREADS', 3)
+threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
port ENV.fetch('PORT', 3000)
-# Specifies the `environment` that Puma will run in.
-environment ENV.fetch('RAILS_ENV', 'development')
-
-# Specifies the `pidfile` that Puma will use.
-pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid')
-
# Allow puma to be restarted by `bin/rails restart` command.
plugin :tmp_restart
+
+# Run the Solid Queue supervisor inside of Puma for single-server deployments
+plugin :solid_queue if ENV['SOLID_QUEUE_IN_PUMA']
+
+# Specify the PID file. Defaults to tmp/pids/server.pid in development.
+# In other environments, only set the PID file if requested.
+pidfile ENV['PIDFILE'] if ENV['PIDFILE']