/askdarcel-api

Backend of the "Ask Darcel" app.

Primary LanguageRuby

askdarcel-api Build Status

This project exposes the API endpoints for supporting the askdarcel-web project, which is built using a Ruby on Rails API Server

Docker-based Development Environment (Recommended)

Requirements

Docker Community Edition (CE) >= 17.06 Docker Compose >= 1.18

Download and install the version of Docker for your OS.

Creating the .env file

The .env file is a de facto file format that allows you to specify environment variables that can be read by an application. It makes it easier to pass environment variables to an application without manually having to set them in the environment. It is supported by:

Create a file named .env with the credentials listed in this document.

Set up the project

This is not a full guide to Docker and Docker Compose, so please consult other guides to learn more about those tools.

# Build (or rebuild) Docker images
$ docker-compose build

# Start the database container (in the background with -d)
$ docker-compose up -d db

# Generate random database fixtures
$ docker-compose run --rm api rake db:setup db:populate

# Start the Rails development server in the api container (in the foreground)
$ docker-compose up api

# Stop all containers, including background ones
$ docker-compose stop

Running Postman tests from the command line

# Reset DB with initial database fixtures
$ docker-compose run --rm api rake db:setup db:populate

# Run Docker container that executes Postman CLI tool named newman
$ docker-compose run --rm postman

Alternative database setup

# Populate the database with an old dump of the database (circa mid-2017)
$ docker-compose run --rm api rake db:create db:schema:load linksf:import

macOS-based Development Environment Not Using Docker

Install Dependencies

  1. Install Homebrew.
  2. Install rbenv and ruby-build.
  • brew install rbenv
    • Follow further setup instructions (including updating your bash profile) from the link above.
    • Add the following lines to your ~/.bash_profile
    export PATH="$HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"
    
  • brew install ruby-build
  1. Install postgres.
  • brew install postgresql
    • Follow further setup instructions displayed after installation.
  • brew services start postgres

Set up the project

After cloning the repository and cding into the workspace:

  1. Install the required ruby version.
  • rbenv install
  1. Install the bundle gem if it isn't yet installed.
    • which bundle || gem install bundle
  2. Install the required gems.
  • bundle install If encounter "command not found" error, run -source ~/.bash_profile
  1. Set up the Algolia credentials

    • Create a .env file in the root of your askdarcel-api directory
    • Populate that file with the backend environment variables found here
  2. Set up the development database and load dummy data.

  • rake db:create:all
  • rake db:migrate
  • rake linksf:import

Alternatively, you can generate random fixtures:

  • rake db:setup db:populate
  1. Run the development server.
  • rails s -b 0.0.0.0
  1. Do NOT do sudo install -rails