Skip to content

viralemergence/pharos-api

Repository files navigation

Pharos

This repository is part of the Pharos project which is split into three repositories:

Repository Purpose
pharos-frontend Frontend application and deployment infrastructure
pharos-api API and deployment infrastructure
pharos-database SQL database and deployment infrastructure
pharos-documentation Markdown files used to generate about pages



Pharos API

🚀 Deployment Status

Click the badges below to view more information about builds on that branch. Changes pushed to any CI/CD branch will automatically be deployed to the corresponding environment.

Branch CI/CD Status Url
prod CircleCI https://rt036ira4i.execute-api.us-west-1.amazonaws.com/Prod/
staging CircleCI https://x77ethnbni.execute-api.us-west-1.amazonaws.com/Prod/
review CircleCI https://wc85irdg5d.execute-api.us-west-1.amazonaws.com/Prod/
dev CircleCI https://9itsn2ewjb.execute-api.us-west-1.amazonaws.com/Prod/

👩‍💻 Development Quick start

  1. Install AWS CLI
  2. Configure AWS SSO using the Pharos AWS Access Portal
  3. Install AWS SAM CLI
  4. Create a development stack using the following command:
sam sync \
  --stack-name pharos-api-[DEVELOPER_NAME]-dev \
  --region us-east-2
Argument Source
--stack-name Naming convention: pharos-api-[DEVELOPER_NAME]-dev
--region us-east-2 because the API and pharos-database should be in the same region
--profile Optional, if [default] profile is set.
Configure AWS SSO using the Pharos AWS Access Portal

This will deploy a new pharos stack, and output the Api url, ClientId, and UserPoolId which should be passed to the pharos-frontend develop command.

Additional arguments for the sam sync command can be found here.

Run Database & Tests Locally

1. Start local testing database using Docker:

This command will start a docker container called pharos-pytest-database which is intended to be a completely throwaway database (will not persist data on shutdown) only for running local tests using pytest.

The database will be populated with records during the course of running tests as necessary.

docker run --rm \
    -P -p 127.0.0.1:5432:5432 \
    -e POSTGRES_PASSWORD="1234" \
    -e POSTGRES_DB="pharos-pytest" \
    --name pharos-pytest-database \
    postgis/postgis

2. Install and source dev dependencies

python3.9 -m venv env .
source env/bin/activate
pip install -r dev-requirements.txt

3. Run project tests

source env/bin/activate
pytest -v --cov=src/libraries/python/

This command also creates and displays a coverage report, the full interactive coverage report can be viewed in a browser on port 8080 (chosing 8080 just because the frontend runs on 8000) with the command:

source env/bin/activate
pytest -v --cov=src/libraries/python/ --cov=src/lambda/ --cov-report=html
cd htmlcov; python -m http.server 8080

🏙️ Deployment Infrastructure

All infrastructure is managed in template.yaml, and all changes to that template should be deployed by committing to a CCI tracking branch.

Pharos is a hybrid serverless application, so multiple deployments of pharos-api will create multiple independent stacks with separate serverless resources, but the deployments will share the database server and networking resources deployed by the pharos-database stack. This means there is no marginal cost to deploying additional instances of pharos-api, because these resources are billed only according to usage.

In general, pharos-api consists of two api gateways, one for binary output for map tiles, and one for JSON output, which serves all other API routes. Each API route is served by a lambda function, with permissions to access stateful resources (DynamoDB and S3) or the database server (deployed as pharos-database) as necessary.

Simplified Infrastructure Diagram

Overview diagram

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published