Parcourir la source

Use dj_static and gunicorn to run the application

Baptiste Jonglez il y a 9 ans
Parent
commit
dca4d7a4bb
4 fichiers modifiés avec 33 ajouts et 8 suppressions
  1. 26 6
      INSTALL.md
  2. 1 1
      celutz/settings.py
  3. 3 1
      celutz/wsgi.py
  4. 3 0
      requirements.txt

+ 26 - 6
INSTALL.md

@@ -34,15 +34,35 @@ should look like this:
     python manage.py migrate
     python manage.py migrate
     python manage.py createsuperuser
     python manage.py createsuperuser
 
 
+Development
+-----------
+
+Just run the builtin Django server:
+
+    ./manage.py runserver
+
+Alternatilevy, you can use gunicorn exactly like in production.
+
+You also need to launch a celery worker (see below).
+
 Production
 Production
 ----------
 ----------
 
 
-One specific information for production usage: you **really** want to serve
-the `media/` directory with a real webserver, and **not** with Django itself.
-Hundreds of tiles (small image files) will be served from this directory each
-time a client visualises a panorama.
+- change DEBUG to False in settings.py
+- change the secret key
+- set the `ALLOWED_HOSTS` variable
+- collect static files with `./manage.py collectstatic`
+
+Finally, run the WSGI server, for instance gunicorn:
+
+    gunicorn celutz.wsgi:application
+
+Internally, `dj_static` is used to serve static and media files (including tiles).
+
+As an alternative, you may wish to serve media files (everything in `media/`)
+with your web server directly.
 
 
-You probably also want to configure your webserver to allow to send very large
+You probably also need to configure your webserver to allow to send very large
 files in a POST request.  An upper limit of 200 MB should be enough, even for
 files in a POST request.  An upper limit of 200 MB should be enough, even for
 very large pictures in raw format.
 very large pictures in raw format.
 
 
@@ -51,7 +71,7 @@ Tile generation
 
 
 Tile generation uses Celery, because it is quite a heavy task CPU-wise.
 Tile generation uses Celery, because it is quite a heavy task CPU-wise.
 
 
-To launch a celery worker while developping, run this in your virtualenv:
+To launch a celery worker, run this in your virtualenv:
 
 
     celery -c 1 -A celutz.celery worker --loglevel=info
     celery -c 1 -A celutz.celery worker --loglevel=info
 
 

+ 1 - 1
celutz/settings.py

@@ -84,7 +84,7 @@ USE_TZ = True
 
 
 # Static files (CSS, JavaScript, Images)
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.7/howto/static-files/
 # https://docs.djangoproject.com/en/1.7/howto/static-files/
-
+STATIC_ROOT = 'static'
 STATIC_URL = '/static/'
 STATIC_URL = '/static/'
 
 
 
 

+ 3 - 1
celutz/wsgi.py

@@ -11,4 +11,6 @@ import os
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "celutz.settings")
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "celutz.settings")
 
 
 from django.core.wsgi import get_wsgi_application
 from django.core.wsgi import get_wsgi_application
-application = get_wsgi_application()
+from dj_static import Cling, MediaCling
+
+application = Cling(MediaCling(get_wsgi_application()))

+ 3 - 0
requirements.txt

@@ -2,9 +2,12 @@ amqp==1.4.7
 anyjson==0.3.3
 anyjson==0.3.3
 billiard==3.3.0.20
 billiard==3.3.0.20
 celery==3.1.18
 celery==3.1.18
+dj-static==0.0.6
 Django==1.8.5
 Django==1.8.5
 djangorestframework==3.2.4
 djangorestframework==3.2.4
+gunicorn==19.3.0
 kombu==3.0.28
 kombu==3.0.28
 Pillow==2.9.0
 Pillow==2.9.0
 pytz==2015.6
 pytz==2015.6
+static3==0.6.1
 wheel==0.24.0
 wheel==0.24.0