Commits

Mikhail Korobov committed 4e865ec

Some renames

  • Participants
  • Parent commits 565d4f6

Comments (0)

Files changed (2)

File fab_deploy/deploy.py

 from fabric.api import env, run, local, settings, cd
 from fabric.contrib.files import upload_template
 
-from fab_deploy.utils import run_as, upload_config_template
+from fab_deploy.utils import upload_config_template
 from fab_deploy.commands import touch, pip_install, pip_update, delete_pyc
 from fab_deploy.django_commands import compress, migrate, syncdb, test
-from fab_deploy.system import install_system_packages, setup_backports, install_vcs
+from fab_deploy.system import prepare_server
 from fab_deploy.apache import apache_setup, apache_install, touch
 from fab_deploy.nginx import nginx_setup, nginx_install
 
 def full_deploy():
-    setup_backports()
-    install_system_packages()
-    install_vcs()
+    prepare_server()
+    deploy_project()
 
-    make_virtualenv()
+def deploy_project():
+    """ Deploys project on prepared server """
+    virtualenv_create()
     make_clone()
     make_hgrc()
 
     pip_install('all')
 
     setup_web_server()
-    update_config()
+    update_django_config()
 
 
-def make_virtualenv():
+def virtualenv_create():
     run('mkdir -p envs')
     run('mkdir -p src')
     with cd('envs'):
         run('virtualenv --no-site-packages %s' % env.conf['INSTANCE_NAME'])
 
+def make_clone():
+    with cd('src'):
+        with settings(warn_only=True):
+            run('mkdir %s' % env.conf['INSTANCE_NAME'])
+            with cd(env.conf['INSTANCE_NAME']):
+                run('hg init')
+    local('hg push ssh://%s@%s/src/%s/' % (env.conf['USER'], env.conf['HOST'], env.conf['INSTANCE_NAME']))
+    with cd('src'):
+        with cd(env.conf['INSTANCE_NAME']):
+            run('hg up -C %s' % env.conf['HG_BRANCH'])
+    update_django_config(restart=False)
+
+def make_hgrc():
+    upload_config_template('hgrc', env.conf['SRC_DIR'] + '/.hg/hgrc')
+
+
+
+def update_django_config(restart=True):
+    upload_template('config.server.py', '%s/config.py' % env.conf['SRC_DIR'], env.conf, True)
+    if not only_upload:
+        touch()
+
+def up(branch=None):
+    delete_pyc()
+    branch = branch or env.conf['HG_BRANCH']
+    with cd('src/'+ env.conf['INSTANCE_NAME']):
+        run('hg up -C %s' % branch)
+    compress()
+    touch()
+
+
+
+def setup_web_server():
+    apache_install()
+    nginx_install()
+    apache_setup()
+    nginx_setup()
 
 def push(*args):
     ''' Run it instead of hg push.
         if 'notest' not in args:
             test()
 
-
-def update_config(only_upload=False):
-    upload_template('config.server.py', '%s/config.py' % env.conf['SRC_DIR'], env.conf, True)
-    if not only_upload:
-        touch()
-
-
-def up(branch=None):
-    delete_pyc()
-    branch = branch or env.conf['HG_BRANCH']
-    with cd('src/'+ env.conf['INSTANCE_NAME']):
-        run('hg up -C %s' % branch)
-    compress()
-    touch()
-
-
-def make_clone():
-    with cd('src'):
-        with settings(warn_only=True):
-            run('mkdir %s' % env.conf['INSTANCE_NAME'])
-            with cd(env.conf['INSTANCE_NAME']):
-                run('hg init')
-    local('hg push ssh://%s@%s/src/%s/' % (env.conf['USER'], env.conf['HOST'], env.conf['INSTANCE_NAME']))
-    with cd('src'):
-        with cd(env.conf['INSTANCE_NAME']):
-            run('hg up -C %s' % env.conf['HG_BRANCH'])
-    update_config(only_upload=True)
-
-
-def make_hgrc():
-    upload_config_template('hgrc', env.conf['SRC_DIR'] + '/.hg/hgrc')
-
-def setup_web_server():
-    apache_install()
-    nginx_install()
-    apache_setup()
-    nginx_setup()

File fab_deploy/system.py

 from fabric.contrib.files import append
 from fab_deploy.utils import run_as
 
+def prepare_server():
+    """ Prepares server: installs system packages """
+    setup_backports()
+    install_common_software()
+
 @run_as('root')
-def install_system_packages():
+def install_common_software():
     to_install = [
-        'python2.5', 'memcached', 'mutt',
-        'libjpeg-dev', 'libmysqlclient15-dev', 'zlib1g-dev',
-        'build-essential', 'python-dev', 'python-setuptools',
-        'python-profiler', 'screen', 'locales-all', 'curl',
+        'python2.5', 'build-essential', 'python-dev', 'python-setuptools',
+        'python-profiler', 'libjpeg-dev', 'libmysqlclient15-dev', 'zlib1g-dev',
         'libssl-dev', 'libcurl3-dev',
+
+        'screen', 'locales-all', 'curl',
+        'memcached',
+        'subversion', 'bzr',
     ]
 
     aptitude_install(" ".join(to_install))
 
+    # git and mercurial are outdated in stable Debian Lenny and don't work with
+    # some source repositories on github and bitbucket
+    aptitude_install('mercurial git-core', 'lenny-backports')
+
     run('easy_install -U pip')
     run('pip install -U virtualenv')
 
         run('aptitude update')
 
 @run_as('root')
-def install_vcs():
-    aptitude_install('mercurial git-core', 'lenny-backports')
-    aptitude_install('subversion bzr')
-
-@run_as('root')
 def create_linux_account(pub_key_file):
     """ Creates linux account and setups ssh access """
     with open(os.path.normpath(pub_key_file), 'rt') as f: