DMPRoadmap / roadmap

DCC/UC3 collaboration for a data management planning tool
MIT License
102 stars 110 forks source link

Rails 6 #3103

Closed benjaminfaure closed 1 year ago

benjaminfaure commented 2 years ago

Hello everyone,

According to Rails maintenance policy, Rails 5.2 we'll reach its end of life in June 2022 https://guides.rubyonrails.org/maintenance_policy.html

Seems like yet another Rails upgrade is on the horizon.

Rails 7 is already out, I guess they switched to yearly release for major versions of the framework. Hopefully upgrading won't be such a big step anymore

briri commented 2 years ago

Just discovered today that Rails is no longer supporting the Webpacker gem. I learned this after running yarn upgrade and noticing that all of the Karma tests would no longer run due to a mismatch in dependencies for webpack.

Rails 7 moves away from Webpacker and provides 3 new options for how to manage JS

We should also consider upgrading:

benjaminfaure commented 2 years ago

I took some time and tried to upgrade the roadmap code to Rails 6.1.

It went fairly well. I tested some of the feature and with some minor corrections I managed to get the roadmap code to run. I'm not sure how we could start to share the work done on the migration. Should we create a new branch and commit it ?

briri commented 2 years ago

Hi @benjaminfaure I think that's probably the best course of action. Just create a rails_6 branch off of the development branch and push it up to this repository. We can all then work from that branch as we move forward with any upgrade work.

@raycarrick-ed and I will need to remember to keep that new branch up to date if we merge any PRs into dev/master.

pherterich commented 2 years ago

Tagging @gjacob24 here as she wanted to give this an initial look for the DMPonline team

briri commented 2 years ago

Thanks for getting this started @benjaminfaure and for creating the rails_6 branch. We can all begin to work from there (or branched that stem from rails_6).

I was able to get the code up and running but had to add a minor change to the various config/environments/[env].rb files. The change will allow us to add a DMPROADMAP_HOST environment variable so that the new Rails middleware that was introduced to mitigate DNS rebinding attacks will allow us to access the website.

I also ran rspec and am seeing lots of Deprecation warnings and failing tests (although those failures could be due to changes in the rspec framework and not the app itself). I don't think these are too bad though, probably only a few updates needed to fix most of the warnings/errors. For example:

> rspec spec/controllers/answers_controller_spec.rb 

Randomized with seed 30811
DEPRECATION WARNING: Calling `<<` to an ActiveModel::Errors message array in order to add an error is deprecated. Please call `ActiveModel::Errors#add` instead. (called from validate at /home/ec2-user/environment/roadmap/app/validators/template_links_validator.rb:23)
F
...

Failures:

  1) AnswersController POST /answers/create_or_update fails due to Plan not found
     Failure/Error: template = create(:template, phases: 1, sections: 1, questions: 1)

     ActiveRecord::RecordInvalid:
       Validation failed: Links A hash is expected for links
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/evaluation.rb:18:in `create'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:12:in `block in result'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:9:in `tap'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:9:in `result'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/factory.rb:43:in `run'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:29:in `block in run'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:28:in `run'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/factory_bot-6.2.1/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
     # ./spec/controllers/answers_controller_spec.rb:9:in `block (2 levels) in <top (required)>'
     # /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <main>'

We're going to need to go through the upgrade docs:

And then fix any failing tests and deprecation warnings.

Once all of that is squared away we can look into upgrading Ruby and individual gems where applicable.

briri commented 2 years ago

Added a new wiki page to record upgrade notes: https://github.com/DMPRoadmap/roadmap/wiki/Rails-Upgrade-Notes

The intended audience would be developers who manage their own instances and may need to upgrade their own cutomizations

briri commented 2 years ago

I was just doing some reading on Rails 7 and discovered that they're moving away from Webpacker and UJS (which they introduced in Rails 5/6). An apparent side effect is that there is no longer support for js.erb (would have been nice if they deprecated instead and made this backwards compatible).

This is going to have a potentially significant impact on us: https://guides.rubyonrails.org/working_with_javascript_in_rails.html

pengyin-shan commented 2 years ago

