From 5d30cfd851c1dfbc307a6fe05640632f5d2c747b Mon Sep 17 00:00:00 2001 From: Luca Guindani Date: Thu, 28 Sep 2023 14:47:03 +0200 Subject: [PATCH] Ruby 3.x support (#527) * Modify Ci to test against 3.x Fork refile gem and patch it to make it 3.x compatible * Fix deprecated methods & improve code style * Fix api tests Update development group gems Update to latest 3.0.x ruby version * Add CI tests against 3.1.x * Update bundler version * Update debase to latest version * Remove debugging configuration for docker * Update simplecov gem * Update project to use ruby 3.1 as main version Add ruby 3.2 to the CI ruby version matrix * Switch to ruby 3.2 as main ruby version * Typo --- .github/workflows/api.yml | 2 +- .github/workflows/ci.yml | 2 +- .ruby-version | 2 +- Gemfile | 12 +++--- Gemfile.lock | 47 +++++++++++------------ README.md | 10 +---- app/controllers/api/v3/base_controller.rb | 2 +- app/controllers/images_controller.rb | 36 ++++++++--------- bin/setup | 4 +- docker-compose.yml | 1 - docker/app.dockerfile | 4 +- docker/config/supervisord-app-dev.conf | 7 ---- docker/worker.dockerfile | 4 +- 13 files changed, 57 insertions(+), 76 deletions(-) diff --git a/.github/workflows/api.yml b/.github/workflows/api.yml index 062943caf..0a6eb07e2 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/api.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - ruby-versions: [ '2.7.5' ] + ruby-versions: [ '3.2.2' ] rubygems-version: [ '3.4.5' ] psql-version: [ '15' ] node-version: [ '18' ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a04a505b2..b15101802 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - ruby-versions: [ '2.7.5' ] + ruby-versions: [ '3.2.2' ] rubygems-version: [ '3.4.5' ] psql-version: [ '15' ] node-version: [ '18' ] diff --git a/.ruby-version b/.ruby-version index 460b6fd40..be94e6f53 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.5 \ No newline at end of file +3.2.2 diff --git a/Gemfile b/Gemfile index 061edee37..4f05ee823 100644 --- a/Gemfile +++ b/Gemfile @@ -42,8 +42,10 @@ gem "rails", '~> 6.1' gem "ranked-model", "~> 0.4" gem 'react-rails', "~> 2.6" gem "recaptcha", "~> 5.6" -gem "redcarpet", "~> 3.5" -gem "refile", github: "refile/refile", require: "refile/rails" +gem "redcarpet", "~> 3.6" +# Use a forked version of refile because main repository is not actively +# maintained anymore and is not compatible with ruby 3.x +gem "refile", git: "https://github.com/catima/refile", tag: "0.6.9", require: "refile/rails" gem "refile-mini_magick", github: "refile/refile-mini_magick" gem 'sassc-rails', "~> 2.1" gem "secure_headers", "~> 6.3" @@ -74,7 +76,7 @@ group :production, :staging, :development do end group :development, :test do - gem "simplecov", "~> 0.20", :require => false + gem "simplecov", "~> 0.22", :require => false gem "byebug", "~> 11.1.3" gem "selenium-webdriver", "~> 4.7.1" end @@ -84,7 +86,7 @@ group :development do gem "awesome_print", "~> 1.8" gem "bcrypt_pbkdf", "~> 1.0", :require => false gem "better_errors", "~> 2.9" - gem "binding_of_caller", "~> 0.8" + gem "binding_of_caller", "~> 1.0" gem "brakeman", "~> 4.10", :require => false gem "faker", "~> 2.15", :require => false gem "letter_opener", "~> 1.7" @@ -98,8 +100,6 @@ group :development do gem "sshkit", "~> 1.21", :require => false gem "terminal-notifier", "~> 2.0", :require => false gem "terminal-notifier-guard", "~> 1.7", :require => false - gem "debase", "~> 0.2.4" - gem "ruby-debug-ide", "~> 0.7.3" platforms :mswin, :mingw, :x64_mingw do gem "tzinfo-data" end diff --git a/Gemfile.lock b/Gemfile.lock index 06f3b160c..6bff825a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,15 @@ GIT panoramic (0.0.7) rails (>= 4.2.0) +GIT + remote: https://github.com/catima/refile + revision: 798ee0f2bdf007b4934c34c8c47db01513bdfabc + tag: 0.6.9 + specs: + refile (0.6.9) + mime-types + sinatra (>= 2.0.0, <= 4.0.0) + GIT remote: https://github.com/refile/refile-mini_magick.git revision: 5c7c30d57a94c4104d84eb4eb9e74ca757c1a773 @@ -15,17 +24,14 @@ GIT mini_magick (~> 4.0) refile (~> 0.6) -GIT - remote: https://github.com/refile/refile.git - revision: c4ac577c6fdad92bc079a62a0e82888319daedc8 +GEM + remote: https://rails-assets.org/ specs: - refile (0.7.0) - mime-types - sinatra (>= 2.0.0, <= 3.0.0) + rails-assets-autosize (4.0.2) + rails-assets-mousetrap (1.6.2) GEM remote: https://rubygems.org/ - remote: https://rails-assets.org/ specs: actioncable (6.1.7.6) actionpack (= 6.1.7.6) @@ -117,7 +123,7 @@ GEM coderay (>= 1.0.0) erubi (>= 1.0.0) rack (>= 0.9.0) - binding_of_caller (0.8.0) + binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) bootstrap (4.6.1) autoprefixer-rails (>= 9.1.0) @@ -159,9 +165,6 @@ GEM rexml crass (1.0.6) date (3.3.3) - debase (0.2.4.1) - debase-ruby_core_source (>= 0.10.2) - debase-ruby_core_source (0.10.18) debug_inspector (1.1.0) device_detector (1.0.7) devise (4.8.1) @@ -288,9 +291,9 @@ GEM railties (>= 6) matrix (0.4.2) method_source (1.0.0) - mime-types (3.4.1) + mime-types (3.5.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0808) mini_magick (4.11.0) mini_mime (1.1.5) mini_portile2 (2.8.4) @@ -395,8 +398,6 @@ GEM bundler (>= 1.15.0) railties (= 6.1.7.6) sprockets-rails (>= 2.0.0) - rails-assets-autosize (4.0.2) - rails-assets-mousetrap (1.6.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -428,7 +429,7 @@ GEM tilt recaptcha (5.10.0) json - redcarpet (3.5.1) + redcarpet (3.6.0) redis (4.2.5) redis-client (0.17.0) connection_pool @@ -484,8 +485,6 @@ GEM activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) - ruby-debug-ide (0.7.3) - rake (>= 0.8.1) ruby-progressbar (1.11.0) ruby-vips (2.1.4) ffi (~> 1.12) @@ -521,7 +520,7 @@ GEM connection_pool (>= 2.3.0) rack (>= 2.2.4) redis-client (>= 0.14.0) - simplecov (0.21.2) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) @@ -593,7 +592,7 @@ DEPENDENCIES bcrypt (~> 3.1) bcrypt_pbkdf (~> 1.0) better_errors (~> 2.9) - binding_of_caller (~> 0.8) + binding_of_caller (~> 1.0) bootstrap (~> 4.5) bootstrap_form (~> 4.3) brakeman (~> 4.10) @@ -604,7 +603,6 @@ DEPENDENCIES cocoon (~> 1.2) coffee-rails (~> 5.0) connection_pool (~> 2.2) - debase (~> 0.2.4) device_detector (~> 1.0.7) devise (~> 4.7) devise-jwt (~> 0.9.0) @@ -652,14 +650,13 @@ DEPENDENCIES rb-fsevent (~> 0.10) react-rails (~> 2.6) recaptcha (~> 5.6) - redcarpet (~> 3.5) + redcarpet (~> 3.6) redis (~> 4.2.5) refile! refile-mini_magick! rspec-rails (~> 5.1.2) rswag (~> 2.10.1) rubocop-rails (~> 2.9) - ruby-debug-ide (~> 0.7.3) ruby-progressbar (~> 1.10) rubyzip (~> 2.3) sassc-rails (~> 2.1) @@ -670,7 +667,7 @@ DEPENDENCIES shoulda-context (~> 2.0) shoulda-matchers (~> 5.1) sidekiq (~> 7.1) - simplecov (~> 0.20) + simplecov (~> 0.22) sinatra (~> 2.2) spring (~> 2.1) sprockets (~> 4.0) @@ -686,4 +683,4 @@ DEPENDENCIES zaru (~> 0.3) BUNDLED WITH - 2.1.4 + 2.4.5 diff --git a/README.md b/README.md index e362307b3..54beba068 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This README describes the purpose of this repository and how to set up a develop This project requires: -* Ruby 2.7.5, preferably managed using [rbenv](http://rbenv.org/) +* Ruby 3.2.2, preferably managed using [rbenv](http://rbenv.org/) * PostgreSQL 15 must be installed and accepting connections * Node 18.x (`brew install nvm`, ...) * [Redis](https://redis.io/) must be installed and running on localhost with the default port @@ -89,14 +89,6 @@ If you want to remove a volume (e.g. to start with a fresh database), you can us ``docker volume rm volume_name`` -If you want to launch the server with **ruby-debug-ide** to establish communication between the debugger engine (debase) and your IDE, run the following commands: - -`` -docker exec catima-app supervisorctl stop server && docker exec catima-app supervisorctl start debug -`` - -You can now connect your IDE on host 127.0.0.1 on port 1234 to start a debugging session. - ### Frontend To access the main application please use the following link. diff --git a/app/controllers/api/v3/base_controller.rb b/app/controllers/api/v3/base_controller.rb index 5b6b89cd4..edb554892 100644 --- a/app/controllers/api/v3/base_controller.rb +++ b/app/controllers/api/v3/base_controller.rb @@ -119,7 +119,7 @@ def api_i18n_scope end def render_response(code, status, options: {}) - message = t(code, options.merge({ scope: api_i18n_scope })) + message = t(code, default: options.merge({ scope: api_i18n_scope })) render json: { message: message, code: code }, status: status end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 52d86eb29..0932cb576 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -4,21 +4,21 @@ def thumbnail size = params[:size].split('x').map { |s| s.to_i } filename = "#{params[:image]}.#{params[:ext]}" - src = Rails.root.join( - 'public', 'upload', params[:catalog_slug], - params[:field_uuid], filename + src = Rails.public_path.join( + 'upload', params[:catalog_slug].to_s, + params[:field_uuid].to_s, filename ) - raise ActiveRecord::RecordNotFound unless File.exists? src + raise ActiveRecord::RecordNotFound unless File.exist? src - dest_dir = Rails.root.join( - 'public', 'thumbs', params[:catalog_slug], - params[:size], 'resize', params[:field_uuid] + dest_dir = Rails.public_path.join( + 'thumbs', params[:catalog_slug].to_s, + params[:size].to_s, 'resize', params[:field_uuid].to_s ) FileUtils.mkdir_p(dest_dir) - dest = File.join(dest_dir, filename) + dest = File.join(dest_dir.to_s, filename) ImageTools.thumbnail(src, dest, size, :resize) - raise ActiveRecord::RecordNotFound unless File.exists? dest + raise ActiveRecord::RecordNotFound unless File.exist? dest redirect_to([ '/thumbs', params[:catalog_slug], @@ -42,21 +42,21 @@ def thumbnail_cropped crop = params[:crop].split(',').map { |s| s.to_i } crop_str = crop.map { |i| i.to_s }.join(',') - src = Rails.root.join( - 'public', 'upload', params[:catalog_slug], - params[:field_uuid], filename + src = Rails.public_path.join( + 'upload', params[:catalog_slug].to_s, + params[:field_uuid].to_s, filename ) - raise ActiveRecord::RecordNotFound unless File.exists? src + raise ActiveRecord::RecordNotFound unless File.exist? src - dest_dir = Rails.root.join( - 'public', 'thumbs', params[:catalog_slug], - params[:size], 'fill', crop_str, params[:field_uuid] + dest_dir = Rails.public_path.join( + 'thumbs', params[:catalog_slug].to_s, + params[:size].to_s, 'fill', crop_str, params[:field_uuid].to_s ) FileUtils.mkdir_p(dest_dir) - dest = File.join(dest_dir, filename) + dest = File.join(dest_dir.to_s, filename) ImageTools.thumbnail(src, dest, size, :fill, crop) - raise ActiveRecord::RecordNotFound unless File.exists? dest + raise ActiveRecord::RecordNotFound unless File.exist? dest redirect_to([ '/thumbs', params[:catalog_slug], diff --git a/bin/setup b/bin/setup index f03306c62..3241c44fc 100755 --- a/bin/setup +++ b/bin/setup @@ -4,8 +4,8 @@ def setup(ci) within_project_root do # During CI we do not check the ruby version to allow for version matrix test "ruby -v" => ruby_version unless ci - run "gem install bundler:2.1.4 --no-document --conservative" - run "bundle install" if File.exist?("Gemfile.lock") + run "gem install bundler:2.4.5 --no-document --conservative" + run "bundle install" if File.exist?("Gemfile.lock") run "bin/yarn install" if File.exist?("yarn.lock") run "bundle exec overcommit --sign" run "bundle exec overcommit --install" diff --git a/docker-compose.yml b/docker-compose.yml index 57248adad..2d209516d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,6 @@ services: - ./docker/.env ports: - "8383:3000" - - "1234:1234" expose: - "4000" depends_on: diff --git a/docker/app.dockerfile b/docker/app.dockerfile index 4b25c636e..66bd262d3 100644 --- a/docker/app.dockerfile +++ b/docker/app.dockerfile @@ -1,10 +1,10 @@ -FROM ruby:2.7.5-bullseye AS base +FROM ruby:3.2.2-bullseye AS base ENV DOCKER_RUNNING=true ENV PSQL_CLIENT_VERSION=15 ENV NODE_VERSION=18 ENV RUBYGEMS_VERSION=3.4.5 -ENV BUNDLER_VERSION=2.1.4 +ENV BUNDLER_VERSION=2.4.5 # Update repositories RUN apt-get update diff --git a/docker/config/supervisord-app-dev.conf b/docker/config/supervisord-app-dev.conf index e386b6d0a..b55674863 100644 --- a/docker/config/supervisord-app-dev.conf +++ b/docker/config/supervisord-app-dev.conf @@ -20,13 +20,6 @@ command=rails s -b 0.0.0.0 -p 3000 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 -[program:debug] -autostart=false -autorestart=true -command=bundle exec rdebug-ide --host 0.0.0.0 --port 1234 -- bin/rails s -p 3000 -b 0.0.0.0 -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 - [program:webpack] autorestart=false command=bash -c "rm -rf public/packs/* || true && bin/shakapacker -w" diff --git a/docker/worker.dockerfile b/docker/worker.dockerfile index 145e99826..1f9b220ef 100644 --- a/docker/worker.dockerfile +++ b/docker/worker.dockerfile @@ -1,10 +1,10 @@ -FROM ruby:2.7.5-bullseye AS base +FROM ruby:3.2.2-bullseye AS base ENV DOCKER_RUNNING=true ENV PSQL_CLIENT_VERSION=15 ENV NODE_VERSION=18 ENV RUBYGEMS_VERSION=3.4.5 -ENV BUNDLER_VERSION=2.1.4 +ENV BUNDLER_VERSION=2.4.5 # Update repositories RUN apt-get update