Commits

Mikhail Korobov committed 54c919f

Script for generating sample config_templaes and reqs folders. Fix #2. Fix #3. Bump version.

  • Participants
  • Parent commits 9c63c09

Comments (0)

Files changed (18)

 include *.txt
 include *.rst
-recursive-include config_templates *
+recursive-include fab_deploy/config_templates *.conf
+include fab_deploy/config_templates/hgrc
+include fab_deploy/config_templates/django_wsgi.py
+recursive-include fab_deploy/example_reqs *.txt
 recursive-include docs *
 recursive-exclude docs/_build *
 exclude docs/_static

File bin/django-fab-deploy

+#!/usr/bin/env python
+import os
+import sys
+import shutil
+from fab_deploy.utils import _data_path
+
+if __name__ == "__main__":
+
+    if 'example_reqs' in sys.argv:
+        shutil.copytree(_data_path('example_reqs'), 'reqs')
+
+    if 'generate_reqs' in sys.argv:
+        os.mkdir('reqs')
+        os.system('pip freeze > reqs/all.txt')
+
+    if 'config_templates' in sys.argv:
+        shutil.copytree(_data_path('config_templates'), 'config_templates')
+
+    if len(sys.argv) == 1:
+        print """
+Usage: django-fab-deploy command
+
+Commands:
+
+    config_templates
+        create a folder with basic config templates
+
+    example_reqs
+        create a folder with example pip requirements
+
+    generate_reqs
+        create a folder with requirements obtained from `pip freeze` command
+"""

File config_templates/apache.config

-Listen localhost:{{ APACHE_PORT }}
-<VirtualHost *:{{ 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 {{ SRC_DIR }}/templates/500.html
-
-    # Possible values include: debug, info, notice, warn, error, crit, alert, emerg
-    LogLevel error
-</VirtualHost>

File config_templates/django_wsgi.py

-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('{{ SRC_DIR }}' + '/..'),
-     '{{ SRC_DIR }}'
-])
-
-os.environ['DJANGO_SETTINGS_MODULE'] = '{{ INSTANCE_NAME }}.settings'
-
-#print sys.path
-
-import django.core.handlers.wsgi
-application = django.core.handlers.wsgi.WSGIHandler()

File config_templates/hgrc

-# [paths]
-# bitbucket = ssh://hg@bitbucket.org/me/myrepo/
-
-# [hooks]
-# changegroup.push = screen -d -m hg push bitbucket

File config_templates/nginx.config

-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/html text/plain text/xml text/css application/javascript application/x-javascript;
-
-    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 {{ SRC_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_media {
-#        root {{ SRC_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 docs/guide.rst

        There are some defaults, e.g. ``DB_NAME`` equals to ``INSTANCE_NAME``,
        and ``INSTANCE_NAME`` equals to ``env.user``.
 
-3. Copy ``config_templates`` folder from django-fab-deploy to your project root.
+3. Copy ``config_templates`` folder from django-fab-deploy to your project root,
+   manually or by running the following command from the project root::
+
+       django-fab-deploy config_templates
+
+   Read the configs and adjust them if it is needed. Basic configs
+   are usually a good starting point and should work as-is.
 
    .. note::
 
-       Read the configs and adjust them if it is needed. Basic configs
-       are usually a good starting point and should work as-is.
-
        {{ variables }} can be used in config templates. They will be
        replaced with values from ``env.conf`` on server.
-       This also apply for :file:`config.server.py` file.
+
+       If you change web server config file or ``env.conf`` variables
+       after initial deployment, apply the changes in web server configs
+       by running ::
+
+           fab setup_web_server
+
 
 4. Create :file:`config.server.py` at project root. This file will become
    :file:`config.py` on server. Example::
         }
         MEDIA_URL = 'http://{{ SERVER_NAME }}/static/'
 
-   .. note::
-
-       If you change :file:`config.server.py` after initial deployment,
-       apply the changes by running ::
-
-           fab update_django_config
-
    Then create :file:`config.py` for development.
    Import config in project's :file:`settings.py`::
 
    ``config.py`` trick is also known as ``local_settings.py``
    (make sure ``config.py`` is ignored in your ``.hgignore``).
 
+   .. note::
+
+       {{ variables }} can be used in :file:`config.server.py`. They will be
+       replaced with values from ``env.conf`` on server.
+
+       If you change :file:`config.server.py` or ``env.conf`` variables
+       after initial deployment, apply the changes to :file:`config.server.py`
+       by running ::
+
+           fab update_django_config
+
+
 
 5. Create ``reqs`` folder at project root. This folder should contain
    text files with `pip requirements <http://pip.openplans.org/requirement-format.html>`_.
    file. List all project requirements here one-by-one or (preferrable) by
    including other requirement files using "-r" syntax.
 
+   You can get basic/example ``reqs`` folder by running ::
+
+       django-fab-deploy example_reqs
+
 
 The project should look like that after finishing steps 1-5::
 

File fab_deploy/config_templates/apache.config

+Listen localhost:{{ APACHE_PORT }}
+<VirtualHost *:{{ 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 {{ SRC_DIR }}/templates/500.html
+
+    # Possible values include: debug, info, notice, warn, error, crit, alert, emerg
+    LogLevel error
+</VirtualHost>

File fab_deploy/config_templates/django_wsgi.py

+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('{{ SRC_DIR }}' + '/..'),
+     '{{ SRC_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/config_templates/hgrc

+# [paths]
+# bitbucket = ssh://hg@bitbucket.org/me/myrepo/
+
+# [hooks]
+# changegroup.push = screen -d -m hg push bitbucket

File fab_deploy/config_templates/nginx.config

+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/html text/plain text/xml text/css application/javascript application/x-javascript;
+
+    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 {{ SRC_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_media {
+#        root {{ SRC_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/deploy.py

     make_clone()
     make_hgrc()
 
-    pip_install('all', restart=False)
+    pip_update('all', restart=False)
 
     setup_web_server()
     update_django_config()

File fab_deploy/example_reqs/all.txt

+# this is just an example how requirements can be handled
+-r basic.txt
+-r django.txt
+-r apps.txt

File fab_deploy/example_reqs/apps.txt

+# django apps and related python packages, e.g. django-registration

File fab_deploy/example_reqs/basic.txt

+# packages that are widely used and rarely updated
+PIL
+mysql-python >= 1.2
+python-memcached >= 1.43
+simplejson

File fab_deploy/example_reqs/django.txt

+# django 1.2 svn
+-e svn+http://code.djangoproject.com/svn/django/branches/releases/1.2.X#egg=Django

File fab_deploy/utils.py

+import os
 from functools import wraps
 from fabric.context_managers import prefix, cd
 from fabric.contrib.files import upload_template
     """ Deletes *.pyc files from project source dir """
     run("find . -name '*.pyc' -delete")
 
+def _data_path(fname):
+    """Return the path to a data file of ours."""
+    return os.path.join(os.path.split(__file__)[0], fname)
     if cmd in sys.argv:
         from setuptools import setup
 
-version='0.1.1'
+version='0.1.2'
 
 setup(
     name='django-fab-deploy',
     author_email='kmike84@gmail.com',
 
     packages=['fab_deploy'],
+    package_data={
+        'fab_deploy': [
+            'config_templates/*.config',
+            'config_templates/*.py',
+            'config_templates/hgrc',
+            'example_reqs/*.txt',
+        ]
+    },
+
+    scripts = ['bin/django-fab-deploy'],
 
     url='https://bitbucket.org/kmike/django-fab-deploy/',
     download_url = 'https://bitbucket.org/kmike/django-fab-deploy/get/tip.zip',