1. Mikhail Korobov
  2. django-fab-deploy

Commits

Mikhail Korobov  committed 172852f

Test project with custom layout

  • Participants
  • Parent commits 4dfe8e1
  • Branches default

Comments (0)

Files changed (17)

File fab_deploy_tests/test_project2/.gitignore

View file
+*.pyc
+src/local_settings.py

File fab_deploy_tests/test_project2/README

View file
+Custom project layout example.

File fab_deploy_tests/test_project2/__init__.py

View file
+# This file is necessary only for testing purposes: we want to make
+# test_project2 python package in order to import from its fabfile

File fab_deploy_tests/test_project2/fabfile.py

View file
+from fab_deploy import *
+
+LAYOUT_OPTIONS = dict(
+    PROJECT_PATH = 'src',
+    LOCAL_CONFIG = 'local_settings.py',
+    REMOTE_CONFIG_TEMPLATE = 'staging_settings.py',
+    PIP_REQUIREMENTS = 'requirements.txt',
+    PIP_REQUIREMENTS_PATH = '',
+    CONFIG_TEMPLATES_PATHS = ['hosting/staging', 'hosting'],
+)
+
+def foo_site():
+    env.hosts = ['foo@127.0.0.1:2222']
+    env.conf = dict(
+        DB_PASSWORD = '123',
+        VCS = 'git',
+        SERVER_NAME = 'foo.example.com',
+    )
+    env.conf.update(LAYOUT_OPTIONS)
+    update_env()

File fab_deploy_tests/test_project2/hosting/apache.config

View file
+NameVirtualHost 127.0.0.1:{{ APACHE_PORT }}
+<VirtualHost 127.0.0.1:{{ APACHE_PORT }}>
+    ServerName {{ SERVER_NAME }}
+    ServerAlias www.{{ SERVER_NAME }}
+    ServerAdmin {{ SERVER_ADMIN }}
+
+    WSGIDaemonProcess {{ INSTANCE_NAME }} user={{ USER }} group={{ USER }} processes={{ PROCESSES }} threads={{ THREADS }}
+    WSGIProcessGroup {{ INSTANCE_NAME }}
+
+    WSGIScriptAlias / {{ ENV_DIR }}/var/wsgi/{{ INSTANCE_NAME }}.py
+    <Directory {{ ENV_DIR }}/var/wsgi/>
+        Order deny,allow
+        allow from all
+    </Directory>
+
+    ErrorLog /var/log/apache2/{{ INSTANCE_NAME }}-error.log
+    ErrorDocument 500 {{ PROJECT_DIR }}/templates/500.html
+
+    # Possible values include: debug, info, notice, warn, error, crit, alert, emerg
+    LogLevel error
+</VirtualHost>

File fab_deploy_tests/test_project2/hosting/django_wsgi.py

View file
+# this file is broken for testing purposes
+# look at hosting/staging/django_wsgi.py for correct example
+sdfsdf

File fab_deploy_tests/test_project2/hosting/nginx.config

View file
+server {
+    listen 80;
+    server_name {{ SERVER_NAME }} www.{{ SERVER_NAME }};
+    access_log /var/log/nginx/{{ SERVER_NAME }}.access.log;
+    charset utf-8;
+    client_max_body_size 8m;
+
+    gzip_types text/plain text/xml text/css application/javascript application/x-javascript application/json;
+
+    location / {
+        proxy_pass http://localhost:{{ APACHE_PORT }};
+        proxy_set_header Host $host;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+    }
+
+    # change /static to your static folder name
+    location /static {
+        root {{ PROJECT_DIR }};
+        autoindex off;
+        expires 1M;
+    }
+
+    # admin media serving
+    # (this location is available if django is installed from svn)
+    location /media {
+        root {{ ENV_DIR }}/src/django/django/contrib/admin;
+        expires 10m;
+        autoindex off;
+    }
+
+    # alternative django admin media path
+#    location /static/admin {
+#        root {{ PROJECT_DIR }};
+#        autoindex off;
+#        expires 10m;
+#    }
+
+    #error_page  404  /404.html;
+
+    # redirect server error pages to the static page /50x.html
+    error_page   500 502 503 504  /50x.html;
+    location = /50x.html {
+        root   /var/www/nginx-default;
+    }
+}

File fab_deploy_tests/test_project2/hosting/staging/django_wsgi.py

View file
+import os
+import sys
+import site
+
+# prevent errors with 'print' commands
+sys.stdout = sys.stderr
+
+# adopted from http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
+def add_to_path(dirs):
+    # Remember original sys.path.
+    prev_sys_path = list(sys.path)
+
+    # Add each new site-packages directory.
+    for directory in dirs:
+        site.addsitedir(directory)
+
+    # Reorder sys.path so new directories at the front.
+    new_sys_path = []
+    for item in list(sys.path):
+        if item not in prev_sys_path:
+            new_sys_path.append(item)
+            sys.path.remove(item)
+    sys.path[:0] = new_sys_path
+
+add_to_path([
+     os.path.normpath('{{ ENV_DIR }}/lib/python2.5/site-packages'),
+     os.path.normpath('{{ ENV_DIR }}/lib/python2.6/site-packages'),
+     os.path.normpath('{{ PROJECT_DIR }}' + '/..'),
+     '{{ PROJECT_DIR }}',
+])
+
+os.environ['DJANGO_SETTINGS_MODULE'] = '{{ INSTANCE_NAME }}.settings'
+
+#print sys.path
+
+import django.core.handlers.wsgi
+application = django.core.handlers.wsgi.WSGIHandler()

File fab_deploy_tests/test_project2/requirements.txt

View file
+django==1.2.5

File fab_deploy_tests/test_project2/src/__init__.py

Empty file added.

File fab_deploy_tests/test_project2/src/local_settings.py

View file
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': 'testdb.sqlite',
+    }
+}
+INSTANCE_NAME = 'local'

File fab_deploy_tests/test_project2/src/manage.py

View file
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

File fab_deploy_tests/test_project2/src/settings.py

View file
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+from local_settings import *
+
+TIME_ZONE = 'America/Chicago'
+LANGUAGE_CODE = 'en-us'
+SITE_ID = 1
+USE_I18N = True
+USE_L10N = True
+MEDIA_ROOT = ''
+MEDIA_URL = ''
+ADMIN_MEDIA_PREFIX = '/media/'
+SECRET_KEY = 'kdpm23v31@#u63@8!eq6%%^t8z=^ak2g6uyjbc!_6bs(!48(+^'
+
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'django.contrib.messages',
+    'django.contrib.admin',
+)

File fab_deploy_tests/test_project2/src/staging_settings.py

View file
+# my_project/config.server.py
+# config file for environment-specific settings
+
+DEBUG = True
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': '{{ DB_NAME }}.sqlite',
+    }
+}
+INSTANCE_NAME = '{{ INSTANCE_NAME }}'

File fab_deploy_tests/test_project2/src/templates/404.html

View file
+404

File fab_deploy_tests/test_project2/src/templates/500.html

View file
+500

File fab_deploy_tests/test_project2/src/urls.py

View file
+from django.conf.urls.defaults import *
+from django.http import HttpResponse
+from django.conf import settings
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^admin/', include(admin.site.urls)),
+    (r'^instance/', lambda r: HttpResponse(settings.INSTANCE_NAME)),
+)