Updating example fabfile and fabconfig to show new DeployConfig object
2 files changed, 105 insertions(+), 76 deletions(-)

A => examples/fabconfig.json
M examples/fabfile_pscom.py
A => examples/fabconfig.json +50 -0
@@ 0,0 1,50 @@ 
+{
+    "global": {
+        "project_name": "pscom",
+        "supervisord_procs": ["pscom"]
+    },
+    "fab": {
+        "shell": "/bin/sh -c",
+        "user": "pscom"
+    },
+    "djeploy": {
+        "env_path": "/usr/home/pscom/envs/pscom",
+        "scm_repo_name": "pscom",
+        "scm_repo_rev": "default",
+        "scm_repo_location": "ssh://hg@bitbucket.org/petersanchez/pscom",
+	"venv_type": "python3"
+    },
+    "spaces": {
+        "staging": {
+	    "global": {
+	        "db_name": "pscom",
+		"db_user": "psanchez",
+		"db_pass": "SECRET-PASSWORD",
+		"db_host": "/tmp",
+		"db_port": "9999"
+	    },
+            "fab": {
+                "hosts": ["dev-server.com"]
+            },
+            "djeploy": {
+                "run_type": "staging"
+            }
+        },
+        "prod": {
+	    "global": {
+	        "db_name": "pscom",
+		"db_user": "pscom",
+		"db_pass": "SECRET-PASSWORD",
+		"db_host": "/tmp",
+		"db_port": "9999"
+	    },
+            "fab": {
+                "hosts": ["petersanchez.com"]
+            },
+            "djeploy": {
+                "scm_repo_rev": "stable",
+                "run_type": "prod"
+            }
+        }
+    }
+}

          
M examples/fabfile_pscom.py +55 -76
@@ 1,69 1,60 @@ 
-'''
-    Deployment fabfile for PeterSanchez.com
+"""
+    Deployment fabfile for petersanchez.com
 
-    Usage:
-    
-     # Full deploy to staging environment
+    -    Usage:
 
-       > fab space:staging deploy:full
+    # Full deploy to staging environment
+
+      > fab space:staging deploy:full
 
-     # Full deploy to production environment
-       
-       > fab space:prod deploy:full
+    # Full deploy to production environment
+
+      > fab space:prod deploy:full
 
-     # Update codebase on production environment
+    # Update codebase on production environment
 
-       > fab space:prod deploy:update
-'''
+      > fab space:prod deploy:update
+
+"""
 import os
 from fabric.api import env, require
-from djeploy import set_env, get_env, command
-from djeploy.django import django_syncdb, django_migrate, django_collectstatic
 from djeploy.ops import space, deploy
+from djeploy.postgresql import postgresql_backup_db
+from djeploy.system import service_command, restart_service
 from djeploy.scm import checkout_code_repo, update_code_repo
-from djeploy.system import service_command, restart_service
+from djeploy import djeploy_require, set_env, get_env, command, DeployConfig
+from djeploy.django import (
+    run_manage_command, django_migrate, django_collectstatic,
+)
 from djeploy.deploy import *
 
 
-# deploy globals
-project_name = 'pscom'
+config = DeployConfig()
 
-# fabric globals
-env.shell = '/bin/sh -c'
-env.user = 'pjs'
+# deploy globals
+project_name = config.project_name
+s_procs = []
 
-# djeploy options
-djeploy_configs = {
-    'env_path': '/home/pjs/envs/%s' % project_name,
-    'scm_repo_name': project_name,
-    'scm_repo_location': \
-        'http://www.my-repo-location.com/hg/%s' % project_name,
-}
-set_env(**djeploy_configs)
+# Get supervisord processes
+if hasattr(config, 'supervisord_procs'):
+    s_procs = config.supervisord_procs
+    if not isinstance(s_procs, (list, tuple)):
+        s_procs = [s_procs]
 
 
 def _localdev():
     'Use the local machine'
-    env.hosts = ['localhost']
-    opts = {
-        'env_path': '/Users/pjs/envs/%s' % project_name,
-        'repo_path': os.getcwd(),
-        'run_type': 'local',
-        'copy_base_settings_local': True,
-    }
-    set_env(**opts)
+    config.load_space('local')
 
 
 def _staging():
     'Use the staging environment'
-    env.hosts = ['my-staging-server.com']
-    set_env(run_type='staging')
+    config.load_space('staging')
 
 
 def _prod():
     'Use the production environment'
-    env.hosts = ['my-production-server.com']
-    set_env(run_type='prod')
+    config.load_space('prod')
 
 
 space_opts = {

          
@@ 90,32 81,42 @@ def _setup():
     make_release_directory()
     checkout_code_repo()
     make_virtual_environment(extra_path=project_name)
-    install_requirements(cache='~/.pipcache', timeout=1)
+    install_requirements(
+        req_path='./deploy/prod_requirements.txt',
+        timeout=1,
+    )
 
     # Backup db before any migrations, etc.
     if not command.is_local:
-        # Hide the actual running print out because it 
+        # Hide the actual running print out because it
         # sets the password in shell via env variable PGPASSWORD
-        command.set_local_settings(hide=['running',], clear_after_run=True)
+        command.set_local_settings(hide=['running', ],
+                                   clear_after_run=True)
 
         release_path = get_env('release_path')['release_path']
         postgresql_backup_db(
-            project_name,
+            config.db_name,
             backup_dir=release_path,
-            connect_as='psanchez',
-            password='my_s3cr3t_p4s5w0rd',
-            host='/tmp',
-            port=9999,
+            connect_as=config.db_user,
+            password=config.db_pass,
+            dbhost=config.db_host,
+            port=config.db_port,
         )
 
     django_collectstatic()
-    django_syncdb()
+    run_manage_command('syncfiles')
     django_migrate()
 
-    _install_site()
+    if s_procs:
+        command.sudo('supervisorctl stop {0}'.format(' '.join(s_procs)))
+
     symlink_current_release()
-    restart_service('apache22') # performs sanity configtest
+
+    if s_procs:
+        command.sudo('supervisorctl start {0}'.format(' '.join(s_procs)))
+
     remove_old_releases()
+    run_manage_command('syncfiles', '--nosync', '--delete')
 
 
 def _soft_update():

          
@@ 126,7 127,9 @@ def _soft_update():
     command.set_cmds()
 
     checkout_code_repo(update=True)
-    _touch_wsgi_handler()
+    env_path = get_env('env_path')['env_path']
+    with command.cd(os.path.join(env_path, 'current', project_name)):
+        command.run('touch deploy/touch_to_reload.wsgi')
 
 
 deploy_opts = {

          
@@ 137,27 140,3 @@ deploy_opts = {
     },
 }
 set_env(**deploy_opts)
-
-
-def _install_site():
-    'Add the virtualhost file to apache'
-    require('hosts', provided_by=[space])
-    opts = get_env('release_path')
-    release_path = opts['release_path']
-
-    if not command.is_local():
-        with command.cd(release_path):
-            cmd = 'cp %s/apache/%s.conf ' % (project_name, project_name) + \
-                  '/usr/local/etc/apache22/Includes/'
-            command.sudo(cmd)
-
-
-def _touch_wsgi_handler():
-    'Touch the mod_wsgi wsgi_handler.py file'
-    require('hosts', provided_by=[space])
-    opts = get_env('env_path')
-    env_path = opts['env_path']
-    wsgi_path = os.path.join(env_path, 'current', project_name, 'apache')
-
-    with command.cd(wsgi_path):
-        command.run('touch wsgi_handler.py')