From 6d413e454117aa748b8594a78f5c6d0becb28f00 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Tue, 5 Mar 2024 12:56:44 -0500 Subject: [PATCH] first commit to upgrade to rails 7.0 (#3353) This is the first pass at upgrading to rails 7. Other than basic upgrade procedures it: * changes the file routes a little bit due to a rails 7 bug. * locks nokogiri for ruby 2.7 support (Ubuntu 20.04) * locks net-imap for ruby 2.7 support (Ubuntu 20.04) --- apps/dashboard/Gemfile | 10 +- apps/dashboard/Gemfile.lock | 133 ++++++++-------- .../config/environments/development.rb | 20 +-- .../config/environments/production.rb | 37 +---- apps/dashboard/config/environments/test.rb | 17 ++- .../initializers/filter_parameter_logging.rb | 4 +- .../new_framework_defaults_7_0.rb | 143 ++++++++++++++++++ apps/dashboard/config/routes.rb | 3 +- apps/dashboard/test/test_helper.rb | 7 +- 9 files changed, 257 insertions(+), 117 deletions(-) create mode 100644 apps/dashboard/config/initializers/new_framework_defaults_7_0.rb diff --git a/apps/dashboard/Gemfile b/apps/dashboard/Gemfile index 6cd4f78423..912388956d 100644 --- a/apps/dashboard/Gemfile +++ b/apps/dashboard/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '6.1.7.6' +gem 'rails', '7.0.8' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' @@ -38,6 +38,11 @@ group :development do # gem 'web-console', '~> 2.0' end +# lock nokogiri & net-imap to versions that are compatible with ruby 2.7.0 +# Ubuntu 20.04 uses. +gem 'nokogiri', '~> 1.15', '< 1.16' +gem 'net-imap', '~> 0.3', '< 0.4' + # Extra third-party gems gem 'dotenv-rails', '~> 2.1' gem 'redcarpet', '~> 3.3' @@ -53,6 +58,8 @@ gem 'rss', '~> 0.2' gem 'jsbundling-rails', '~> 1.0' gem 'cssbundling-rails', '~> 1.1' +# should upgrade to propshaft - only have an issue with fontawesome icons +gem 'sprockets-rails', '>= 2.0.0' # OOD specific gems gem 'ood_support', '~> 0.0.2' @@ -66,4 +73,3 @@ gem "sinatra", require: false gem "sinatra-contrib", require: false gem "erubi", require: false gem "dalli", require: false - diff --git a/apps/dashboard/Gemfile.lock b/apps/dashboard/Gemfile.lock index f542780bce..005edddc8f 100644 --- a/apps/dashboard/Gemfile.lock +++ b/apps/dashboard/Gemfile.lock @@ -1,65 +1,71 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.6) - actionpack (= 6.1.7.6) - activesupport (= 6.1.7.6) + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.6) - actionpack (= 6.1.7.6) - activejob (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) mail (>= 2.7.1) - actionmailer (6.1.7.6) - actionpack (= 6.1.7.6) - actionview (= 6.1.7.6) - activejob (= 6.1.7.6) - activesupport (= 6.1.7.6) + net-imap + net-pop + net-smtp + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.7.6) - actionview (= 6.1.7.6) - activesupport (= 6.1.7.6) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) + rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.6) - actionpack (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.7.6) - activesupport (= 6.1.7.6) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7.6) - activesupport (= 6.1.7.6) + activejob (7.0.8) + activesupport (= 7.0.8) globalid (>= 0.3.6) - activemodel (6.1.7.6) - activesupport (= 6.1.7.6) - activerecord (6.1.7.6) - activemodel (= 6.1.7.6) - activesupport (= 6.1.7.6) - activestorage (6.1.7.6) - actionpack (= 6.1.7.6) - activejob (= 6.1.7.6) - activerecord (= 6.1.7.6) - activesupport (= 6.1.7.6) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.6) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) autoprefixer-rails (10.2.5.1) @@ -142,7 +148,7 @@ GEM mime-types-data (3.2023.1205) mini_mime (1.1.5) mini_portile2 (2.8.5) - minitest (5.21.2) + minitest (5.22.0) mocha (2.1.0) ruby2_keywords (>= 0.0.5) multi_json (1.15.0) @@ -162,11 +168,11 @@ GEM nokogiri (1.15.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) - ood_appkit (2.1.1) + ood_appkit (2.1.4) addressable (~> 2.4) lograge (~> 0.3) ood_core (~> 0.1) - rails (>= 6.0.0, < 7) + rails (>= 6.0.0) redcarpet (~> 3.2) ood_core (0.24.2) ffi (~> 1.9, >= 1.9.6) @@ -185,21 +191,20 @@ GEM rack (~> 2.2, >= 2.2.4) rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7.6) - actioncable (= 6.1.7.6) - actionmailbox (= 6.1.7.6) - actionmailer (= 6.1.7.6) - actionpack (= 6.1.7.6) - actiontext (= 6.1.7.6) - actionview (= 6.1.7.6) - activejob (= 6.1.7.6) - activemodel (= 6.1.7.6) - activerecord (= 6.1.7.6) - activestorage (= 6.1.7.6) - activesupport (= 6.1.7.6) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) bundler (>= 1.15.0) - railties (= 6.1.7.6) - sprockets-rails (>= 2.0.0) + railties (= 7.0.8) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -207,18 +212,19 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (6.1.7.6) - actionpack (= 6.1.7.6) - activesupport (= 6.1.7.6) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rake (13.1.0) rdoc (6.6.2) psych (>= 4.0.0) redcarpet (3.6.0) regexp_parser (2.9.0) - request_store (1.5.1) + request_store (1.6.0) rack (>= 1.4) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) @@ -269,7 +275,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.12) + zeitwerk (2.6.13) zip_tricks (5.6.0) PLATFORMS @@ -292,11 +298,13 @@ DEPENDENCIES jsbundling-rails (~> 1.0) local_time (~> 1.0.3) mocha (~> 2.1) + net-imap (~> 0.3, < 0.4) + nokogiri (~> 1.15, < 1.16) ood_appkit (~> 2.1.0) ood_core (~> 0.24.1) ood_support (~> 0.0.2) pbs (~> 2.2.1) - rails (= 6.1.7.6) + rails (= 7.0.8) redcarpet (~> 3.3) rest-client (~> 2.0) rss (~> 0.2) @@ -304,6 +312,7 @@ DEPENDENCIES selenium-webdriver (= 4.5.0) sinatra sinatra-contrib + sprockets-rails (>= 2.0.0) timecop (~> 0.9) webrick zip_tricks (~> 5.5) diff --git a/apps/dashboard/config/environments/development.rb b/apps/dashboard/config/environments/development.rb index bb111e48ce..fbc3af60b8 100644 --- a/apps/dashboard/config/environments/development.rb +++ b/apps/dashboard/config/environments/development.rb @@ -16,20 +16,26 @@ # Show full error reports. config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + 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}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false + + config.cache_store = :null_store end - config.cache_store = :memory_store + config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_caching = false @@ -42,21 +48,17 @@ # 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 - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker - # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true - config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new \ - min_threads: 1, max_threads: 1 + config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new(min_threads: 1, max_threads: 1) config.hosts = nil end diff --git a/apps/dashboard/config/environments/production.rb b/apps/dashboard/config/environments/production.rb index 1f1e3e3d09..28749c32e7 100644 --- a/apps/dashboard/config/environments/production.rb +++ b/apps/dashboard/config/environments/production.rb @@ -12,7 +12,6 @@ # 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. - # TODO: find out why is this set to false config.eager_load = false # Full error reports are disabled and caching is turned on. @@ -56,14 +55,8 @@ # Locales are handled in config/initializers/locales.rb. - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Log disallowed deprecations. - config.active_support.disallowed_deprecation = :log - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] + # Don't log any deprecations. + config.active_support.report_deprecations = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new @@ -73,34 +66,12 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new($stdout) + logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session - - config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new \ - min_threads: 1, max_threads: 1 + config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new(min_threads: 1, max_threads: 1) config.hosts = ENV['ALLOWED_HOSTS'].nil? ? nil : ENV['ALLOWED_HOSTS'].split(',') end diff --git a/apps/dashboard/config/environments/test.rb b/apps/dashboard/config/environments/test.rb index 1e57561bb4..47a96e152f 100644 --- a/apps/dashboard/config/environments/test.rb +++ b/apps/dashboard/config/environments/test.rb @@ -8,11 +8,12 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. + # Turn false under Spring and add config.action_view.cache_template_loading = true. config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. @@ -34,6 +35,11 @@ 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 + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -49,10 +55,9 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new \ - min_threads: 1, max_threads: 1 + config.active_job.queue_adapter = ActiveJob::QueueAdapters::AsyncAdapter.new(min_threads: 1, max_threads: 1) - config.paths["app/views"].unshift "test/fixtures/config/views" + config.paths['app/views'].unshift('test/fixtures/config/views') config.hosts = nil end diff --git a/apps/dashboard/config/initializers/filter_parameter_logging.rb b/apps/dashboard/config/initializers/filter_parameter_logging.rb index 4b34a03668..adc6568ce8 100644 --- a/apps/dashboard/config/initializers/filter_parameter_logging.rb +++ b/apps/dashboard/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. +# Configure parameters to be 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 += [ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/apps/dashboard/config/initializers/new_framework_defaults_7_0.rb b/apps/dashboard/config/initializers/new_framework_defaults_7_0.rb new file mode 100644 index 0000000000..b13ef5ed16 --- /dev/null +++ b/apps/dashboard/config/initializers/new_framework_defaults_7_0.rb @@ -0,0 +1,143 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.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 `7.0`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +# `button_to` view helper will render `