I was just doing some reading on Rails 7 and discovered that they're moving away from Webpacker and UJS (which they introduced in Rails 5/6). An apparent side effect is that there is no longer support for js.erb (would have been nice if they deprecated instead and made this backwards compatible).

This is going to have a potentially significant impact on us: https://guides.rubyonrails.org/working_with_javascript_in_rails.html

Yes, we also tried to remove webpacker in another project after the Rails upgrade. Just an FYI that the Rails conference is next week (June 15), they might introduce Rails 6/7 features and how to upgrade (mainly Rails 7 I think). I will update here if I find anything helpful for us.

briri commented 2 years ago

Thanks @pengyin-shan!

I find it super frustrating that they would not make something like that backwards compatible since they introduced it and guided us all to adopt it :/

pengyin-shan commented 2 years ago

Thanks @pengyin-shan!

I find it super frustrating that they would not make something like that backwards compatible since they introduced it and guided us all to adopt it :/

I personally feel that handling javascript is the 'special' (?) part of the Rails framework, compared to other frameworks because the MVC style is more strictly maintained in Rails. Now since other frameworks are becoming more flexible in interacting with js (like node, which is easy to add front-end framework like react or angular), Rails team is also trying to catch the trend. But this is a periodical pain because now the framework needs to balance between strict MVC rules and client-side interactions.

pengyin-shan commented 2 years ago

I was just doing some reading on Rails 7 and discovered that they're moving away from Webpacker and UJS (which they introduced in Rails 5/6). An apparent side effect is that there is no longer support for js.erb (would have been nice if they deprecated instead and made this backwards compatible).

This is going to have a potentially significant impact on us: https://guides.rubyonrails.org/working_with_javascript_in_rails.html

As for js.erb, I wonder if it is better for us to start split now (i.e. start to use js in Rails 6) that next year we need to do this again?

briri commented 2 years ago

Agreed, the boundaries between the two have always been a bit strange and hard to manage. There doesn't appear to any official guidance at this point. for example: https://stackoverflow.com/questions/71422105/rails-ajax-rails-is-not-defined-rails-7

This likely means that we cannot move to 7 this summer and will need to deal with it next year. I wonder if its a good opportunity to start moving towards a JS framework like React or Vue. Some of my colleagues have done this in their Rails projects and they've been able to manage it without having to rewrite the entire application (e.g. they have a single page that is managed with React).

We moved to the js.erb model because most of our individual strengths have been with backend development and Rails. The JS skillset is something we would need training on. Do any of the @DMPRoadmap/devs have experience with React or another JS framework?

@pengyin-shan if you could find out what their official recommendations are at the conference, that would be great!

pengyin-shan commented 2 years ago

@briri for sure I will pay attention to this!

For the adding front-end framework thing, I was recently trying to add react to node (I think a similar way could work for Angular or Vue, not sure about Rails side though).

A possible pattern is that the server-side deals with API only.

For example:

app.get("/api", (req, res) => {
  res.json({ message: "API ready for get request" });
});

And the client side proxy to the server:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:3001"

But I haven't tried rails yet...we need to change a lot using this way. So probably a simple re-write of js.erb is better for now?

benjaminfaure commented 2 years ago

I used React/Redux a few years ago on another project.

I did some tests with React & Rails, if you use this gem https://github.com/reactjs/react-rails you can include React components into html.erb file and pass partial variables as components props.

It's really convenient because it's possible to rewrite parts of the UI and not do a complete overall.

gjacob24 commented 2 years ago

Created a new issue #3187 to keep a track of all the tasks needed to be completed before the rails 6 release. Hope it's useful. I will add tasks to it as I do some user testing. Please edit as required.

StCyr commented 2 years ago

It's a mess here on Ubuntu 22.04

I could not install ruby 2.7 because of an SSL issue (openssl dropped support for an encryption scheme needed to compile ruby 2.7). So I went for ruby 3. This makes me stumble on an issue when running rails credentials:edit. Apparently the cause is that rails 5.2 isn't compatible with ruby 2.7. So I've tried to upgrade to rails 6.1 but roadmap depends on devise_invitable whose latest version depends on `actionmailer´ 5 while rails 6.1 requires actionmailer 6.1

It looks like I'm on a dead-end street; The only solution left for me seems to downgrade openssl on my server... bad :disappointed: