Beispiel #1
0
def deploy_db(rollback=False):
    """
    Deploy a sqlite database from development
    """
    env.deployment_root = '/home/%s/%s/'% (env.user,root_domain())
    db_name = env.deployment_root + '/'.join(['database',project_name()+'.db'])
    
    if not rollback:
        db_dir = env.deployment_root+'database'
        if env.DEFAULT_DATABASE_ENGINE=='django.db.backends.sqlite3' and not exists(db_name):

            if env.verbosity:
                print env.host,"DEPLOYING DEFAULT SQLITE DATABASE to",db_name
            if not os.path.exists(env.DEFAULT_DATABASE_NAME) or not env.DEFAULT_DATABASE_NAME:
                print "ERROR: the database does not exist. Run python manage.py syncdb to create your database first."
                sys.exit(1)
            run('mkdir -p '+db_dir)
            put(env.DEFAULT_DATABASE_NAME,db_name)
            sudo("chown -R %s:www-data %s"% (env.user,db_dir))
            sudo("chmod -R ug+w "+db_dir)
    elif rollback and env.DEFAULT_DATABASE_ENGINE=='django.db.backends.sqlite3':
        if env.INTERACTIVE:
            delete = confirm('DELETE the database on the host?',default=False)
            if delete:
                run('rm -f '+db_name)
    
    return
Beispiel #2
0
def deploy_wsgi(version='',patch=False):
    """
    wrapper around WSGI
    """
    if not env.DOMAINS: env.DOMAINS = [root_domain()]
    for domain in env.DOMAINS:
        w = WSGI(domain,version)
        w.deploy(patch)
Beispiel #3
0
 def __init__(self,version=''):
     super(Project,self).__init__(version)
     self.deploy_type = self.__class__.__name__.lower()
     self.deploy_root = env.deployment_root+'/'.join(['env',self.fullname,self.deploy_type,''])
     
     #try to exclude a few common things in the project directory
     self.rsync_exclude = ['*.pyc','*.log','.*','/build','/dist','/media','/app*','/www','/public','/templates']
     
     self.versioned = True
     self.local_path = './'
     self.local_settings_dir = os.path.join('./',project_name(),'sitesettings')
     
     #the name of a settings.py setting
     self.setting =''
     self.dest_path_postfix = ''
     if not env.DOMAINS: env.DOMAINS = [root_domain()]
Beispiel #4
0
def deploy_webservers(version='',patch=False):
    """ Deploy  apache & nginx site configurations to the host """
    if not env.DOMAINS: env.DOMAINS = [root_domain()]
    #TODO - incorrect - check for actual package
    if exists('/etc/apache2/sites-enabled/') and exists('/etc/nginx/sites-enabled'):

        for d in env.DOMAINS:
            a = ApacheWebserver(d,version)
            a.deploy(patch)
            
            n = NginxWebserver(d,version)
            n.deploy(patch)
        set_server_state('deployed_webservers_' + project_fullname())
        return True

    else:
        print env.host,"""WARNING: Apache or Nginx not installed"""
        return False
    return False
Beispiel #5
0
    def stage_local_files(self):
        #a dest_path_postfix is a /url/postfix/ from a django media setting
        #we need to create the full postfix directory on top of the deploy_root (eg STATIC_ROOT+ADMIN_MEDIA_PREFIX)
        #so locally we create a tmp staging directory to rsync from
        staging_dir = '%s_staging_dir'% self.deploy_type
        #ensure this is run only once per deploy_type
        if hasattr(env,staging_dir):
            return env[staging_dir]

        env[staging_dir] = s = tempfile.mkdtemp()

        #for cleanup later
        env.woventempdirs = env.woventempdirs + [s]
        shutil.copytree(self.local_path,os.path.join(s,self.last_postfix))
        #render settings files and replace
        if self.deploy_type == 'project':
            context = {
                'user':env.user,
                'project_name':project_name(),
                'project_fullname':project_fullname(),
                'root_domain':root_domain(),
                
            }
            for d in env.DOMAINS:
                context['domain']=d
                template_file = d.replace('.','_') + '.py'
                template_path = os.path.join(s,'project',project_name(),'sitesettings',template_file)
                f = open(template_path,"r")
                t = f.read()
                f.close()
                t = Template(t)
                rendered = t.render(Context(context))
                f = open(template_path,"w+")
                f.write(rendered)
                f.close()
        return s
Beispiel #6
0
def test_root_domain():
    #In the event of noinput, the domain will default to example.com
    domain = root_domain()
    assert domain == 'example.com'