rreddy
rreddy

Reputation: 95

Issues deploying django-nvd3 charts on heroku

Did any one try to deploy django-nvd3 charts on to Heroku recently with success? I was trying to deploy django application using nvd3 charts on to heroku the whole weekend with no luck. It works perfectly fine in my dev enviornment (ubuntu). However when I try to push it to Heroku, am facing all sorts of errors.

on Dev environment I installed npm (this includes node.js) and later installed bower and finally installed django-bower; as suggested on https://github.com/areski/django-nvd3. I tried different charts and all work okay, with no issues

However, when I was trying to push the code over to Heroku, I was hitting quite a few errors. Fixing one leads to others. I was wondering, if I need to add a package.json (to list npm dependencies like bower) and bower.json (to list bower dependencies like d3, nvd3) files to my repo, in the first place?

I googled a lot for some documentation that gives gun-shot info on this(django, nvd3, bower, npm/node all married together), but couldn't see any

Note: I will try to post heroku logs for more info.

bower.json is given something like:

{
"dependencies": {    
    "d3": "3.3.6",
    "nvd3": "1.1.12-beta"  
}

package.json is given something like:

"engines": {    
    "node": "0.11.11",    
    "npm": "1.3.25"    
 },  
"dependencies": {    
    "bower": "1.3.1"    
 }

Errors I encountered are something like:

1. gunicorn is not recognized - resolved this
2. NameError: Name 'DATABASES' is not defined in settings.py - resolved this
3. django.core.management is not found - resolved this
4. Git error: fatal: HEAD corrupted/ cannot be deployed on to heroku - resolved this
5. listening at localhost 127.0.0.1:8000 - am working on this. I think this is also to do with my DATABASES setting that is pointing at dj_database_url.config(default=['DATABASE_URL'])??

Is there any Git repo with django+nvd3charts that is deployed successfully on to Heroku? Can I have a look at the configuration?

Also looking at https://github.com/areski/django-nvd3; I do not see any bower dependencies or npm dependencies listed here, does it work like this?

Or, can Heroku automatically install npm/bower without package.json and also can it look at settings.py file and by looking at bower dependencies, does Heroku also install those dependencies with out a need for bower.json file to specifically listing d3, nvd3 as dependencies? I suppose its not the case, as far as I could see

Please suggest

Upvotes: 2

Views: 305

Answers (1)

Matt Harley
Matt Harley

Reputation: 358

I wrote a blog post about this which you find here: https://mattdoesstuff.wordpress.com/2015/04/10/getting-npm-d3-nvd3-django-bower-django-bower-nvd3-and-heroku-to-play-nicely-together/

Use django-nvd3 and django-bower

pip install django-nvd3 django-bower
pip freeze > requirements.txt
git add .
git commit -m "don't forget your requirements.txt!"

Use a multi-buildpack

heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git

Use the Node and Python buildpacks together

# ./.buildpacks
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/amanjain/heroku-buildpack-python-with-django-bower.git

Download bower using npm

# ./package.json
{"private": true,"dependencies": {"bower": "1.4.1"}}

User django-bower to collect its assets

# ./bin/post_compile
# install bower components
./manage.py bower_install

Tell django where to find bower

# settings.py
...
import os

APPLICATION_DIR = os.path.dirname(globals()['__file__'])
HEROKU = bool(os.environ.get('DATABASE_URL'))

BOWER_COMPONENTS_ROOT = os.path.join(APPLICATION_DIR, 'components')

# where to find your local bower
BOWER_PATH = '/usr/local/bin/bower'

if HEROKU:
    BOWER_PATH = '/app/node_modules/bower/bin/bower'

BOWER_INSTALLED_APPS = (
    'd3#3.3.13',
    'nvd3#1.7.1',
)
...

Credits * http://www.rawsrc.com/using-django-bower-on-heroku/ * https://github.com/ddollar/heroku-buildpack-multi.git * https://github.com/areski/django-nvd3

Upvotes: 1

Related Questions