This repo represents the backend development work for the Emergency Response Team of Hack Oregon 2016-17 Project Season. The development and deployment chain is modeled on the pattern contained here:
https://github.com/hackoregon/backend-service-pattern
- Docker or Docker toolkit
- Database Read-Only Credentials (assumes AWS, otherwise updated settings.py and project_config.py accordingly, Contact Emergency Response Team)
- Travis-CI (not required for local dev)
- Cluster deployment keys - Contact the DevOps team (not required for local dev)
- ECS Service Name - Contact the DevOps team (not required for local dev)
This API is built using Docker and Docker-Compose installed.
This project was setup in a single database environment. Development, testing, and production have been connecting to same database. Prior to granting any write access to API, especially for testing ensure to change:
- The database credentials below will need to change to no longer override the "TEST_NAME" to 'fire', change other db creds as needed. It will then create a 'test_fire' database to run tests on. One will need to create method for loading test data.
- Ultimately to destroy the test db with each run you will remove the --keepdb argument from the test scripts.
To run the API for the first time:
-
In the /emerresponseAPI folder create a file project_config.py. Make sure env.sh is in the .gitignore and .dockerignore:
AWS = { 'ENGINE': 'django.contrib.gis.db.backends.postgis', 'NAME': '<YOUR_AWS_DB_NAME>', 'HOST': '<YOUR_AWS_DB_NAME>', 'USER': '<YOUR_AWS_DB_NAME>', 'PASSWORD': '<YOUR_AWS_DB_NAME>', }
DJANGO_SECRET_KEY = <YOUR_DJANGO_SECRET>
-
Create
env.sh
in the project ./bin folder. Make sure env.sh is in the .gitignore and .dockerignore (You will provide values if deploying to your own cluster. For the Hack Oregon project, consult the team.):export DOCKER_REPO=<NOT HERE> export DOCKER_IMAGE=<NOT HERE> export PROJ_SETTINGS_DIR=<NOT HERE> export DEPLOY_TARGET=<NOT HERE> export CONFIG_BUCKET=<NOT HERE> export AWS_ACCESS_KEY_ID=<NOT HERE> export AWS_SECRET_ACCESS_KEY=<NOT HERE> echo "##############################" echo Your Local Project Environment echo "##############################" echo DOCKER_REPO: $DOCKER_REPO echo DOCKER_IMAGE: $DOCKER_IMAGE echo PROJ_SETTINGS_DIR: $PROJ_SETTINGS_DIR echo DEPLOY_TARGET: $DEPLOY_TARGET echo CONFIG_BUCKET: $CONFIG_BUCKET
-
From project root run:
$ ./bin/build-proj.sh -l (flag is for local)
Allow process to run, should build in a few minutes.
-
Run the tests: $ ./bin/test-proj.sh -l
-
To start project locally:
$ ./bin/start-proj.sh -l
-
Access the swagger docs at:
-
Consult here for CI/CD info: https://github.com/hackoregon/backend-service-pattern
-
For changes in the django code, stop the container and re-run the start-proj.sh command.
-
For any changes to the docker image, additions to the pip packages (requirements.txt), or other non-code changes rerun the build-proj.sh command.
-
If you are receiving a 'permission denied' notification on any of the shell commands, they may have lost the executable permission. run: $ chmod +x ./bin/. should correct the problem. You may choose to run command on individual files as well.
## to view admin page/browsable endpoints
## open your browser in host machine
## for endpoints preview:
$ http://localhost:8000/emergency/<endpoint>
## ie:
$ http://localhost:8000/emergency/agencies
Pagination currently set to 50
## To select page:
'http://localhost:4546/<endpoint>?page=NUM'
Thanks to all the members of the Hack Oregon Team. This repo represents the work of many volunteers including the Hack Oregon 2017 Emergency Response and DevOps teams.