Skip to content

Commit

Permalink
Ruby 3.x support (catima#527)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucaguindani authored Sep 28, 2023
1 parent 6ec0e5e commit 5d30cfd
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.5
3.2.2
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
47 changes: 22 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -686,4 +683,4 @@ DEPENDENCIES
zaru (~> 0.3)

BUNDLED WITH
2.1.4
2.4.5
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v3/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 18 additions & 18 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ services:
- ./docker/.env
ports:
- "8383:3000"
- "1234:1234"
expose:
- "4000"
depends_on:
Expand Down
4 changes: 2 additions & 2 deletions docker/app.dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 0 additions & 7 deletions docker/config/supervisord-app-dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions docker/worker.dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 5d30cfd

Please sign in to comment.