2013-07-18 23 views
7

Sto provando a distribuire il mio progetto django esistente con heroku, seguendo il percorso fornito da heroku e adattandomi in base alle necessità per essere specifico per il mio progetto. Giusto per scorrere velocemente quello che ho fatto finora:Django Deployment With Heroku

  • installato django-toolbelt nel mio virtualenv
  • creato un Procfile nella radice del mio progetto denominato Procile che comprende:

    web: gunicorn projectname.wsgi 
    
  • utilizzando foreman start confermato che il mio progetto ancora eseguita correttamente localmente

  • creato requirements.txt utilizzando 01.233.266,436102 millionse lo mise nella radice del mio progetto
  • aggiunto il testo seguente settings.py:

    import dj_database_url 
    DATABASES['default'] = dj_database_url.config() 
    
    # Honor the 'X-Forwarded-Proto' header for request.is_secure() 
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 
    
    # Allow all host headers 
    ALLOWED_HOSTS = ['*'] 
    
    # Static asset configuration 
    import os 
    BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 
    STATIC_ROOT = 'staticfiles' 
    STATIC_URL = '/static/' 
    
    STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'), 
    ) 
    

Questo è un punto in cui io sono un po 'confuso, la procedura dettagliata non ha fatto menzione di ciò che accade con le mie impostazioni db esistenti, lasciare così com'è, rimuovere, cambiare?

  • aggiunto quanto segue wsgi.py:

    from django.core.wsgi import get_wsgi_application 
    from dj_static import Cling 
    
    application = Cling(get_wsgi_application()) 
    
  • Heroku aggiunto come un telecomando git e spinto il mio progetto a Heroku. Ha funzionato.

  • heroku ps:scale web=1

Tuttavia, quando provo ad accedere al mio progetto ottengo una Application Error. Quando controllo lo stato con heroku heroku ps --app projectname, il dyno si è bloccato. Il riavvio non fa nulla.

heroku logs --app projectname rendimenti:

2013-07-18T00:01:14.246956+00:00 heroku[web.1]: Starting process with command `gunicorn projectname.wsgi` 
2013-07-18T00:01:16.054952+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Starting gunicorn 17.5 
2013-07-18T00:01:16.058972+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Listening at: http://0.0.0.0:55131 (2) 
2013-07-18T00:01:16.061566+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Using worker: sync 
2013-07-18T00:01:16.080073+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [INFO] Booting worker with pid: 7 
2013-07-18T00:01:16.091347+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:01:16.091347+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:01:16.091347+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [ERROR] Exception in worker process: 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:01:16.091558+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:01:16.091771+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:01:16.091771+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:01:16.091771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:01:16.091347+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:01:16.091771+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:01:16.091558+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:01:16.099257+00:00 app[web.1]: 2013-07-18 00:01:16 [7] [INFO] Worker exiting (pid: 7) 
2013-07-18T00:01:16.091771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:01:16.286985+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Shutting down: Master 
2013-07-18T00:01:16.288144+00:00 app[web.1]: 2013-07-18 00:01:16 [2] [INFO] Reason: Worker failed to boot. 
2013-07-18T00:01:17.956769+00:00 heroku[web.1]: Process exited with status 3 
2013-07-18T00:01:17.981029+00:00 heroku[web.1]: State changed from starting to crashed 
2013-07-18T00:11:46.404151+00:00 heroku[web.1]: State changed from crashed to starting 
2013-07-18T00:11:50.427658+00:00 heroku[web.1]: Starting process with command `gunicorn projectname.wsgi` 
2013-07-18T00:11:51.405718+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Starting gunicorn 17.5 
2013-07-18T00:11:51.406995+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Listening at: http://0.0.0.0:21344 (2) 
2013-07-18T00:11:51.407226+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Using worker: sync 
2013-07-18T00:11:51.418300+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [INFO] Booting worker with pid: 7 
2013-07-18T00:11:51.425145+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:11:51.425145+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [ERROR] Exception in worker process: 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:11:51.425145+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:11:51.425145+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:11:51.425341+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:11:51.425341+00:00 app[web.1]: Traceback (most recent call last): 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in spawn_worker 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  self.callable = self.load() 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  worker.init_process() 
2013-07-18T00:11:51.425341+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 115, in wsgi 
2013-07-18T00:11:51.425341+00:00 app[web.1]:  self.wsgi = self.app.wsgi() 
2013-07-18T00:11:51.425513+00:00 app[web.1]:  return util.import_app(self.app_uri) 
2013-07-18T00:11:51.425513+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 33, in load 
2013-07-18T00:11:51.425513+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 353, in import_app 
2013-07-18T00:11:51.425513+00:00 app[web.1]:  __import__(module) 
2013-07-18T00:11:51.425513+00:00 app[web.1]: ImportError: No module named projectname.wsgi 
2013-07-18T00:11:51.425868+00:00 app[web.1]: 2013-07-18 00:11:51 [7] [INFO] Worker exiting (pid: 7) 
2013-07-18T00:11:51.550395+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Shutting down: Master 
2013-07-18T00:11:51.550395+00:00 app[web.1]: 2013-07-18 00:11:51 [2] [INFO] Reason: Worker failed to boot. 
2013-07-18T00:11:52.851413+00:00 heroku[web.1]: Process exited with status 3 
2013-07-18T00:11:52.867339+00:00 heroku[web.1]: State changed from starting to crashed 
2013-07-18T00:14:14.285978+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=projectname.herokuapp.com fwd="173.54.54.86" dyno= connect= service= status=503 bytes= 
2013-07-18T00:14:14.405875+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=projectname.herokuapp.com fwd="173.54.54.86" dyno= connect= service= status=503 bytes= 

