From e2a6dc3e04aca5493a6e4bd3e4ff8358bca4c66c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Mon, 28 Aug 2023 20:50:35 +0700 Subject: [PATCH] chore: Upgrade Node.js to v20 (#7759) Co-authored-by: Vishnu Narayanan Co-authored-by: Pranav Raj S --- .circleci/config.yml | 15 ++++----- .github/workflows/run_foss_spec.yml | 5 ++- .github/workflows/run_response_bot_spec.yml | 3 +- .github/workflows/size-limit.yml | 7 ++-- .nvmrc | 2 +- Procfile.dev | 2 +- app.json | 3 ++ deployment/setup_20.04.sh | 4 +-- docker/Dockerfile | 37 +++++++++++---------- lib/tasks/yarn.rake | 1 + package.json | 7 ++-- 11 files changed, 50 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e2c6dc583e7f4..c67063ae6b31d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,9 +15,9 @@ defaults: &defaults - image: cimg/postgres:15.3 - image: cimg/redis:6.2.6 environment: - - RAILS_LOG_TO_STDOUT: false - - COVERAGE: true - - LOG_LEVEL: warn + - RAILS_LOG_TO_STDOUT: false + - COVERAGE: true + - LOG_LEVEL: warn parallelism: 4 resource_class: large @@ -46,7 +46,7 @@ jobs: 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 + nvm install v20 echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV @@ -64,7 +64,6 @@ jobs: - ~/.bundle key: chatwoot-bundle-{{ .Environment.CACHE_VERSION }}-v20220524-{{ checksum "Gemfile.lock" }} - # Only necessary if app uses webpacker or yarn in some other way - restore_cache: keys: @@ -82,7 +81,7 @@ jobs: - ~/.cache/yarn - run: - name: Download cc-test-reporter + name: Download cc-test-reporter command: | mkdir -p ~/tmp curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ~/tmp/cc-test-reporter @@ -182,7 +181,7 @@ jobs: - attach_workspace: at: ~/build - run: - name: Download cc-test-reporter + name: Download cc-test-reporter command: | mkdir -p ~/tmp curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ~/tmp/cc-test-reporter @@ -204,4 +203,4 @@ workflows: - build - upload-coverage: requires: - - build + - build diff --git a/.github/workflows/run_foss_spec.yml b/.github/workflows/run_foss_spec.yml index 71009f5a0d173..7a32f3fd15aaa 100644 --- a/.github/workflows/run_foss_spec.yml +++ b/.github/workflows/run_foss_spec.yml @@ -52,7 +52,8 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 + cache: yarn - name: yarn run: yarn install @@ -75,6 +76,8 @@ jobs: - name: Run backend tests run: | bundle exec rspec --profile=10 --format documentation + env: + NODE_OPTIONS: --openssl-legacy-provider - name: Upload rails log folder uses: actions/upload-artifact@v3 diff --git a/.github/workflows/run_response_bot_spec.yml b/.github/workflows/run_response_bot_spec.yml index daa89494af110..ded5c903e3052 100644 --- a/.github/workflows/run_response_bot_spec.yml +++ b/.github/workflows/run_response_bot_spec.yml @@ -51,7 +51,8 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 + cache: yarn - name: yarn run: yarn install diff --git a/.github/workflows/size-limit.yml b/.github/workflows/size-limit.yml index efe4971571459..01d72339d62fc 100644 --- a/.github/workflows/size-limit.yml +++ b/.github/workflows/size-limit.yml @@ -21,7 +21,8 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 20 + cache: 'yarn' - name: yarn run: yarn install @@ -30,9 +31,11 @@ jobs: run: | rm -rf enterprise rm -rf spec/enterprise - + - name: Run asset compile run: bundle exec rake assets:precompile + env: + NODE_OPTIONS: --openssl-legacy-provider - name: Size Check run: yarn run size diff --git a/.nvmrc b/.nvmrc index 47979412e93f2..6f7af3750c3be 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.20.1 +20.5.1 \ No newline at end of file diff --git a/Procfile.dev b/Procfile.dev index 94371cbae1f59..73c2af7e8fdbf 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,4 +1,4 @@ backend: bin/rails s -p 3000 -frontend: bin/webpack-dev-server +frontend: export NODE_OPTIONS=--openssl-legacy-provider && bin/webpack-dev-server # https://github.com/mperham/sidekiq/issues/3090#issuecomment-389748695 worker: dotenv bundle exec sidekiq -C config/sidekiq.yml diff --git a/app.json b/app.json index 6324672fb8f15..a89f2a08aeec9 100644 --- a/app.json +++ b/app.json @@ -60,6 +60,9 @@ ], "stack": "heroku-20", "buildpacks": [ + { + "url": "heroku/nodejs" + }, { "url": "heroku/ruby" } diff --git a/deployment/setup_20.04.sh b/deployment/setup_20.04.sh index 8cd0a4e1aa21e..9003d7926e2cf 100644 --- a/deployment/setup_20.04.sh +++ b/deployment/setup_20.04.sh @@ -172,7 +172,7 @@ EOF function install_dependencies() { apt update && apt upgrade -y apt install -y curl - curl -sL https://deb.nodesource.com/setup_16.x | bash - + curl -sL https://deb.nodesource.com/setup_20.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 curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg @@ -349,7 +349,7 @@ function setup_chatwoot() { sed -i -e '/RAILS_ENV/ s/=.*/=$RAILS_ENV/' .env echo -en "\nINSTALLATION_ENV=linux_script" >> ".env" - rake assets:precompile RAILS_ENV=production + rake assets:precompile RAILS_ENV=production NODE_OPTIONS=--openssl-legacy-provider EOF } diff --git a/docker/Dockerfile b/docker/Dockerfile index 126a1174ea4d5..676b5bf7476f4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ # pre-build stage -FROM ruby:3.2.2-alpine3.16 AS pre-builder +FROM ruby:3.2.2-alpine3.18 AS pre-builder # ARG default to production settings # For development docker-compose file overrides ARGS @@ -13,18 +13,21 @@ ENV RAILS_SERVE_STATIC_FILES ${RAILS_SERVE_STATIC_FILES} ARG RAILS_ENV=production ENV RAILS_ENV ${RAILS_ENV} +ARG NODE_OPTIONS="--openssl-legacy-provider" +ENV NODE_OPTIONS ${NODE_OPTIONS} + ENV BUNDLE_PATH="/gems" RUN apk update && apk add --no-cache \ - openssl \ - tar \ - build-base \ - tzdata \ - postgresql-dev \ - postgresql-client \ - nodejs \ - yarn \ - git \ + openssl \ + tar \ + build-base \ + tzdata \ + postgresql-dev \ + postgresql-client \ + nodejs-current \ + yarn \ + git \ && mkdir -p /var/app \ && gem install bundler @@ -70,7 +73,7 @@ RUN rm -rf /gems/ruby/3.2.0/cache/*.gem \ && rm .gitignore # final build stage -FROM ruby:3.2.2-alpine3.16 +FROM ruby:3.2.2-alpine3.18 ARG BUNDLE_WITHOUT="development:test" @@ -92,12 +95,12 @@ ENV BUNDLE_PATH="/gems" RUN apk update && apk add --no-cache \ build-base \ - openssl \ - tzdata \ - postgresql-client \ - imagemagick \ - git \ - vips \ + openssl \ + tzdata \ + postgresql-client \ + imagemagick \ + git \ + vips \ && gem install bundler RUN if [ "$RAILS_ENV" != "production" ]; then \ diff --git a/lib/tasks/yarn.rake b/lib/tasks/yarn.rake index 7918073918071..2ffd264137e74 100644 --- a/lib/tasks/yarn.rake +++ b/lib/tasks/yarn.rake @@ -2,6 +2,7 @@ # https://github.com/rails/rails/issues/43906#issuecomment-1099992310 task before_assets_precompile: :environment do # run a command which starts your packaging + ENV['NODE_OPTIONS'] = '--openssl-legacy-provider' system('yarn') end diff --git a/package.json b/package.json index 8ab021ff71d9c..a6cd77e8f607c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "prepare": "husky install", "size": "size-limit" }, - "size-limit": [{ + "size-limit": [ + { "path": "public/packs/js/widget-*.js", "limit": "270 KB" }, @@ -146,9 +147,9 @@ "webpack-dev-server": "^3" }, "engines": { - "node": ">=10.x", + "node": "20.x", "npm": ">=6.x", - "yarn": ">=1.x" + "yarn": "1.22.x" }, "husky": { "hooks": {