Skip to content

Local Development

Rick Waldron edited this page May 10, 2022 · 12 revisions

Project Setup

  1. Install Node.js (version 12.0.0).

  2. Install yarn (version >=1.19.x): npm install yarn@latest -g

  3. Install Dependencies: yarn install

  4. Set up local database: Local Database Setup

  5. Download Heroku CLI and make a Heroku account if you do not have one. You will need to be added to the Heroku app "teacher-moments-staging".

  6. Set up local environment configuration

    • This is the list of all environment variables that are are pre-populated in config/dev, need to be exported prior to running the Teacher Moments server:
      ENV=dev
      
    • Run heroku config --app teacher-moments-staging --shell and copy the output for the following into config/dev-heroku-secrets:
      AWS_ACCESS_KEY_ID=...
      AWS_SECRET_ACCESS_KEY=...
      DATABASE_URL=...
      DCSS_BRAND_LANDING_PAGE_URL=...
      DCSS_BRAND_LOGO=...
      DCSS_BRAND_NAME_TITLE=...
      DCSS_BRAND_OWNER=...
      ENV=...
      HEROKU_POSTGRESQL_ORANGE_URL=...
      NEW_RELIC_LICENSE_KEY=...
      NEW_RELIC_LOG=...
      NODE_ENV=...
      PAPERTRAIL_API_TOKEN=...
      PGDATABASE=...
      PGHOST=...
      PGPASSWORD=...
      PGSSLMODE=...
      PGUSER=...
      REDIS_TLS_URL=...
      REDIS_URL=...
      REDIS_USE_SSL=...
      S3_BUCKET=...
      SENDGRID_API_KEY=...
      SENDGRID_PASSWORD=...
      SENDGRID_SENDER=...
      SENDGRID_USERNAME=...
      SESSION_SECRET=...
      SQL_DEBUG=...
      WATSON_KEY=...
      WATSON_SPEECHTOTEXT_KEY=...
      WATSON_SPEECHTOTEXT_URL=...
      WATSON_URL=...
      WATSON_VISREC_KEY=...
      WATSON_VISREC_URL=...
      
  7. Start the development server

    • If you are using Mac or Linux, export the required environment variables first:
      source config/dev; source config/dev-heroku-secrets;
      
    • And then run the dev server with:
      yarn dev
      
      ...You should see your local site at http://localhost:3000.

Linting Code

This project uses Eslint for linting. To catch syntax and style errors, run

yarn lint

This linting command also runs on Travis CI when you submit a PR.

Local Database Setup

  1. Export config/dev

    source config/dev;
    

    You may need to run:

    export PGUSER=`whoami`;
    
  2. Install PostgreSQL (unless already installed)

  3. Start PostgreSQL and make yourself a default database

    • Mac:
      brew services start postgresql
      createdb # creates a default database under your user name
      
    • Linux
      sudo su postgres
      createuser --interactive # enter your username and make yourself a super user
      su yourusername
      createdb # creates a default database under the current user
      
  4. Initialize local database

    • The following should be run with a $PGUSER & $PGPASSWORD for a super user who can create databases and roles (see step 1):

      yarn db-init:dev
      

      This command creates a database called teachermoments and then sets up a role called tm and then creates all of the tables in teachermoments.

      To do this manually, create a database called teachermoments:

      createdb teachermoments
      

      Then create the role tm with a password teachermoments, then run:

      yarn db-migrate-up
      

Seeding a super_admin for local development

  • In the terminal, start teacher moments with the correct env vars and sql debugging enabled:
    export $(cat config/dev); SQL_DEBUG=1 yarn dev;
    
  • Then create a super admin user with the following command for a NEW user, you cannot run this command on an existing user. Put the new super admin's account details in the double quotes before running.
    yarn workspace server seed:super-admin email="" username="" password=""
    

You can now log in as your super user and adjust permissions for any other user as needed.

Clone this wiki locally