-
Notifications
You must be signed in to change notification settings - Fork 0
Continuous deployment via travis-ci #7
base: feature/heroku
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we be using the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just start with master. If we add additional environments we can change the branch later. |
||
|
||
# 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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,20 @@ | |
|
||
DEBUG = False | ||
|
||
ALLOWED_HOSTS = [ | ||
'caciviclab-ballot-api.herokuapp.com', | ||
] | ||
|
||
if 'ALLOWED_HOSTS' not in os.environ: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try this:
When it's stored in an env variable, we should be able to format like so: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'll try that. |
||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put this key in an environment variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think you could store Travis deploy secrets in an environment variable. As far as I know, storing encrypted secrets in the Travis config is the preferred way to do this.