This repository contains code relevant to Pelleum's backend API. This API responds to requests sent from Pelleum's frontend mobile application.
- Run
python3 -m pip install --user --upgrade pip
- Run
python3 -m pip install --user virtualenv
- Run
python3 -m venv env
- Activate virtual environment with
source env/bin/activate
- Install packages with
python3 -m pip install -r requirements.txt
- See "Makefile Targets" section for Makefile setup
- With an activated virtual environment, run
pip freeze > requirements.in
- Run
make requirements.txt
To migrate a new table or make a change to an existing table:
- Add a new model file or change an existing one found in the /models directory
- Run:
make migration rev_id=<YOUR REVISION ID> migration_message="your migration message"
Example:make migration rev_id=0002 migration_message="Added payments table"
- This will auto-generate alembic files in the /migrations/versions directory, which are used for migration
- From there, provided you have a docker postgreSQL database up and running (
docker-compose up -d db
), you can migrate your changes by runningmake migrate
- Install Docker
- Set environment variables in
.env
file in the project's root directory (get from senior engineer) - Run
docker-compose up -d db
(this spins up a local PostgreSQL database for the API to utilize) - Run
make run
(this runs server locally)
The following are helpful commands that utilize this project's Makefile. To ensure theses work for you, do the following:
- Install
make
. If on MacOS, you can use Homebrew. - Add
alias make='gmake'
to yourbash_profile
(or similar), which you can access at~/.bash_profile
. After adding this, you'll need to restart your terminal for it to take effect. make --version
should be 4.3 or higher.
make run
: runs the API locallymake build
: builds the app's docker imagemake push
: pushes image to Docker Hubmake format
: formats the code using black and sorts imports using isort. Running this target is necessary for continuous integration.make test
: starts continuous integration, which includes running all unit testsmake migration
: see "Migrating Database Schemas" sectionmake migrate
: migrates a schema to a target database
- Can use Postman to test calls (Can get Postman collection from senior engineer)
- Can also test calls via API Docs
As mentioned above, continuous integration is initiated by running make test
. Running this command will:
- Spin up the application's docker container a test postgreSQL database docker container for tests to utilize
- Lint the code using Pylint
- Check the code's format
- Configure the newly spun up database
- Run unit tests
Note: These docker containers utilize a tests.env
file.
Unit tests can be run manually by running invoke tests
or by running them individually using your IDE. Before running them, be sure to:
- Spin up the test postgreSQL docker container by running
docker-compose up -d test_db
- Create
account_connections
schema using PgAdmin or by running:CREATE SCHEMA account_connections
. - Migrate database tables by running
alembic upgrade head
(you can temporarily change the database URL in the env.py file to run alembic against the test database)
- Run
docker login
, get credentials from Bitwarden - Run
docker build -t pelleum/pelleum-api .
(ormake build
) to build the docker image - Run
docker push pelleum/pelleum-api
(ormake push
) to push the image to Docker Hub - Verify that the image has been updated in Docker Hub
- Update pelleum-api service in AWS console
- Make sure to use latest version and check the "Force new deployment" box
- Verify by viewing logs in CloudWatch