This repository, under the umbrella of Project Cognoma (https://github.com/cognoma), holds the source code, under open source license, of a runnable django rest API, a component in the overall system specified in Project Cognoma.
Make sure to fork this repository on +GitHub first.
- Docker - tested with 1.12.1
- Docker Compose - tested with 1.8.0
docker-compose up
Sometimes the postgres image takes a while to load on first run and the Django server starts up first. If this happens just ctrl+C and rerun docker-compose up
The code in the repository is also mounted as a volume in the core-service container. This means you can edit code on your host machine, using your favorite editor, and the django server will automatically restart to reflect the code changes.
The server should start up at http://localhost:8080/, see the API docs.
Accessing the root API endpoint (ex: http://localhost:8080/) will bring up the Swagger UI for viewing the API.
Note: swagger will only display endpoints that you are authorized to
view. In order to authenticate, go to the top right corner and click
Authorize
. Where it says api_key
, type in Bearer <your_random_slug_here>
and hit enter to authenticate for the rest of the session.
Make sure the service is up first using docker-compose up
then run:
docker-compose exec core python manage.py test
To load data, again with service up run:
docker-compose exec core bash
python manage.py acquiredata
python manage.py loaddata
To verify, run curl http://localhost:8000/diseases/
to get a list of all diseases.
Or, run curl http://localhost:8000/samples?limit=10
to view data for 10 samples.
This project is deployed within the Greene Lab AWS account. To be able to deploy this project you will need to:
- Be invited to the account.
- Receive an AWS access key and secret key.
This project leverages AWS Ec2 Container Service (ECS). ECS provides a private container registry called the Ec2 Container Repository (ECR). To be able to push Docker images to this repository you will first need to get a login with:
aws ecr get-login --region us-east-1
and then run the output of that command. It will look something like:
docker login -u AWS -p <A_GIANT_HASH> -e none https://934349674827.dkr.ecr.us-east-1.amazonaws.com
This project uses two containers: one for Nginx and one for the core-service.
You will probably be deploying only the core-service unless you have modified
config/prod/nginx.conf
.
Run these commands:
docker build --tag cognoma-core-service .
docker tag cognoma-core-service:latest 934349674827.dkr.ecr.us-east-1.amazonaws.com/cognoma-core-service:latest
docker push 934349674827.dkr.ecr.us-east-1.amazonaws.com/cognoma-core-service:latest
Run these commands:
docker build --tag cognoma-nginx --file config/prod/Dockerfile_nginx .
docker tag cognoma-nginx:latest 934349674827.dkr.ecr.us-east-1.amazonaws.com/cognoma-nginx:latest
docker push 934349674827.dkr.ecr.us-east-1.amazonaws.com/cognoma-nginx:latest
Navigate to
Cognoma's ECS Tasks Page
and select the tasks corresponding to the container you are deploying.
The tasks will have a Task Definition like either cognoma-core-service:X
or cognoma-nginx:X
which can be used to determine which are the correct
tasks. Once you have selected the correct tasks click the Stop button.
This will cause the tasks to be stopped and ECS will restart them with the
new version of the container you have pushed. Therefore you're now done.