The purpose of this document is to provide detailed instructions to enable a new engineer to quickly get the various components up and running in a development environment.
Components
The Mustard web application consists of the following components:
The top level structure of the code consists of the following:
.vscode/ - Visual Studio Code editor settings
api/ - the rails app
deploy/ - deployment configurations and scripts
frontend/ - the angular app
.gitignore - file to ignore sensitive or temporary files from being committed to version control
docker-compose.yaml - configuration file for local development with docker
To download the code, open a bash terminal with git installed, and run
Once you’ve downloaded the repository locally, you’ll need to create environment files which contain ENV variables for each of your key environments. (development, staging, production).
2. Create the Backend Environment Files
The backend environment files live in the “mustard/api” directory of the project. To create, run the following.
3. Create the Frontend Environment Files
The frontend environment files live in the “mustard/frontend/src/environments” directory of the project. Due to the public nature of frontend code, any production config for the angular app will always be visible. This is why we already have the staging and production config files in this directory. To create the local environment file, run the following.
4. Run with Docker
Firstly, regardless of OS, you’ll need to install Docker. You can find instructions on how to install for your OS here: https://www.docker.com/get-started
Navigate to the root directory of the repository, and run the following.
Once all of the above are run and completed, you should be able to view the application locally at http://localhost:3000/. The first compilation of the angular app will take approximately 1 minute, and will not be available until complete.
5. Run without Docker
For more fine grained control during development, you may want to run the application outside of docker. This is less consistent with staging and production environments, and may also be inconsistent with other developer’s local environments, so care must be taken when developing without docker. Below outlines how you would run each part of the application by hand on MacOS, installation in other environments is not outlined.
Install dependencies
Install imagemagick
Install Redis
This requires adding the redis_url to the environment “./mustard/api/.env” locally as `REDIS_URL=redis://password@localhost:6379/0`
Install Postgres
Install Frontend dependencies
Install backend dependencies
Setup the Database
Navigate to the API directory and run the following to setup the database schema
Run the components
Backend
Background processing
Frontend
Common rails commands in docker
It is common during Ruby on Rails development to run certain commands to do things like migrate the database, run the rails console, view the currently configured routes or run rspec test suite.
$> cd ./mustard/api
$> touch .env # local
$> touch staging.env # staging
$> touch production.env # production
$> cd ./mustard/frontend/src/environments
$> cp sample-environment.ts environment.ts
$> docker-compose run api rails db:create # database setup
$> docker-compose run api rails db:setup # database setup
$> docker-compose run api rails db:migrate # database setup
$> docker-compose run frontend yarn install # frontend dependency installation
$> docker-compose up # run the server