Qualsiasi aiuto/consiglio sarebbe molto apprezzato, ho trovato alcun modo per contattare Heroku direttamente su questo, tutto ciò che si riferisce qui a così.

risposta

0

Beh, non proprio sicuro. Sebbene la documentazione di heroku raccomandi il modo in cui hai provato. Non sono davvero sicuro di dove gunicorn venga installato in heroku e di come importi il ​​progetto django. Il modo più probabile che il processo/server con le impostazioni di Django sembra essere

web: bin/gunicorn_django --workers = 4 = --bind 0.0.0.0: $ PORT django_project/settings.py

come raccomandato qui: http://blog.abhiomkar.in/2011/09/17/deploying-django-on-heroku-mac-os-x/

+0

Grazie, tuttavia, ciò non spiega cosa succede con le impostazioni del mio database. – apardes

+0

Bene, puoi usare qualcosa come questo ATABASES = {'default': dj_database_url.config (default = 'postgres: // settings_stuff')}. Dovresti anche controllare https://devcenter.heroku.com/articles/heroku-postgresql#connection-in-python per capire come connetterti a db – dusual

2

Questo è un punto in cui mi sono un po 'confuso, la procedura dettagliata non ha fatto menzione di ciò che accade con le mie impostazioni db esistenti, lasciare così com'è, rimuovere, modificare?

Anch'io ho seguito la loro soluzione e ho avuto gli stessi problemi.Per me è stata l'affermazione dei DATABASES a fare l'errore. Ho sostituito la mia configurazione del database con quella che forniscono, mentre deve essere aggiunta al dizionario già creato dalle impostazioni del database. Così, invece di sostituire la sua dichiarazione del database è sufficiente aggiungere:

DATABASES['default'] = dj_database_url.config() 
2

C'è la possibilità che Heroku ha identificato il tipo sbagliato di applicazione durante il processo di compilazione. Questo è accaduto a me:

(venv)josephs-mbp:myproject josephfusaro$ git push heroku master 
Fetching repository, done. 
Counting objects: 27, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (13/13), done. 
Writing objects: 100% (14/14), 1.26 KiB | 0 bytes/s, done. 
Total 14 (delta 9), reused 0 (delta 0) 

-----> Node.js app detected 

Questo è saltato fuori a me, perché sto costruendo un'applicazione Python/Django. Mi sono imbattuto in this Stackoverflow thread che spiega come può accadere e mostra come è possibile eseguire l'override del pacchetto di build. Per questo esempio, saremo specificando il buildpack Python, ma è possibile istruire Heroku di utilizzare la buildpack per qualsiasi tipo di applicazione che si sta costruendo (click here for a full list)

heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python 
0

ho usato:

DATABASES = { 
'default': dj_database_url.config(default='sqlite:///db.sqlite') 
} 

questo modulo può essere utilizzato localmente e su heroku