-
Notifications
You must be signed in to change notification settings - Fork 105
Docker Setup for Local Development
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 Docker for personal use
-
Install Brew
- Use brew to download nvm:
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
- Use brew to download nvm:
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):
-
View local version of API at http://127.0.0.1:5000
To populate local database:
- Ensure database and API are running:
docker-compose up -d db openfec
- Drop database
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
- Or populate db using flyway:
docker-compose exec openfec flyway migrate -configFiles=/app/data/flyway.toml
- Or populate db using flyway:
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
The above examples the command docker-compose exec <Service> <Command>
to run commands in service containers. Alternately, commands can be run in the Exec tab of a service in docker desktop. For pytest could be run like this in the openfec container: