diff --git a/.travis.yml b/.travis.yml index 02cb7de..691fb27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,14 @@ language: python python: - 3.6 -script: flake8 +script: + - flake8 + - python manage.py test + +deploy: + provider: heroku + app: caciviclab-ballot-api + run: python manage.py migrate + on: master + api_key: + secure: "FE+fi/wY2+LfPP2WZW1Tvvw24+ijldCr7BqIzeeHtKIdu8QK5WOhgdZ8rgkUXtoeGWx3j9vvGeaRCdmQr06kfJ2qk8dsidKSxiAPu3uvL4ppGwqhB+EqgDdMNoUKvStYeBdSNYOpytWYUOdKMu6DPUGwMxGQwItwmtNAHYTZ4ciTno6sdIaFi0/UXoPixGAgvxR+VzgNANy6+86Kl4dO9LMAHmeaPPebmQFOV4WvutEoryHsPklOJHDFEBcUnqRA1YK1FPPZ9Fpy88ZPF6Alx8O0f5B3TxadSgtEqgTMp7FGkpcGE9dh4/Tb6MESm/6l3EANNEEMs9iCqpvA3dboTcSqUkb7yqbEqt5Th5pB/gWxthgvlM25EiE/hCa36jB8kUAO/XjaH1QKBr7SwtvywzDdW4Xn5JXlsunQa3eW/GDUV4oADwRjGjq6kqQADj+FX19jLMR+NhBjZvJ4qQx43wSz8yKBWURl/oN/9B2YuEJJ//OtA8mEtLtL0vphiNXp4T6w/RcVL8hj5Jfe61ULgfX51QwRjbnzXJf0JurvfOZJBbO48K8ZPv0u1FTZ7Bn2QjSGo/bha+IHwUyqjaBEudrpbShE+BQ+YNcBOB2YnR0Zgi1n4snO1uZ3+V0HirtTsiHfDJdSA07l8jDWW4x9lbDFTmXEA6UwYOsOohTwZgc=" diff --git a/README.md b/README.md index 1c8a0e5..3759c09 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Build -Status](https://travis-ci.org/adborden/ballot-api.svg?branch=master)](https://travis-ci.org/adborden/ballot-api) +Status](https://travis-ci.org/caciviclab/ballot-api.svg?branch=master)](https://travis-ci.org/caciviclab/ballot-api) # Ballot API @@ -20,3 +20,32 @@ California. $ python manage.py runserver And open your browser to http://localhost:8000 + + +## Development + +Please don't forget to run the tests. + + $ flake8 + $ python manage.py test + + +## Deployment + +The ballot-api can easily be deployed to Heroku. After creating an initial app +in Heroku, you'll want to set these environment variables. `DATABASE_URL` should +be set automatically after enabling the PostgreSQL add-on. + +| Environment variable | Description | Example | +| ------------------------ | ----------- | ------- | +| `ALLOWED_HOSTS` | Comma-separated list of host names for the app | caciviclab-ballot-api.herokuapp.com | +| `DATABASE_URL` | [Database connection URL](https://pypi.python.org/pypi/dj-database-url) (set by PostgreSQL add-on) | postgresql://user:password@hostname:port/database_name?options | +| `DJANGO_SETTINGS_MODULE` | Settings module to use for Django | ballot_api.settings.heroku | +| `SECRET_KEY` | Django secret key | a-random-string-of-50-characters | + + +### Continuous deployment + +The `caciviclab-ballot-api` is deployed continuously to Heroku via Travis by merging to +the `master` branch. Once tests and linting checks are good, `master` is +deployed and any pending migrations will be run. diff --git a/ballot_api/settings/heroku.py b/ballot_api/settings/heroku.py index 6c4a277..9409743 100644 --- a/ballot_api/settings/heroku.py +++ b/ballot_api/settings/heroku.py @@ -8,13 +8,20 @@ DEBUG = False -ALLOWED_HOSTS = [ - 'caciviclab-ballot-api.herokuapp.com', -] + +if 'ALLOWED_HOSTS' not in os.environ: + raise Exception('ALLOWED_HOSTS environment variable must be set to a comma-separated list of host names for heroku configuration.') + +ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(',') + + +if 'DATABASE_URL' not in os.environ: + raise Exception('DATABASE_URL environment variable must be set for heroku configuration.') DATABASES['default'] = dj_database_url.config() -SECRET_KEY = os.environ.get('SECRET_KEY', None) -if not SECRET_KEY: +if 'SECRET_KEY' not in os.environ: raise Exception('SECRET_KEY environment variable must be set for heroku configuration.') + +SECRET_KEY = os.environ.get('SECRET_KEY')