-
Notifications
You must be signed in to change notification settings - Fork 105
Docker Setup for Local Development
tmpayton edited this page Jan 14, 2025
·
9 revisions
This guide will walk through the process of setting up the API locally using Docker. It will show how to configure the environment variables, provide commonly used Docker commands, configure the database, and run pytest and locust.
- Clone this repository
- Install Brew
- Install docker engine using brew:
brew install docker
- Install docker-compose using brew:
brew install docker-compose
- Install rancher using brew:
brew install rancher
- Install nvm using brew:
brew install nvm
- Use nvm to install our current node version:
nvm install node <node version>
(version can be found in our package-lock.json file) - In the project directory install dependencies and build the project:
npm install && npm run build
- Open the rancher desktop application
- In rancher navigate to the
Extensions
tab on the left, then add theLogs Explorer
extension
- In rancher navigate to the
Set the following environment variables:
Required:
export SQLA_CONN=<XXXX>
export SQLA_SAMPLE_DB_CONN=postgresql://postgres:password@db:5432/cfdm_test
export SQLA_DOCKER_DB_CONN=postgresql://postgres:password@db:5432/cfdm_test
export SQLA_TEST_CONN=postgresql://postgres:password@db:5432/cfdm_unit_test
Optionally set environment variables for running redis/celery and locust locally:
export AWS_ACCESS_KEY_ID=<XXXX>
export AWS_SECRET_ACCESS_KEY=<XXXX>
export AWS_PUBLIC_BUCKET=<XXXX>
export AWS_DEFAULT_REGION=<XXXX>
export FEC_DOWNLOAD_API_KEY=<XXXX>
export FEC_WEB_API_KEY_PUBLIC=<XXXX>
export SLACK_HOOK=<XXXX>
-
Build the image:
- with cache (faster):
docker-compose build
- without cache:
docker-compose build --no-cache
- with cache (faster):
-
Start Services:
- Start database, flask-app, and elasticsearch (Recommended):
docker-compose up openfec db elasticsearch
- Start services in background:
docker-compose up -d openfec db elasticsearch
- Start all services:
docker-compose up
- Start a singular service (openfec, db, redis, celery-worker, celery-beat, or elasticsearch):
docker-compose up <Service> -d
- Stop all services:
docker-compose down
- Stop a singular service (oopenfec, db, redis, celery-worker, celery-beat, or elasticsearch):
docker-compose down <Service>
- Restart all services:
docker-compose restart
- Start database, flask-app, and elasticsearch (Recommended):
To populate local database:
- Ensure database and API are running:
docker-compose up -d db openfec
- Drop database if exists
docker-compose exec -it db dropdb -U postgres cfdm_test
- Recreate database
docker-compose exec -it db createdb -U postgres cfdm_test
- Run task:
docker-compose exec openfec invoke create_sample_db
- View local version of API at http://127.0.0.1:5000
To use local database:
- remove SQLA_CONN:
unset SQLA_CONN
- Stop services:
docker-compose down
- Start services again:
docker-compose up -d openfec db
- Ensure services are running:
docker-compose up -d openfec db elasticsearch
- Run pytest:
docker-compose exec openfec pytest
- Ensure openfec is running:
docker-compose up -d openfec
- Run locust:
- Dev:
docker-compose exec openfec locust --host=https://fec-dev-api.app.cloud.gov/v1/ --logfile=locustfile.log
- Stage:
docker-compose exec openfec locust --host=https://api-stage.open.fec.gov/v1/ --logfile=locustfile.log
- Prod:
docker-compose exec openfec locust --host=https://api.open.fec.gov/v1/ --logfile=locustfile.log
- Dev:
- Open localhost:8089 to run tests