Skip to content

Commit

Permalink
chore: upgrade ruby to 3.1.3 (#5555)
Browse files Browse the repository at this point in the history

* chore: update to ruby 3.1.3

* chore: ping docker version to alpine3.16 for nodev16.x

Starting with Node 17, nodejs switched to OpenSSL3. The docker builds
are installing node18.xx with alpine-3.1.3.

From Node.js 17's announcement post:

    If you hit an ERR_OSSL_EVP_UNSUPPORTED error in your application
with Node.js 17, it’s likely that your application or a module you’re
using is attempting to use an algorithm or key size which is no longer
allowed by default with OpenSSL 3.0. A new command-line option,
--openssl-legacy-provider, has been added to revert to the legacy
provider as a temporary workaround for these tightened restrictions.

Looks like a webpack issue. This is fixed in webpacl 5+ and we are on
webpack4 at the moment.
Solutions

    Upgrade webpack.
    Pin nodejs version to be 16.x.x
    Use  --openssl-legacy-provider as a workaround.

Pin docker version to alpine3.16 branch to have node16.x by default

ref:
#5555 (comment)

* chore: update webmock

* chore: fix ruby gem path in dockerfile

* chore: switch to node16 in circleci

* chore: update ruby version in linux installer script

* chore: update ruby version in linux installer script

* chore: fix circleci

* chore: fix circleci

* feat: upgrade node version to 16.x in linux installer

* chore: update systemd files

Co-authored-by: Sojan Jose <sojan@chatwoot.com>
  • Loading branch information
vishnu-narayanan and sojan-official authored Jan 24, 2023
1 parent b196492 commit b1ec67d
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 54 deletions.
15 changes: 13 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defaults: &defaults
working_directory: ~/build
docker:
# specify the version you desire here
- image: cimg/ruby:3.0.4-browsers
- image: cimg/ruby:3.1.3-browsers

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
Expand Down Expand Up @@ -38,6 +38,18 @@ jobs:
name: Which bundler?
command: bundle -v

- run:
name: Swap node versions
command: |
set +e
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install v16
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
# Run bundler
# Load installed gems from cache if possible, bundle install then save cache
# Multiple caches are used to increase the chance of a cache hit
Expand Down Expand Up @@ -193,4 +205,3 @@ workflows:
- upload-coverage:
requires:
- build

1 change: 0 additions & 1 deletion .github/workflows/run_foss_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:

- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0.4 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: yarn
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Style/ClassAndModuleChildren:
- 'config/application.rb'
Style/MapToHash:
Enabled: false
Style/HashSyntax:
Enabled: true
EnforcedStyle: no_mixed_keys
EnforcedShorthandSyntax: never
RSpec/NestedGroups:
Enabled: true
Max: 4
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.4
3.1.3
14 changes: 12 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

ruby '3.0.4'
ruby '3.1.3'

##-- base gems for rails --##
gem 'rack-cors', require: 'rack/cors'
Expand Down Expand Up @@ -107,7 +107,12 @@ gem 'sidekiq-cron', '~> 1.3'

##-- Push notification service --##
gem 'fcm'
gem 'webpush'

# Ref: https://github.com/mastodon/mastodon/pull/18449
# ref: https://github.com/zaru/webpush/pull/106
# lets switch to web-push gem once the above PR is merged
# https://github.com/zaru/webpush/pull/106#issuecomment-1342925261
gem 'webpush', git: 'https://github.com/ClearlyClaire/webpush.git', ref: 'f14a4d52e201128b1b00245d11b6de80d6cfdcd9'

##-- geocoding / parse location from ip --##
# http://www.rubygeocoder.com/
Expand Down Expand Up @@ -137,6 +142,11 @@ gem 'stripe'
## to populate db with sample data
gem 'faker'

# Can remove this in rails 7
gem 'net-imap', require: false
gem 'net-pop', require: false
gem 'net-smtp', require: false

group :production, :staging do
# we dont want request timing out in development while using byebug
gem 'rack-timeout'
Expand Down
40 changes: 29 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/ClearlyClaire/webpush.git
revision: f14a4d52e201128b1b00245d11b6de80d6cfdcd9
ref: f14a4d52e201128b1b00245d11b6de80d6cfdcd9
specs:
webpush (0.3.8)
hkdf (~> 0.2)
jwt (~> 2.0)

GIT
remote: https://github.com/chatwoot/devise-secure_password
revision: d777b04f12652d576b1272b8f39857e3e0b3fc26
Expand Down Expand Up @@ -73,8 +82,8 @@ GEM
zeitwerk (~> 2.3)
acts-as-taggable-on (9.0.1)
activerecord (>= 6.0, < 7.1)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
administrate (0.17.0)
actionpack (>= 5.0)
actionview (>= 5.0)
Expand Down Expand Up @@ -360,7 +369,7 @@ GEM
hana (~> 1.3)
regexp_parser (~> 2.0)
uri_template (~> 0.7)
jwt (2.4.1)
jwt (2.5.0)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
Expand Down Expand Up @@ -426,6 +435,14 @@ GEM
multipart-post (2.2.3)
net-http-persistent (4.0.1)
connection_pool (~> 2.2)
net-imap (0.3.1)
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
netrc (0.11.0)
newrelic_rpm (8.9.0)
nio4r (2.5.8)
Expand Down Expand Up @@ -469,7 +486,7 @@ GEM
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.7)
public_suffix (5.0.1)
puma (5.6.4)
nio4r (~> 2.0)
pundit (2.2.0)
Expand Down Expand Up @@ -662,6 +679,7 @@ GEM
time_diff (0.3.0)
activesupport
i18n
timeout (0.3.1)
trailblazer-option (0.1.2)
twilio-ruby (5.68.0)
faraday (>= 0.9, < 3.0)
Expand Down Expand Up @@ -693,7 +711,7 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.14.0)
webmock (3.18.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand All @@ -702,9 +720,6 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
webpush (1.1.0)
hkdf (~> 0.2)
jwt (~> 2.0)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -779,6 +794,9 @@ DEPENDENCIES
listen
maxminddb
mock_redis
net-imap
net-pop
net-smtp
newrelic_rpm
omniauth-oauth2
pg
Expand Down Expand Up @@ -826,12 +844,12 @@ DEPENDENCIES
web-console
webmock
webpacker (~> 5.4, >= 5.4.3)
webpush
webpush!
wisper (= 2.0.0)
working_hours

RUBY VERSION
ruby 3.0.4p208
ruby 3.1.3p185

BUNDLED WITH
2.3.16
2.3.26
12 changes: 6 additions & 6 deletions app/controllers/concerns/switch_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ module SwitchLocale

private

def switch_locale(&action)
def switch_locale(&)
# priority is for locale set in query string (mostly for widget/from js sdk)
locale ||= locale_from_params
# if locale is not set in account, let's use DEFAULT_LOCALE env variable
locale ||= locale_from_env_variable
set_locale(locale, &action)
set_locale(locale, &)
end

def switch_locale_using_account_locale(&action)
def switch_locale_using_account_locale(&)
locale = locale_from_account(@current_account)
set_locale(locale, &action)
set_locale(locale, &)
end

def set_locale(locale, &action)
def set_locale(locale, &)
# if locale is empty, use default_locale
locale ||= I18n.default_locale
# Ensure locale won't bleed into other requests
# https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
I18n.with_locale(locale, &action)
I18n.with_locale(locale, &)
end

def locale_from_params
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ def ensure_current_account(account)
Current.account = account if account.present?
end

def switch_locale(&action)
def switch_locale(&)
locale ||= locale_from_account(Current.account)
locale ||= I18n.default_locale
# ensure locale won't bleed into other requests
# https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
I18n.with_locale(locale, &action)
I18n.with_locale(locale, &)
end
end
2 changes: 1 addition & 1 deletion app/models/dashboard_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def validate_content
'required' => %w[url type],
'properties' => {
'type' => { 'enum': ['frame'] },
'url' => { 'type': 'string', 'format' => 'uri' }
'url' => { :type => 'string', 'format' => 'uri' }
}
},
'additionalProperties' => false,
Expand Down
2 changes: 1 addition & 1 deletion app/services/whatsapp/providers/whatsapp_cloud_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def send_attachment_message(phone_number, message)
"#{phone_id_path}/messages",
headers: api_headers,
body: {
messaging_product: 'whatsapp',
:messaging_product => 'whatsapp',
'to' => phone_number,
'type' => type,
type.to_s => type_content
Expand Down
6 changes: 3 additions & 3 deletions deployment/chatwoot-web.1.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ KillMode=mixed
StandardInput=null
SyslogIdentifier=%p

Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4/bin:/home/chatwoot/.rvm/gems/ruby-3.0.4@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.0.4/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin"
Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3/bin:/home/chatwoot/.rvm/gems/ruby-3.1.3@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.1.3/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin"
Environment="PORT=3000"
Environment="RAILS_ENV=production"
Environment="NODE_ENV=production"
Environment="RAILS_LOG_TO_STDOUT=true"
Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.0.4"
Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4:/home/chatwoot/.rvm/gems/ruby-3.0.4@global"
Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.1.3"
Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3:/home/chatwoot/.rvm/gems/ruby-3.1.3@global"
6 changes: 3 additions & 3 deletions deployment/chatwoot-worker.1.service
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ KillMode=mixed
StandardInput=null
SyslogIdentifier=%p

Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4/bin:/home/chatwoot/.rvm/gems/ruby-3.0.4@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.0.4/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin"
Environment="PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3/bin:/home/chatwoot/.rvm/gems/ruby-3.1.3@global/bin:/home/chatwoot/.rvm/rubies/ruby-3.1.3/bin:/home/chatwoot/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/home/chatwoot/.rvm/bin:/home/chatwoot/.rvm/bin"
Environment="PORT=3000"
Environment="RAILS_ENV=production"
Environment="NODE_ENV=production"
Environment="RAILS_LOG_TO_STDOUT=true"
Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.0.4"
Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.0.4:/home/chatwoot/.rvm/gems/ruby-3.0.4@global"
Environment="GEM_HOME=/home/chatwoot/.rvm/gems/ruby-3.1.3"
Environment="GEM_PATH=/home/chatwoot/.rvm/gems/ruby-3.1.3:/home/chatwoot/.rvm/gems/ruby-3.1.3@global"
6 changes: 3 additions & 3 deletions deployment/setup_20.04.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ EOF
function install_dependencies() {
apt update && apt upgrade -y
apt install -y curl
curl -sL https://deb.nodesource.com/setup_14.x | bash -
curl -sL https://deb.nodesource.com/setup_16.x | bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update
Expand Down Expand Up @@ -328,8 +328,8 @@ function setup_chatwoot() {
sudo -i -u chatwoot << EOF
rvm --version
rvm autolibs disable
rvm install "ruby-3.0.4"
rvm use 3.0.4 --default
rvm install "ruby-3.1.3"
rvm use 3.1.3 --default
git clone https://github.com/chatwoot/chatwoot.git
cd chatwoot
Expand Down
9 changes: 5 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pre-build stage
FROM ruby:3.0.4-alpine AS pre-builder
FROM ruby:3.1.3-alpine3.16 AS pre-builder

# ARG default to production settings
# For development docker-compose file overrides ARGS
Expand Down Expand Up @@ -61,11 +61,12 @@ RUN if [ "$RAILS_ENV" = "production" ]; then \
fi

# Remove unnecessary files
RUN rm -rf /gems/ruby/3.0.0/cache/*.gem \
&& find /gems/ruby/3.0.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete
RUN rm -rf /gems/ruby/3.1.0/cache/*.gem \
&& find /gems/ruby/3.1.0/gems/ \( -name "*.c" -o -name "*.o" \) -delete

# final build stage
FROM ruby:3.0.4-alpine
FROM ruby:3.1.3-alpine3.16


ARG BUNDLE_WITHOUT="development:test"
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/accounts/macros_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
{ 'action_name' => 'snooze_conversation' },
{ 'action_name' => 'assign_agent', 'action_params' => [user_1.id] },
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] },
{ 'action_name' => 'add_private_note', 'action_params': ['We are sending greeting message to customer.'] }
{ 'action_name' => 'add_private_note', :action_params => ['We are sending greeting message to customer.'] }
])
end

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/twitter/twitter_message_create_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'type' => 'message_create',
'id' => '123',
'message_create' => {
target: { 'recipient_id' => '1' },
:target => { 'recipient_id' => '1' },
'sender_id' => '2',
'source_app_id' => '268278',
'message_data' => {
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/webhooks/line_events_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject(:job) { described_class.perform_later(params: params) }

let!(:line_channel) { create(:channel_line) }
let!(:params) { { line_channel_id: line_channel.line_channel_id, 'line' => { test: 'test' } } }
let!(:params) { { :line_channel_id => line_channel.line_channel_id, 'line' => { test: 'test' } } }
let(:post_body) { params.to_json }
let(:signature) { Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('SHA256'), line_channel.line_channel_secret, post_body)) }

Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/webhooks/telegram_events_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject(:job) { described_class.perform_later(params) }

let!(:telegram_channel) { create(:channel_telegram) }
let!(:params) { { bot_token: telegram_channel.bot_token, 'telegram' => { test: 'test' } } }
let!(:params) { { :bot_token => telegram_channel.bot_token, 'telegram' => { test: 'test' } } }

it 'enqueues the job' do
expect { job }.to have_enqueued_job(described_class)
Expand Down
Loading

0 comments on commit b1ec67d

Please sign in to comment.