From f58b762389c90f3b3c937c43282eab2b04f842f2 Mon Sep 17 00:00:00 2001 From: Aaron D Borden Date: Sun, 9 Apr 2017 18:29:03 -0700 Subject: [PATCH 1/4] Continuous deployment via travis-ci --- .travis.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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=" From 3ad1a28968062ef8cadd473538efdede03501c00 Mon Sep 17 00:00:00 2001 From: Aaron D Borden Date: Sun, 9 Apr 2017 18:51:07 -0700 Subject: [PATCH 2/4] Configurable ALLOWED_HOSTS Clean up settings guards for helpful hints setting environment settings. --- ballot_api/settings/heroku.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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') From 11298f497bff187711b7ffd9149408a10ce9c74b Mon Sep 17 00:00:00 2001 From: Aaron D Borden Date: Sun, 9 Apr 2017 20:21:41 -0700 Subject: [PATCH 3/4] Update README with deployment instructions --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c8a0e5..9895ffe 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,31 @@ 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. + +Env | 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. From 50f4726ebf52dce7734af4977359776caadbe5de Mon Sep 17 00:00:00 2001 From: Aaron D Borden Date: Tue, 18 Apr 2017 08:10:18 -0700 Subject: [PATCH 4/4] Fix markdown table display --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9895ffe..3759c09 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,12 @@ 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. -Env | 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 +| 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