Skip to content

BOC-Rubber-Duck/stock-app

Repository files navigation

Diamond Hands Stock App

Diamond Hands is an application to help beginners query, buy, & sell stock. See how you stack up against all the pros on Diamond Hands. Or add your friends for a friendly wager!

  • This Stock "paper-trading" app was the final capstone project for the Hack Reactor Software Engineering Immersive Program.
  • The Rubber Ducks engineering team were a part of the Remote Part Time Program Cohort 28 (RPP28)

Installation (Local Development)

In MacOS:

  • From the root directory, install the following:
  1. Download the Github repo:
 git clone git@github.com:BOC-Rubber-Duck/stock-app.git
  1. Download NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
  1. Install packages:
npm install

Dependencies

  • The app requires various packages available via NPM. All of these packages are enumerated in the package.json file in the repository. Installation instructions are in the following sections.

  • In addition to running a server, a PostgreSQL database instance will have to be deployed and accessible to the server. Instructions for doing so are below:

  • The stock prices are sourced via a free API service with https://marketstack.com. To get an API key, register for a free account with 1000 API requests/mo here: MarketStack API

Running Local

  • The following are the scripts that are relevent for local development and deployment (Found in package.json file):
  1. "react-dev" webpack build script
npm run react-dev
  1. "start" nodemon server start
npm start
  1. "test" jest testing
npm test
  1. "test-coverage" jest test with coverage
npm run test-coverage
  1. "react-prod" webpack build script in production mode
npm run react-prod

PostgreSQL Database Setup:

To run on MacOS: https://wiki.postgresql.org/wiki/Homebrew :

brew install postgresql
brew services start postgresql
psql postgres

Check services:

brew services

Login as "user"

psql -h localhost -p 5432 -U user -d database_name

run an .sql file to initialize (must be in same folder as command execution): Generic:

psql -h host -U username -d myDataBase -a -f myInsertFile

specific to this instance:

psql -h 127.0.0.1 -U user -d stonks -f setup.sql

Local PostgreSQL setup using docker:

Run a Docker image from official PostgreSQL image: https://wkrzywiec.medium.com/database-in-a-docker-container-how-to-start-and-whats-it-about-5e3ceea77e50

  1. run this command from the level that you would like to access the mounted files from:
docker run -d \
    --name postgres_db \
    -e POSTGRES_PASSWORD=<password> \
    -e POSTGRES_USER=user \
    -e POSTGRES_DB=stonks \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -p 5432:5432 \
    -v /custom/mount:/var/lib/postgresql/data \
    postgres
  1. check that the container is running:
sudo docker ps
  1. connect to a Docker containerized service from the host:
psql -h localhost -p 49153 -d docker -U docker --password

Deploy Production

CI/CD recommendations:

Continuous Integration:

We used Github's own actions functions to setup continuous integration. The test-suite.yml instructions are triggered on any Pull Requests before approval is allowed. More information can be found at: https://docs.github.com/en/actions/guides/about-continuous-integration

Continuous Deployment:

Use Github actions to trigger a new Docker image build on any push to main branch. Instrutions can be found in the docker-publish.yml file.

To Run on AWS EC2 Instance:

In the AWS instance, run the following commands to install docker, then deploy the app:

yum update
yum install docker

Set docker to start on reboot:

sudo systemctl enable docker
sudo systemctl start docker

Run the latest version of the app:

sudo docker run -d --name stonks-app -p 80:3000 ghcr.io/boc-rubber-duck/stock-app:main

By setting up a watchman service on the AWS instance, the newly deployed image will then trigger an image pull and re-deployment of the revised app. Instructions are found in the documentation for the watchman service here: https://containrrr.dev/watchtower/

Run the package with the following arguments to set the polling interval in seconds as well as several other usefull flags for development.

sudo docker run -d \
  --name watchtower \
  -v /var/run/docker.sock:/var/run/docker.sock \
    containrrr/watchtower \
  -i 600 \
  --cleanup \
  --debug

Run Database on AWS instance:

sudo yum update
sudo yum install docker
sudo systemctl enable docker
sudo systemctl start docker

Then run this script to pull down the official PostgreSQL docker image and run a container with the appropriate file mounting:

docker run -d \
    --name postgres_db \
    -e POSTGRES_PASSWORD=<password> \
    -e POSTGRES_USER=<user> \
    -e POSTGRES_DB=stonks \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -p 5432:5432 \
    -v /custom/mount:/var/lib/postgresql/data \
    postgres

Finally, you'll need to populate the database by running the scripts either locally from an ssh session in the instance, or via an exposed port remotely. Change to your database IP if accessing remotely.

psql -h localhost -p 49153 -d docker -U docker --password

Run the following commands from the './db/' folder of this project:

psql -h <IPADDRESS> -U user -d stonks -f setup.sql

Contributions

Members of the Rubber Duck Team (emoji key):


Alizeh Rehman

(Project Manager)
💻 📖

NylonEric

(Architecture Owner)
💻 📖

Margo Kearns

(UI Owner)
💻 📖

Bill Roth

(Software Engineer)
💻 📖

kingsleyallen

(Software Engineer)
💻 📖

Sam Brown

(Software Engineer)
💻 📖

tbrinkman3

(Software Engineer)
💻 📖

License

MIT

About

Fantasy Stock Trading Application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages