Skip to content

Latest commit

 

History

History
134 lines (90 loc) · 4.19 KB

LOCALDEV.md

File metadata and controls

134 lines (90 loc) · 4.19 KB

Local Dev

Environment

Requirements:

  • Ruby 2.6.4
  • Node 8+
  • Postgres 10+ with PostGIS extension installed

To get it running you will need both node and ruby installed. Use the language version manager of your choice, or follow the instructions below.

** Updated Jan 19, 2023. Ruby 2.6.4 has reached EOL and is no longer available via RVM. It can be installed locally with RBENV however, running the back end of the app outside of a Docker container, would be highly problematic as installing some of the dependancies may cause many compatibility issues **

Getting the code

To get started, first clone this repo and navigate to it.

git clone git@github.com:NYCPlanning/ceqr-app.git
cd ceqr-app

Installing Ruby

I suggest using rbenv installed with Homebrew.

brew install rbenv
rbenv init
rbenv install 2.6.4

Installing Node

macOS will come with node installed. I use n to manage node versions. Our current configuration expects yarn to manage javascript dependencies.

npm install -g n
n 8.15.0
brew install yarn

Installing Postgres

I use Postgres.app on macOS, though you can manage Postgres however you like.

CEQR App has two Postgis databases:

  • ceqr_rails, which is used for all saved state of the app, including projects, users, and saved analyses.
  • ceqr_data, which is accesed by Rails as a read-only database containing all the inputs necessary for any given CEQR analysis. (TODO: Currently, there is no seed file for this database. Ideally, for tests, a small local version could be created. The development environment might as well point to the production data since it's read-only.)

Setting configuration

Rails config sits in a .env file that is not checked into version control. This allows configuring through environment variables in production. To get started, copy the config example:

cd backend
cp .env-example .env

Next, edit .env to the appropriate settings. Descriptions of each are below:

  • DATABASE_URL - Postgres url string to the ceqr_rails database. Locally, this should point to your development database. Rails will automatically swap to ceqr_test when the test suite is run. Remember to use postgis:// as the prefix.
  • CEQR_DATA_DB_URL - Postgres url string to the read-only production ceqr_data running on Digital Ocean. Remember to use postgis:// as the prefix. See 1Password for database connection string.
  • JWT_SALT - salt for the JSON Web Token used for user sessions. Necessary, but only really important in production.
  • ADMIN_EMAILS - A comma seperated list (no spaces) of email addresses used for admin emails (example: user account in need of verification.)
  • SENDGRID_KEY - Sendgrid key for sending emails. Can be found in Heroku account.

Setting up Rails

Once you have the latest version of Ruby installed, you'll first need bundler, Rails' package manager.

To install Rails and its dependencies, run:

gem install bundler
bundle install

NOTE: You may encounter issues installing gems. If you do, investigate the errors. You may require additional libraries that can be install with homebrew.

Next, the database needs to be created. If Rails is installed correctly, this command will create the ceqr_rails database, load the schema, and seed the db with some initial data.

bin/rails db:create db:schema:load db:seed

Setting up Ember

The Ember app sits in the frontend directory. It's served by the Rails app using ember-cli-rails gem.

To install Ember and its dependenices, run:

cd frontend
yarn install

Running the app

For the backend:

cd backend/
bin/rails s

For the frontend:

cd frontend/
yarn start-with-backend

Troubleshooting Rails server

If you receiver a Address already in use error for "127.0.0.1" port 3000, you may need to kill off some Ruby processes.

  1. List out processes which are using port 3000:
lsof -wni tcp:3000
  1. End the processes:
kill -9 <pid>
  1. Try rails s again.

Running the tests

rspec