Heroku relies upon GIT for deployment. The following commands are for deployment. Before deploying to Heroku make certain to run the following command* locally and commit the changes:
./manage.py collectstatic --noinput
* Currently this command fails to create the staticfiles dir on Heroku, so this has to be run locally and the changes committed.
Deploy to Heroku:
git push heroku master
If any of the models have been updated in a deployment then those changes have to migrated so the database schema is updated. The migration should be created locally, committed, and pushed to Heroku as opposed to running the makemigration command on Heroku. Locally run the following:
./manage.py makemigrations
or python manage.py makemigrations
(both commands have the same effect.)
Commit the files that are created.
In order to run those migrations, run the following commands:
heroku run ./manage.py migrate
or heroku run python manage.py migrate
(both commands have the same effect.)
Your schema will now be udpated.
DEBUG: This should always be False on the production site. Make certain the environment variable DEV_DEBUG is set to anything but the string 'True'. To check what variables are set to in Heroku's environment run the following command:
heroku config
This will list all config variables (alternatively go to the Settings section on the Heroku dashboard and click the 'Reveal Config Vars' button.)
A live development server works exactly the same way as a production server on Heroku does. All commands and configurations are the same. The only difference is that the requirements_dev.txt can be used on this server to have access to the various debugging tools.
Post deployment to a dev server runt he following command in order to install the dev tools (if desired):
heroku run pip install -r requirement_dev.txt
The migration commands presented in the Production section also hold true for development. Post deployment make sure to run the migration commands.
DEBUG: In order to turn DEBUG on, set the DEV_DEBUG environment variable to the string 'True'. DEBUG will be off id set to anything but 'True'. In order to change the DEV_DEBUG variable use the following command:
heroku config:set DEV_DEBUG='True'
The above command will turn DEBUG on. Setting to any other string will turn DEBUG off.
Postgres is used for this project. If PostgreSQL is not installed on your machine follow the instructions in the following links.
OS X: http://www.postgresql.org/download/macosx/
Ubunutu: https://help.ubuntu.com/community/PostgreSQL
Windows (should support 7 & 8): http://www.postgresql.org/download/windows/
After PostgreSQL has been successfully installed make sure to create the taxcalc database.
For Ubuntu the command is:
createdb taxcalc
If you need to add a user and grant permissions make sure to have psql installed as well.
Make sure to create a directory wherever you keep your projects.
mkdir project_name
git clone [email protected]:OpenSourcePolicyCenter/webapp.git
conda create -n webapp pip python=2.7
source activate webapp
Install the required packages listed in the conda-requirements.txt file:
conda install --file conda-requirements.txt
Some of the packages are listed in a requirements.txt, which uses pip. Install pip:
conda install pip
Then use pip to install the remaining packages
pip install -r requirements.txt
then:
pip install -r requirements_dev.txt
Since Django can be a more involved process using foreman might be a better tool for some situations. If no work will be done on the back end, then foreman might be the tool of choice (although once Django is setup all you will have to do is run the server locally to make use of it.)
Some important points:
- You must start the virtual environment.
- The Heroku toolbar that is installed with the requirements.txt file is expecting PostgreSQL to exist on your system.
After the environment is activated the following command will start foreman:
foreman start
Once the server has started foreman will use port 5000.
Once all the dependecies are installed a couple of commands are necessary to get the Django project up and running and onto ./manage.py runserver
. Make sure the virtual environment is activated.
In the settings.py file there is a database configuration that looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'taxcalc',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '',
'PORT': '5432',
}
}
- Change the USER to your user name (the one you used to setup Postgres).
- Change the PASSWORD to the password you used to setup Postgres.
- Change HOST to 127.0.0.1
PLEASE DO NOT COMMIT YOUR LOCAL CHANGES TO THE DATABASE CONFIG IN THE SETTINGS FILE. GIT STASH THEM!
Next change the DEBUG & TEMPLATE_DEBUG settings to True.
Second migrations have to been run. Migrations manage the schema for all database objects. Go to the root of the project simply run:
./manage.py migrate
Django will then run the migrations and all the tables will be created in the db. NOTE: it is critical that migrations are run when updating models, otherwise the changes to the models will not be recognized and errors will be thrown by Django (these errors tend to be increasingly informative and you will usually be prompted by Django that there are unmigrated changes when you run the local server.)
./manage.py runserver
Now you have a live project being run locally!