From 856df114f6422b83b941939bf1aca93d7eb090d7 Mon Sep 17 00:00:00 2001 From: Janell-Huyck Date: Thu, 30 May 2024 12:54:54 -0400 Subject: [PATCH] Set up to use nvm for deploys and circleci --- .circleci/config.yml | 25 ++++-- .nvmrc | 1 + Gemfile | 2 +- Gemfile.lock | 142 +++++++++++++++++----------------- README.md | 110 ++++++++++---------------- config/deploy.rb | 5 +- lib/capistrano/tasks/nvm.rake | 15 ++++ 7 files changed, 148 insertions(+), 152 deletions(-) create mode 100644 .nvmrc create mode 100644 lib/capistrano/tasks/nvm.rake diff --git a/.circleci/config.yml b/.circleci/config.yml index 344932c3..5b16204a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,22 +59,31 @@ jobs: gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)" - run: - name: Install Node.js and Dependencies - no_output_timeout: 15m + name: Install NVM and Node.js command: | - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV - echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV + echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --install' >> $BASH_ENV echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> $BASH_ENV source $BASH_ENV - nvm install 12.22.12 - nvm use 12.22.12 - node --version - npm --version + echo "Node Version Manager (NVM) installed successfully." + echo "NVM version: $(nvm --version)" + echo "Node.js version: $(node --version)" + + - run: + name: Install Dependencies + no_output_timeout: 15m + shell: /bin/bash -eo pipefail + command: | + echo "Installing Ruby gems..." bundle install --jobs=4 --retry=3 + + echo "Installing required system packages..." sudo apt-get update sudo apt-get install -y xvfb libfontconfig wkhtmltopdf + echo "Installation steps completed successfully." + - save_cache: paths: - ./vendor/bundle diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..48b14e6b --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +20.14.0 diff --git a/Gemfile b/Gemfile index 98464337..3712e117 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '3.3.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 6.1.7.7' +gem 'rails', '~> 6.1.7' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server diff --git a/Gemfile.lock b/Gemfile.lock index 78fab96c..906d2046 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,60 +1,60 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.7.7) - actionpack (= 6.1.7.7) - activesupport (= 6.1.7.7) + actioncable (6.1.7.8) + actionpack (= 6.1.7.8) + activesupport (= 6.1.7.8) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.7.7) - actionpack (= 6.1.7.7) - activejob (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + actionmailbox (6.1.7.8) + actionpack (= 6.1.7.8) + activejob (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) mail (>= 2.7.1) - actionmailer (6.1.7.7) - actionpack (= 6.1.7.7) - actionview (= 6.1.7.7) - activejob (= 6.1.7.7) - activesupport (= 6.1.7.7) + actionmailer (6.1.7.8) + actionpack (= 6.1.7.8) + actionview (= 6.1.7.8) + activejob (= 6.1.7.8) + activesupport (= 6.1.7.8) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.7.7) - actionview (= 6.1.7.7) - activesupport (= 6.1.7.7) + actionpack (6.1.7.8) + actionview (= 6.1.7.8) + activesupport (= 6.1.7.8) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.7.7) - actionpack (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + actiontext (6.1.7.8) + actionpack (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) nokogiri (>= 1.8.5) - actionview (6.1.7.7) - activesupport (= 6.1.7.7) + actionview (6.1.7.8) + activesupport (= 6.1.7.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.7.7) - activesupport (= 6.1.7.7) + activejob (6.1.7.8) + activesupport (= 6.1.7.8) globalid (>= 0.3.6) - activemodel (6.1.7.7) - activesupport (= 6.1.7.7) - activerecord (6.1.7.7) - activemodel (= 6.1.7.7) - activesupport (= 6.1.7.7) - activestorage (6.1.7.7) - actionpack (= 6.1.7.7) - activejob (= 6.1.7.7) - activerecord (= 6.1.7.7) - activesupport (= 6.1.7.7) + activemodel (6.1.7.8) + activesupport (= 6.1.7.8) + activerecord (6.1.7.8) + activemodel (= 6.1.7.8) + activesupport (= 6.1.7.8) + activestorage (6.1.7.8) + actionpack (= 6.1.7.8) + activejob (= 6.1.7.8) + activerecord (= 6.1.7.8) + activesupport (= 6.1.7.8) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.7.7) + activesupport (6.1.7.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -86,7 +86,7 @@ GEM bundler (>= 1.2.0, < 3) thor (~> 1.0) byebug (11.1.3) - cancancan (3.5.0) + cancancan (3.6.1) capistrano (3.17.1) airbrussh (>= 1.0.0) i18n @@ -109,7 +109,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.3) + concurrent-ruby (1.3.1) coveralls_reborn (0.28.0) simplecov (~> 0.22.0) term-ansicolor (~> 1.7) @@ -143,7 +143,12 @@ GEM factory_bot_rails (6.4.3) factory_bot (~> 6.4) railties (>= 5.0.0) - ffi (1.16.3) + ffi (1.17.0-aarch64-linux-gnu) + ffi (1.17.0-arm-linux-gnu) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86-linux-gnu) + ffi (1.17.0-x86_64-darwin) + ffi (1.17.0-x86_64-linux-gnu) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.5) @@ -172,11 +177,11 @@ GEM matrix (0.4.2) method_source (1.1.0) mini_mime (1.1.5) - minitest (5.23.0) + minitest (5.23.1) msgpack (1.7.2) mutex_m (0.2.0) mysql2 (0.5.6) - net-imap (0.4.11) + net-imap (0.4.12) date net-protocol net-pop (0.1.2) @@ -204,12 +209,12 @@ GEM nokogiri (1.16.5-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - pagy (8.4.0) + pagy (8.4.4) paper_trail (15.1.0) activerecord (>= 6.1) request_store (~> 1.4) parallel (1.24.0) - parser (3.3.1.0) + parser (3.3.2.0) ast (~> 2.4.1) racc pdfkit (0.8.7.3) @@ -221,20 +226,20 @@ GEM rack (2.2.9) rack-test (2.1.0) rack (>= 1.3) - rails (6.1.7.7) - actioncable (= 6.1.7.7) - actionmailbox (= 6.1.7.7) - actionmailer (= 6.1.7.7) - actionpack (= 6.1.7.7) - actiontext (= 6.1.7.7) - actionview (= 6.1.7.7) - activejob (= 6.1.7.7) - activemodel (= 6.1.7.7) - activerecord (= 6.1.7.7) - activestorage (= 6.1.7.7) - activesupport (= 6.1.7.7) + rails (6.1.7.8) + actioncable (= 6.1.7.8) + actionmailbox (= 6.1.7.8) + actionmailer (= 6.1.7.8) + actionpack (= 6.1.7.8) + actiontext (= 6.1.7.8) + actionview (= 6.1.7.8) + activejob (= 6.1.7.8) + activemodel (= 6.1.7.8) + activerecord (= 6.1.7.8) + activestorage (= 6.1.7.8) + activesupport (= 6.1.7.8) bundler (>= 1.15.0) - railties (= 6.1.7.7) + railties (= 6.1.7.8) sprockets-rails (>= 2.0.0) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) @@ -247,9 +252,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (6.1.7.7) - actionpack (= 6.1.7.7) - activesupport (= 6.1.7.7) + railties (6.1.7.8) + actionpack (= 6.1.7.8) + activesupport (= 6.1.7.8) method_source rake (>= 12.2) thor (~> 1.0) @@ -286,7 +291,7 @@ GEM rspec-support (3.13.1) rspec_junit_formatter (0.6.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.63.5) + rubocop (1.64.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -332,13 +337,12 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.3) - base64 + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.0) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) sqlite3 (1.7.3-aarch64-linux) sqlite3 (1.7.3-arm-linux) @@ -384,7 +388,7 @@ GEM wkhtmltopdf-binary (0.12.6.7) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.14) + zeitwerk (2.6.15) PLATFORMS aarch64-linux @@ -423,7 +427,7 @@ DEPENDENCIES paper_trail pdfkit puma - rails (~> 6.1.7.7) + rails (~> 6.1.7) rails-controller-testing rb-readline rspec-rails (~> 4.1.0) diff --git a/README.md b/README.md index 4c73246a..855a3610 100644 --- a/README.md +++ b/README.md @@ -2,110 +2,78 @@ This is a web application originally developed for the Preservation Lab at the University of Cincinnati. Provided that you have Ruby on Rails installed you can run this application on your local machine or server. -```bash -git clone github.com/uclibs/treatment_database - -bundle install - -# Run the migration to prepare the database. - -rails db:migrate - -rails db:seed - -rails server - -rails db:seed (optional) - +## Prerequisites +- a current version of nvm +- Node >= 20.14.0 +- Yarn >= 1.22.17 +- Ruby 3.3.1 +- Rails 6.1.7.7 + +### Notes: + +#### Ruby Version Management +As of the new release of Ruby version 3.3.1, you need to use the following command to +install Ruby 3.3.1: +
+With rvm: ``` - -See [wiki](https://github.com/uclibs/treatment_database/wiki/Migration) for migration steps. - -# Dockerizing application - -To dockerize the treatment database application in **Development Mode** use the following commands after setting up docker on your local machine or server. - -```bash -cd \\to_the_treatment_database_directory -docker build -t treatment_database_image . -docker run -it --rm treatment_database_image bundle exec rspec -docker run -d --name treatment_database -p 3000:3000 -itP -v $(pwd):/app treatment_database_image +rvm reinstall 3.3.1 --with-openssl-dir=`brew --prefix openssl@1.1` --with-opt-dir=`brew --prefix openssl@1.1 ``` - -Then to check the containers which are running: - -```bash -docker ps -``` - -If running on local machine, access the app in the browser: [http://localhost:3000](http://localhost:3000) - -Access the rails console: - -```bash -docker exec -it treatment_database rails c +With rbenv: ``` - -Access the shell: - -```bash -docker exec -it treatment_database /bin/sh +CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1) --with-opt-dir=$(brew --prefix openssl@1.1)" rbenv install 3.3.1 && rbenv rehash ``` -To stop the container: +#### Node Version Management -```bash -docker stop treatment_database -``` +This project uses nvm (Node Version Manager) to manage Node.js versions. The `.nvmrc` file is configured to use the +latest LTS version of Node, 20.14.0, to ensure compatibility with the latest features and security updates. -To delete the container: +When running locally, you will need to set the node version with `nvm use` as described below under "Installation". +For deployment, the `.nvmrc` file will be used to set the node version and the deployment script will automatically +use the correct version. -```bash -docker rm treatment_database -``` - -To build the Docker image of the application in **Production Mode** and to run the app on NGINX server inside docker: +## Installation ```bash -docker-compose build +git clone github.com/uclibs/treatment_database +nvm install # Installs the node version listed in .nvmrc +nvm use # Directs to the correct node version listed in .nvmrc +bundle install ``` -Then: +## Prepare the database. ```bash -docker-compose up +rails db:migrate +rails db:seed +rails server +rails db:seed # (Optional, for example works) ``` +### Important: +Running the db:seed is not sufficient to populate the database with the necessary data. You will need to import the data +for the controlled vocaublary and users. +See [wiki](https://github.com/uclibs/treatment_database/wiki/Migration) for migration steps. ## Running the Tests The treatment database has a test suite built with rspec, running it is simple, just call the following in the project directory: ```bash -bin/rails db:migrate RAILS_ENV=test - bundle exec rspec - -docker exec -it treatment_database bundle exec rspec ``` ## Deploy Instructions - Use Capistrano for deploying to QA and Production environments; local deploy not supported. - ### QA deploy - 1. Connect from VPN or on-campus network. 1. On local terminal, type `cap qa deploy` 1. When prompted, type apache username. 1. When prompted, type apache password. - -Capistrano will deploy the `qa` branch by default from the github repository for QA deploys. Switch branches for deploy to QA by altering [/config/deploy/qa.rb](https://github.com/uclibs/treatment_database/blob/qa/config/deploy/qa.rb#L5) (branch must be pushed to remote). - + Capistrano will deploy the `qa` branch by default from the github repository for QA deploys. Switch branches for deploy to QA by altering [/config/deploy/qa.rb](https://github.com/uclibs/treatment_database/blob/qa/config/deploy/qa.rb#L5) (branch must be pushed to remote). ### Production deploy - 1. Connect from VPN or on-campus network. 1. On local terminal, type `cap production deploy` 1. When prompted, type apache username. 1. When prompted, type apache password. - -Capistrano will deploy the `main` branch from the github repository by default for Production deploys. + Capistrano will deploy the `main` branch from the github repository by default for Production deploys. \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index dd63edfb..062720c6 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -67,6 +67,5 @@ end end -Capistrano::DSL.stages.each do |stage| - after stage, 'deploy:confirmation' -end +before 'deploy:starting', 'deploy:confirmation' +after 'git:create_release', 'nvm:load' diff --git a/lib/capistrano/tasks/nvm.rake b/lib/capistrano/tasks/nvm.rake new file mode 100644 index 00000000..2da5587b --- /dev/null +++ b/lib/capistrano/tasks/nvm.rake @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +namespace :nvm do + task :load do + on roles(:all) do + within release_path do + # Read the .nvmrc file and install the specified Node.js version + execute "nvm install $(cat #{release_path}/.nvmrc)" + + # Use the installed Node.js version + execute "nvm use $(cat #{release_path}/.nvmrc)" + end + end + end +end