Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

separate fabconfig.py file for using as template of configuration to …

…be added to settings.py
  • Loading branch information...
commit 4b60b415b8ee0c4bda198c9344dcb17b48ca3728 1 parent 294a725
@alexisbellido authored
Showing with 161 additions and 128 deletions.
  1. +1 −127 README
  2. +125 −0 fabconfig.py
  3. +35 −1 fabfile.py
View
128 README
@@ -68,132 +68,6 @@ $ pip install Fabric
4a. To copy this project to your own Django project, you just need to copy the file fabfile.py and the directory deploy, both in the root of this project, to the root of your project and then add the following at the end of your project's settings.py:
-#### START OF FABRIC CONFIGURATION ####
-
-# Use local_settings.py to override settings.
-# This file should be outside of control version.
-# Copy local_settings_template.py as a starting point.
-try:
- from local_settings import *
-except ImportError:
- pass
-
-# DO NOT USE TRAILING SLASH AND USE UNDERSCORES IN DIRECTORIES TO MIMIC django-admin.py starproject.
-PROJECT_USER = 'user'
-
-PROJECT_NAME = 'django_gunicorn_project' # Used for upstart script and virtualenv
-PROJECT_DESCRIPTIVE_NAME = 'The Django gunicorn project' # Used as description in upstart script
-
-# with the new Django 1.4 project layout there's an inner project directory at PROJECT_DIR/PROJECT_INNER_DIR
-PROJECT_DIR = '/home/user/django_gunicorn_project'
-PROJECT_INNER_DIR = 'django_gunicorn_project'
-PROJECT_LOGDIR = '/home/alexis/logs/django_gunicorn_project'
-PROJECT_SCRIPT_NAME = 'run-' + PROJECT_NAME
-
-PROJECT_DOMAIN = 'example.com'
-PROJECT_DOMAIN_STAGING = 'staging.example.com'
-PROJECT_DOMAIN_DEVELOPMENT = 'development.example.com'
-
-# This will be in local, outside of version control, and should use DEBUG conditionals for switching between development/staging and production settings,
-# see local_settings_template.py (which is not used by the project) for example.
-PROJECT_SETTINGS_PATH = '/home/user/djsettings/django_gunicorn_project_local_settings.py'
-
-PROJECT_GUNICORN_LOGLEVEL = 'info'
-PROJECT_GUNICORN_NUM_WORKERS = 3
-PROJECT_GUNICORN_BIND_IP = '127.0.0.1'
-PROJECT_GUNICORN_BIND_PORT = '8000'
-
-PROJECT_NGINX_IP = '192.168.0.185'
-PROJECT_NGINX_PORT = '80'
-
-PROJECT_NGINX_IP_STAGING = '192.168.0.185'
-PROJECT_NGINX_PORT_STAGING = '81'
-
-PROJECT_NGINX_IP_DEVELOPMENT = '192.168.0.185'
-PROJECT_NGINX_PORT_DEVELOPMENT = '82'
-
-# Some of these values are shared by development when not specified here, update build_projects_var function if needed
-PROJECT_GUNICORN_LOGLEVEL_STAGING = 'debug'
-PROJECT_GUNICORN_NUM_WORKERS_STAGING = 3
-PROJECT_GUNICORN_BIND_IP_STAGING = '127.0.0.1'
-PROJECT_GUNICORN_BIND_PORT_STAGING = '8001'
-
-PROJECT_GUNICORN_BIND_PORT_DEVELOPMENT = '8002'
-
-PROJECT_LOG_GUNICORN = 'gunicorn.log'
-PROJECT_LOG_NGINX_ACCESS = 'nginx-access.log'
-PROJECT_LOG_NGINX_ERROR = 'nginx-error.log'
-
-PROJECT_REPO_TYPE = 'git'
-PROJECT_REPO_URL = 'git@github.com:user/My-Project.git'
-
-EXTRA_APPS = (
- {
- 'name': 'someapp',
- 'production': {'type': 'git',
- 'source': 'git+ssh://user@host/home/user/someapp.git',
- 'dir': '/home/user/djapps/someapp',
- },
- 'staging': {'type': 'git',
- 'source': 'git+ssh://user@host/home/user/someapp.git',
- 'dir': '/home/user/djapps/someapp_staging',
- },
- 'development': {'type': 'git',
- 'source': 'git+ssh://user@host/home/user/someapp.git',
- 'dir': '/home/user/djapps/someapp_development',
- },
- },
- {
- 'name': 'anotherapp',
- 'production': {'type': 'editable',
- 'source': '/home/user/django_gunicorn_project/django-someapp',
- 'dir': '/home/user/django_gunicorn_project/django-someapp',
- },
- 'staging': {'type': 'editable',
- 'source': '/home/user/django_gunicorn_project_staging/django-someapp',
- 'dir': '/home/user/django_gunicorn_project_staging/django-someapp',
- },
- 'development': {'type': 'editable',
- 'source': '/home/user/django_gunicorn_project_development/django-someapp',
- 'dir': '/home/user/django_gunicorn_project_development/django-someapp',
- },
- },
-)
-
-# Web servers should be setup one by one.
-# Public ip and port to be used by Nginx will be passed for each web server in setup_nginx.
-
-UBUNTU_PACKAGES=('man',
- 'manpages',
- 'git-core',
- 'nginx',
- 'python-pip',
- 'postgresql-server-dev-9.1',
- 'postgresql-client-9.1',
- 'sqlite3',
- 'python-dev'
- )
-
-PIP_PACKAGES=('virtualenv',
- 'virtualenvwrapper',
- 'Fabric',
- )
-
-PIP_VENV_PACKAGES=('psycopg2',
- 'ipython',
- 'yolk',
- 'Django==1.4',
- 'gunicorn',
- 'Fabric',
- 'South',
- 'Sphinx'
- 'docutils',
- )
-
-MIRROR_URL = '-i http://d.pypi.python.org/simple'
-
-#### END OF CONFIGURATION ####
-
4b. To start building your project on top of this one change the SECRET_KEY in settings.py to make it unique for your project and proceed to step 5.
5. Copy local_settings_template.py from the root of this project to some directory in the deployer and adapt for your project, feel free to change the name of the file as the full path will be later used in the PROJECT_STAGING_SETTINGS_PATH constant in the fabfile.py configuration section.
@@ -202,7 +76,7 @@ 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.
-6. Change to your project's directory and edit the required constants in settings.py; they are below the comment #### START CONFIGURATION ####. There are some comments to guide you.
+6. Change to your project's directory and add the configuration values at the bottom of your settings.py file. You can start based on fabconfig.py
How to run the fabfile
------------------------
View
125 fabconfig.py
@@ -0,0 +1,125 @@
+#### START OF FABRIC CONFIGURATION ####
+
+# Use local_settings.py to override settings.
+# This file should be outside of control version.
+# Copy local_settings_template.py as a starting point.
+try:
+ from local_settings import *
+except ImportError:
+ pass
+
+# DO NOT USE TRAILING SLASH AND USE UNDERSCORES IN DIRECTORIES TO MIMIC django-admin.py starproject.
+PROJECT_USER = 'user'
+
+PROJECT_NAME = 'django_gunicorn_project' # Used for upstart script and virtualenv
+PROJECT_DESCRIPTIVE_NAME = 'The Django gunicorn project' # Used as description in upstart script
+
+# with the new Django 1.4 project layout there's an inner project directory at PROJECT_DIR/PROJECT_INNER_DIR
+PROJECT_DIR = '/home/user/django_gunicorn_project'
+PROJECT_INNER_DIR = 'django_gunicorn_project'
+PROJECT_LOGDIR = '/home/alexis/logs/django_gunicorn_project'
+PROJECT_SCRIPT_NAME = 'run-' + PROJECT_NAME
+
+PROJECT_DOMAIN = 'example.com'
+PROJECT_DOMAIN_STAGING = 'staging.example.com'
+PROJECT_DOMAIN_DEVELOPMENT = 'development.example.com'
+
+# This will be in local, outside of version control, and should use DEBUG conditionals for switching between development/staging and production settings,
+# see local_settings_template.py (which is not used by the project) for example.
+PROJECT_SETTINGS_PATH = '/home/user/djsettings/django_gunicorn_project_local_settings.py'
+
+PROJECT_GUNICORN_LOGLEVEL = 'info'
+PROJECT_GUNICORN_NUM_WORKERS = 3
+PROJECT_GUNICORN_BIND_IP = '127.0.0.1'
+PROJECT_GUNICORN_BIND_PORT = '8000'
+
+PROJECT_NGINX_IP = '192.168.0.185'
+PROJECT_NGINX_PORT = '80'
+
+PROJECT_NGINX_IP_STAGING = '192.168.0.185'
+PROJECT_NGINX_PORT_STAGING = '81'
+
+PROJECT_NGINX_IP_DEVELOPMENT = '192.168.0.185'
+PROJECT_NGINX_PORT_DEVELOPMENT = '82'
+
+# Some of these values are shared by development when not specified here, update build_projects_var function if needed
+PROJECT_GUNICORN_LOGLEVEL_STAGING = 'debug'
+PROJECT_GUNICORN_NUM_WORKERS_STAGING = 3
+PROJECT_GUNICORN_BIND_IP_STAGING = '127.0.0.1'
+PROJECT_GUNICORN_BIND_PORT_STAGING = '8001'
+
+PROJECT_GUNICORN_BIND_PORT_DEVELOPMENT = '8002'
+
+PROJECT_LOG_GUNICORN = 'gunicorn.log'
+PROJECT_LOG_NGINX_ACCESS = 'nginx-access.log'
+PROJECT_LOG_NGINX_ERROR = 'nginx-error.log'
+
+PROJECT_REPO_TYPE = 'git'
+PROJECT_REPO_URL = 'git@github.com:user/My-Project.git'
+
+EXTRA_APPS = (
+ {
+ 'name': 'someapp',
+ 'production': {'type': 'git',
+ 'source': 'git+ssh://user@host/home/user/someapp.git',
+ 'dir': '/home/user/djapps/someapp',
+ },
+ 'staging': {'type': 'git',
+ 'source': 'git+ssh://user@host/home/user/someapp.git',
+ 'dir': '/home/user/djapps/someapp_staging',
+ },
+ 'development': {'type': 'git',
+ 'source': 'git+ssh://user@host/home/user/someapp.git',
+ 'dir': '/home/user/djapps/someapp_development',
+ },
+ },
+ {
+ 'name': 'anotherapp',
+ 'production': {'type': 'editable',
+ 'source': '/home/user/django_gunicorn_project/django-someapp',
+ 'dir': '/home/user/django_gunicorn_project/django-someapp',
+ },
+ 'staging': {'type': 'editable',
+ 'source': '/home/user/django_gunicorn_project_staging/django-someapp',
+ 'dir': '/home/user/django_gunicorn_project_staging/django-someapp',
+ },
+ 'development': {'type': 'editable',
+ 'source': '/home/user/django_gunicorn_project_development/django-someapp',
+ 'dir': '/home/user/django_gunicorn_project_development/django-someapp',
+ },
+ },
+)
+
+# Web servers should be setup one by one.
+# Public ip and port to be used by Nginx will be passed for each web server in setup_nginx.
+
+UBUNTU_PACKAGES=('man',
+ 'manpages',
+ 'git-core',
+ 'nginx',
+ 'python-pip',
+ 'postgresql-server-dev-9.1',
+ 'postgresql-client-9.1',
+ 'sqlite3',
+ 'python-dev'
+ )
+
+PIP_PACKAGES=('virtualenv',
+ 'virtualenvwrapper',
+ 'Fabric',
+ )
+
+PIP_VENV_PACKAGES=('psycopg2',
+ 'ipython',
+ 'yolk',
+ 'Django==1.4',
+ 'gunicorn',
+ 'Fabric',
+ 'South',
+ 'Sphinx',
+ 'docutils',
+ )
+
+MIRROR_URL = '-i http://d.pypi.python.org/simple'
+
+#### END OF CONFIGURATION ####
View
36 fabfile.py
@@ -1,8 +1,42 @@
"""
This Fabric script allows you setup an Ubuntu 11.10 server to run a Django project with Nginx and gunicorn.
-For detailed instructions see README in the project's root.
+How to use
+===============
+1. This step is optional. If you still haven't created a user to run the project you can start with an existing user to create one.
+$ fab -H existing_user@host add_user:user
+That will create user with a random password and sudo permissions.
+
+2. Fill configuration details in settings.py.
+
+3. Run setup to install the server applications, create virtualenvs, install basic Python packages and configuration files for one or more environments.
+Start creating a development environment on the development box.
+Then create a staging environment, ideally on one of the production boxes, as it will be used to get code from repositories and then rsync to production.
+$ fab -H user@host setup:production,staging,development,mirror=y
+
+4. Install or update project and apps for one environment.
+$ fab -H user@host update_site:env=production,update_settings=y,upgrade_apps=y
+
+5. To start, stop or restart the site on one environment.
+$ fab -H user@host start_site:env=production
+$ fab -H user@host stop_site:env=production
+$ fab -H user@host restart_site:env=production
+
+6. Work on the development environment and use this to commit from time to time.
+
+$ fab -H user@host commit:env=development,message='commit message and escaping comma\, this way',push=n,test=y
+
+Parameters:
+env: 'production', 'staging', 'development'.
+mirror: 'y', 'n'. Default: 'n'.
+
+Development can be accessed at http://PROJECT_DOMAIN_DEVELOPMENT:development_port
+Staging can be accessed at http://PROJECT_DOMAIN_STAGING:staging_port
+Production can be accessed at http://PROJECT_DOMAIN:port
+
+For more detailed instructions see README in The-Django-gunicorn-fabfile-project.
+https://github.com/alexisbellido/The-Django-gunicorn-fabfile-project
"""
from fabric.api import run, sudo, hosts, settings, abort, warn, cd, local, put, get, env
Please sign in to comment.
Something went wrong with that request. Please try again.