Skip to content

Commit

Permalink
changes for working with new project layout on Django 1.4, refactorin…
Browse files Browse the repository at this point in the history
…g of functions in fabfile to use different environments and simplified instructions on the fabfile comments
  • Loading branch information
alexisbellido committed May 24, 2012
1 parent 8562f31 commit 4c00fed
Show file tree
Hide file tree
Showing 7 changed files with 485 additions and 288 deletions.
13 changes: 7 additions & 6 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
The Django gunicorn fabfile project
======================================

Latest changes
===============

Modified the project directory layout to work with Django 1.4.

This is a bare Django project that includes a Fabric file, commonly known as a fabfile, to setup an Ubuntu 11.10 server with the following environment:

- Nginx to serve static files,
Expand All @@ -20,6 +25,8 @@ The fabfile has been tested with Fabric >= 1.3.1.
How to use
===============

** TODO ** This part needs updating for working with the new functions on the fabfile. See instructions on top of fabfile.py for now.

The two hosts interacting in the basic usage scenario are the deployer, which is the GNU/Linux workstation on which you will run the fabfile, and the target, which is the GNU/Linux server where the Django project will be setup when the fabfile is run. There are other hosts involved, like the one hosting the git repository with your code, but the deployer and the target are the ones where you have full control, including ssh root access.

This fabfile has been developed and tested using Ubuntu 11.10 and the standard software packages that are available via the Ubuntu repositories and PyPi, but it could be adapted to run with other GNU/Linux distributions.
Expand Down Expand Up @@ -53,8 +60,6 @@ There are some important points to notice in the local_settings_template.py. DEB

Modify INSTALLED_APPS as needed. For now the fabfile doesn't support running Django's syncdb and supposes you have a database already setup for the apps that you need.

Finally, ROOT_URLCONF is set to simply 'urls', to avoid depending on the project name. Django shouldn't have any problems with this.

6. Change to your project's directory and edit the required constants in fabfile.py; they are below the comment #### START OF CONFIGURATION ####. There are some comments to guide you.

7. Now it's time to run the fabfile to start setting up the target. Notice that user and host in the following commands refer to the user with sudo permission in the target and that host is the IP or hostname (public or as defined in your deployer's /etc/hosts).
Expand Down Expand Up @@ -88,19 +93,15 @@ The first parameter is the commit message that will be used for all repositories
TODO
==========

- A function to clean an interrupted setup.
- Put fabfile settings in a separe module or probably use the project's local_settings.py.
- Distribute via PyPi.
- Make the project generic to work with other versions of Ubuntu and Python.
- Add support for other version control systems.
- Add support for PyPi mirrors in setup_server function.
- Avoid duplication of virtualenvwrapper lines .basrc and .bash_profile.
- Support for Django test framework.
- setup git user and email with git config before starting with commit/push, using
git config --global user.name "Your Name"
git config --global user.email you@example.com
- Support for easier commit and push in the deploy function.
- Support for easily adding and setting up Django applications.
- Support for syncdb and database distribution. Is it needed or better left to do manually?
- Memcached setup.
- Varnish setup.
File renamed without changes.
31 changes: 20 additions & 11 deletions settings.py → django_gunicorn_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
Expand Down Expand Up @@ -40,9 +40,12 @@
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
# calendars according to the current locale.
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
Expand All @@ -62,11 +65,6 @@
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
Expand All @@ -83,7 +81,7 @@
)

# Make this unique, and don't share it with anybody.
SECRET_KEY = '+xh+&)d#!2=-fu@o(f*a#q)bvsqn-kz8n%mdq4w@+wzq@2$xu#'
SECRET_KEY = 's%-6o6w(#ri@dw*apwb2#2uxjl@sttnr7cs0kl&ugi5%_y-0!*'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
Expand All @@ -98,10 +96,15 @@
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'django_gunicorn_project.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'django_gunicorn_project.wsgi.application'

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
Expand All @@ -123,15 +126,21 @@

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
Expand All @@ -148,6 +157,6 @@
# This file should be outside of control version.
# Copy local_settings_template.py as a starting point.
try:
from local_settings import *
from local_settings import *
except ImportError:
pass
pass
2 changes: 1 addition & 1 deletion urls.py → django_gunicorn_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.conf.urls.defaults import patterns, include, url
from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
Expand Down
28 changes: 28 additions & 0 deletions django_gunicorn_project/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
WSGI config for django_gunicorn_project project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_gunicorn_project.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
Loading

0 comments on commit 4c00fed

Please sign in to comment.