Skip to content

AP-588 Upgrade Rails to 8.0.x#20

Open
steve-sullivan wants to merge 13 commits intomainfrom
AP-588-upgrade-dependencies
Open

AP-588 Upgrade Rails to 8.0.x#20
steve-sullivan wants to merge 13 commits intomainfrom
AP-588-upgrade-dependencies

Conversation

@steve-sullivan
Copy link
Copy Markdown

Upgrade Rails and dependencies to 8.0.x

  • Upgrade Rails to 8.0.5
  • Upgrade omniauth-cas to 3.x and add CSRF protection
  • Update Puma, RSpec, RuboCop, and Berkeley Library gems
  • Fix Rails 8 changes (ActiveRecord connection pool, status codes)
  • Update auth for OmniAuth 2
  • Fix CI (db task + secret_key_base requirement)

Copy link
Copy Markdown
Member

@anarchivist anarchivist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good - rw+c. most of my comments are minor. you might want to ask Anna to look at this, too.

@steve-sullivan steve-sullivan requested a review from awilfox March 26, 2026 23:22
Copy link
Copy Markdown
Member

@awilfox awilfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly good, just a few nits. However, it looks like rails app:update wasn't run, similar to what happened at the beginning of BerkeleyLibrary/UCBEARS#21. Can you make sure that's run and the configuration files are updated appropriately? I described how to do that in the UCBEARS MR.

Comment on lines 9 to 10
ActiveRecord::Base.connection_pool.with_connection(&:active?)
rescue PG::ConnectionBad
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we upgraded Framework to 8.0, the suggested way to do it was to use verify! on the connection object. We also needed to add ActiveRecord::DatabaseConnectionError to the rescue block, but I'm not sure if that's because of verify! or because in general Rails 8 can raise that.

Suggested change
ActiveRecord::Base.connection_pool.with_connection(&:active?)
rescue PG::ConnectionBad
ActiveRecord::Base.connection.verify!
rescue PG::ConnectionBad, ActiveRecord::DatabaseConnectionError

I don't mind doing it the way already here; I just haven't seen it before. (will this raise if there are no active connections, or just return nil?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch - I've updated to use verify! instead of active!

Gemfile.lock Outdated

RUBY VERSION
ruby 3.3.9p170
ruby 3.3.9p170
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be moving this to 3.3.11 as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you think it's worth pinning the base image to 3.3.11?

Right now:
FROM ruby:3.3-slim AS base

I could pin it to 3.3.11, but then future bumps would need to be manually updated.

Copy link
Copy Markdown
Member

@anarchivist anarchivist Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little complicated, but we shouldn't change the Dockerfile.

In practice, we should be updating the Ruby version in the Gemfile.lock (or ship with a .ruby-version file), but it doesn't really have too much of an effect here. IIRC, this specifies the version that bundle was run under.

If we rebuild the image (e.g., after a merged new pull request), it will fetch the latest tag of ruby:3.3-slim, which updates the Ruby patch version under the hood.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, yeah, my container was already running 3.3.11, but the lockfile wasn't updating. Finally did with this command:
docker compose run --rm app bundle update --ruby

Gemfile Outdated
gem 'rack-cors'
gem 'rails', '~> 7.0.4'
gem 'ransack', '~> 2.6'
gem 'rails', '~> 8.0.4'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They've already snuck out another release while this was being worked on!

Suggested change
gem 'rails', '~> 8.0.4'
gem 'rails', '~> 8.0.5'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those sneaky guys... Updated to 8.0.5!

- name: Validate database migrations
env:
RAILS_ENV: production
SECRET_KEY_BASE: dummy
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to test the Rails secrets stuff here like we do in Framework?

See BerkeleyLibrary/framework@6cf75564ef, specifically .github/workflows/build.yml and docker-compose.ci.yml. This makes a "real" (throwaway) secret, and that ensures the app is going to read it from the correct place in production.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to shoe-horn that kind of test stage into the build.yml, but looks like it would take a little more work, galc-ui setup is a bit different than framework... so reverted back to the secret_key_base->dummy.

@steve-sullivan steve-sullivan requested a review from awilfox March 31, 2026 20:59
Copy link
Copy Markdown
Member

@awilfox awilfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're quite close! Luckily there aren't too many new configurations it found for 8.0. I'm not sure about 7.1 and 7.2; you may need to step each one of those as well.

You don't need to do each one, since some of them are obviously not going to affect us (old IE support and the like). The main ones I'm concerned about from 7.1 and 7.2 are the Postgres adaptor settings and YJIT.

@@ -26,6 +26,10 @@
module GalcApi
class Application < Rails::Application
config.load_defaults 7.0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be preferable to use the initialiser to test each new configuration, and assuming each one works fine, to change this to 8.0.

Suggested change
config.load_defaults 7.0
config.load_defaults 8.0

Comment on lines +5 to +7
# 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`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly this.

@awilfox
Copy link
Copy Markdown
Member

awilfox commented Mar 31, 2026

To be clear, you can download the 7.1 and 7.2 files I linked above and put them in config/initializers/ and perform the same procedure as is described in the 8.0 file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants