def deploy(self, patch=False): if not exists(self.deploy_root): run("mkdir -p %s" % self.deploy_root) with cd(self.deploy_root): u_domain = self.domain.replace('.','_') filename = "%s.wsgi"% u_domain context = {"user": env.user, "project_name": env.project_name, "u_domain":u_domain, "root_domain":env.root_domain, } wsgi_exists = exists(filename) if wsgi_exists and not patch: print env.host,"%s already exists on the host %s. Skipping..."% (self.deploy_type,filename) return False elif not wsgi_exists and patch: print env.host,"Error: Cannot patch %s %s. This version does not exist"% (project_fullname(), self.deploy_type) return False current_version = active_version() if current_version == env.project_fullname and not patch: print env.host,"Warning: Cannot deploy %s, version %s already active. Increase the version and re-deploy. Skipping.."% (self.deploy_type,env.project_fullname) return False else: #not exists upload_template('woven/'+self.template, filename, context, ) #finally set the ownership/permissions #We'll use the group to allow www-data execute if self.deploy_type == 'wsgi': sudo("chown %s:www-data %s"% (env.user,filename)) run("chmod ug+xr %s"% filename) set_server_state(self.state+env.project_fullname)
def deploy(self,patch=False): """ Deploy your project """ if not self.local_path: if env.verbosity: print "Warning: No %s set in project settings. Skipping %s..."% (self.setting,self.deploy_type) return False if self.installed and not patch and self.versioned: if env.verbosity: print env.host,"Warning: %s version %s already deployed. Skipping..."% (self.deploy_type,self.fullname) return False elif not self.installed and not patch: run('mkdir -p '+self.deploy_root) #Webserver must be able to write into the public directory in the case of fileuploads #TODO - Make this optional?? if self.deploy_type == 'public': sudo("chown -R www-data:sudo %s" % self.deploy_root[:-1]) #strip trailing / sudo("chmod -R ug+w %s"% self.deploy_root[:-1]) elif not self.installed and patch and self.versioned: if env.verbosity: print env.host,"Warning: Cannot patch %s. This version %s does not exist. Skipping.."% (self.deploy_type,self.fullname) return False l = local('ls '+self.local_path).rstrip() if not l: if env.verbosity: print "Warning: Theres are no files to deploy for %s. Skipping.."% self.deploy_type return False #bug in fabric 0.9 on rsync on alternate port fixed in 1.0 fab_vers = int(get_version(form='short')[0]) if fab_vers < 1: extra_opts = '--rsh="ssh -p%s"'% env.port #to save a bit of network usage if there is an existing version we will copy that first if self.versioned: av = active_version() if av and not patch: delete=True av_root = self.deploy_root.replace(self.fullname,av) dest_root = self.deploy_root.replace(self.deploy_type+'/','') run('cp -R %s %s'% (av_root,dest_root)) elif patch: delete=False else: delete=True else: delete = False if self.dest_path_postfix: self.last_postfix = self.dest_path_postfix.split('/')[-2] #since -1 will be trailing slash and thus empty postfix = self.dest_path_postfix.replace(self.last_postfix+'/','') remote_dir = self.deploy_root[:-1]+postfix run('mkdir -p '+remote_dir) else: self.last_postfix = self.deploy_type remote_dir = env.deployment_root+'/'.join(['env',self.fullname]) staging_dir = self.stage_local_files() rsync_project(local_dir=os.path.join(staging_dir,self.last_postfix),remote_dir=remote_dir, extra_opts=extra_opts,exclude=self.rsync_exclude,delete=delete) #delete orphaned .pyc - specific to projects & remove 'woven' from installed apps if self.deploy_type == 'project': run("find %s -name '*.pyc' -delete"% self.deploy_root) set_server_state(self.state+self.fullname) if env.verbosity: if patch: print env.host,"PATCHED %s "% (self.deploy_type) else: print env.host,"DEPLOYED %s "% (self.deploy_type)