Setting Up Dev Environment (Mac) - PatrickF1/GraceTunes GitHub Wiki

Editor

The CI is configured to fail on warning level RuboCop offenses. Therefore, install the RuboCop integration for your editor of choice and enable autocorrection on save to prevent unexpected build failures. Or if you prefer to manually run it, run rubocop --autocorrect on the entire repo before committing.

Installing the Stack

Ruby 3.2.2

  • Install Rbenv to manage Rubies: brew install rbenv
  • Run and follow the instructions printed by rbenv init
  • Then install the correct version of Ruby: rbenv install $ruby_version
    • If it seems to hang, add the --verbose flag to check the progress
    • If rbenv doesn't list $ruby_version, try updating ruby-build: git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Postgres 15

  • brew install postgresql@15
  • To have launchd start postgresql now and restart at login: brew services start postgresql
  • createuser --superuser gracetunes_user (gracetunes_user is the user used to connect to the database on the development and test environments)
  • Create the tables on both the dev and test databases: bundle exec rails db:setup (bundle exec makes sure you are using the Ruby gems specified in your Gemfile to run the command following it)
  • If you want to seed the dev DB with test fixtures: bundle exec rails db:fixtures:load
  • When upgrading Postgres, you'll need to re-install the pg gem

Rails 7.1 and rest of gems

  • run bundle install from inside the repo
  • if pg gem fails to install, make sure you have Postgres 15 installed and running

Git 2 (not fully compatible with Git 1)

Heroku CLI (for running the app locally and deploying)

Environment variables

To control the knobs and secrets used by the app, we use a .env file that contains a set of key-value pairs. It is not checked into git. On app initialization, these key-value pairs are inserted into the shell environment. In turn, the app reads in these values from the environment. Here is a template .env file.

RAILS_ENV=development
GOOGLE_CLIENT_ID=(ask Patrick or get your own at https://console.developers.google.com/)
GOOGLE_CLIENT_SECRET=(same as above)
SECRET_KEY_BASE=(generate your own with `bundle exec rails secret`)
RAILS_MAX_THREADS=2
ABOUT_URL=https://docs.google.com/document/d/e/2PACX-1vS086ZBTQU-hG5q36mUUBm8oGEgIjoZEP7w2JuyHFS9hDIAJ8WODNHVomcBJI5rZLyhukYMVrL1atjA/pub
REQUEST_SONG_URL=https://docs.google.com/forms/d/e/1FAIpQLSe4zko5wg2FfTfTGGAVENnARWfg-4AJSQqz54BlWdagBhKISA/viewform?usp=sf_link
API_USERNAME=(whatever you want)
API_PASSWORD=(whatever you want)
# YJIT kills performance in dev environment, so only enable if profiling or trying to repro YJIT bug
# RUBYOPT=--enable-yjit

The Google config vars are used to authenticate with Google's API. You can generate your own at https://console.developers.google.com > Enable APIS > Search "Contact".

Running the App

heroku local and then navigate to localhost:5001. heroku local defaults the port to 5001. It does not read .env for a port number, but you can control the port it listens on by passing the -p/--port option.

Tricks

Make a copy of the production database to use locally

dropdb tunes_dev
heroku pg:pull DATABASE_URL tunes_dev