Public Repository

Last pushed: 2 months ago
Short Description
Short description is empty for this repo.
Full Description

BBW API

Overview

The project consists of 4 Docker containers:

  • postgres: DB container
  • data: Shared valume so postgres data persists
  • web: API wrapped in gunicorn
    • This is called web in the test versions of docker-compose and Dockerfile
  • nginx: NGINX layer. Connects Gunicorn to localhost:80

Dependencies

  • Docker

I also highly recommend you install Anaconda for Sublime Text

Basic Info

All commands in this README depend on the docker-containers being up.
Nearly all commands happen from /bin/bash in web container.
To start your Docker containers and access /bin/bash from the web container, do the following:

# Kill and rebuild any currently running containers
docker-compose kill; docker-compose build;

# Start Docker (leave this running and keep eye on logs)
docker-compose up

# Run /bin/bash in the web container (in a new terminal)
docker-compose run web /bin/bash

Initial DB Setup ()

# Execute this command from the host machine after running docker-compose up
docker-compose run postgres psql -h postgres -U postgres -d terraintracker -c 'CREATE EXTENSION postgis'


# Create db tables (back in web container)
docker-compose run web /bin/bash
python manage.py db upgrade
python manage.py initialize

Testing

Make sure your db is up-to-date before testing

# Run unit tests
docker-compose run web python ./setup.py test

# Run tests with coverage [WIP, may not work]
docker-compose run web /bin/bash
python setup.py install
cd terraintracker
py.test --cov terraintracker --cov-report=html
# open htmlcov/index.html

# Run individual test
docker-compose run web /bin/bash
python setup.py install
py.test -s <path_to_test_file>

# Lint
python setup.py lint

Curl the geo endpoint

docker-compose up
curl -u adam:'Test!234' 'http://localhost/geo/isWater?lat=19.1&lon=10.1'

Changing the db (Alembic migrations)

First, make the changes in the the code (models folder). Then auto-generate a new migration file with

docker-compose run web python manage.py db migrate

Now, edit the new Python file in web/migrations/versions so that it makes sense.
If you see a table/index in the migration file Alembic provided and you think

Alembic should ignore it forever, add it to [alembic:exclude] in alembic.ini

Then, run you migration file with:

docker-compose run web python manage.py db upgrade


## Adding columns to live db config

See: live_configuration.py for instructions.



#### Run psql on postgres container

docker-compose run postgres psql -h postgres -U postgres -d terraintracker


## BURN IT DOWN

This initializes a clean application. Destroys all Docker containers on your system. Removes all data.

Kill and restart all containers, including volumes holding DB tables - CAUTION: YOU WILL LOSE DATA

docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q) && docker volume rm $(docker volume ls -q) && docker-compose build && docker-compose up -d

Give Postgres a chance to initialize

sleep 40 # wait a lil bit for the containers to come up

In a new terminal:

Migrate. Add initialization data (default users, etc). Test.

docker-compose run web python ./manage.py db upgrade
docker-compose run web python ./manage.py initialize
docker-compose run web python ./setup.py test
```

Deployment

Docker Cloud

TODO

Docker Pull Command
Owner
gobulls1026

Comments (0)