def deploy(package, opts=''): """ Uploads the given package to remote host and deploys it there. :param str package: Path to tar.gz package in local file system. In case of wildcard, all the matched package are deployed. Package can be in formats: tar.gz (custom package structure, deb, rpm :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) Examples:: fab dist.deploy:package=../../package.tar.gz fab dist.deploy:package=../../package.tar.gz,opts="--theme --activate" fab dist.deploy:package=../../*.deb fab dist.deploy:package=../../*.deb,opts='--force' """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Iterate matched packages # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) releasename, releaseversion, releaseextension = split_package_name( packagename) # Upload package to home directory, with same as the orig logger.info('Uploading the package: %s -> %s' % (package, packagename)) put(package, packagename) logger.info('Release name: %s' % releasename) # Run the package specific deployment actions if releaseextension == 'tar.gz': deploy_targz(packagename, opts) elif releaseextension == 'egg': opts = opts or '-Z' sudo('easy_install %s %s' % (opts, packagename)) elif releaseextension == 'deb': opts = opts or '--install' sudo('dpkg %s %s' % (opts, packagename)) elif releaseextension == 'rpm': opts = opts or '-Uvh' sudo('rpm %s %s' % (opts, packagename)) # Remove the package with cd('~'): sudo('rm -f ./%s' % packagename) # Restart apache logger.info('Restarting apache') apache = Apache() apache.restart()
def deploy(package, opts=''): """ Uploads the given package to remote host and deploys it there. :param str package: Path to tar.gz package in local file system. In case of wildcard, all the matched package are deployed. Package can be in formats: tar.gz (custom package structure, deb, rpm :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) Examples:: fab dist.deploy:package=../../package.tar.gz fab dist.deploy:package=../../package.tar.gz,opts="--theme --activate" fab dist.deploy:package=../../*.deb fab dist.deploy:package=../../*.deb,opts='--force' """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Iterate matched packages # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) releasename, releaseversion, releaseextension = split_package_name(packagename) # Upload package to home directory, with same as the orig logger.info('Uploading the package: %s -> %s' % (package, packagename)) put(package, packagename) logger.info('Release name: %s' % releasename) # Run the package specific deployment actions if releaseextension == 'tar.gz': deploy_targz(packagename, opts) elif releaseextension == 'egg': opts = opts or '-Z' sudo('easy_install %s %s' % (opts, packagename)) elif releaseextension == 'deb': opts = opts or '--install' sudo('dpkg %s %s' % (opts, packagename)) elif releaseextension == 'rpm': opts = opts or '-Uvh' sudo('rpm %s %s' % (opts, packagename)) # Remove the package with cd('~'): sudo('rm -f ./%s' % packagename) # Restart apache logger.info('Restarting apache') apache = Apache() apache.restart()
def deploy_targz(packagename, opts): """ Run the deploy activities for source/custom tar.gz package. The script can deploy following kind of tar.gz packages: - Python source package: if setup.py is found from root folder, it is run with python setup.py install - Custom source package (created with build task): runs scripts/deploy.sh found from the package :param str packagename: Name of the package to deploy. Example 'mypackage-1.1.0.tar.gz' :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) """ root_dir = config['trac_root'] webserver_user = config['webserver_user'] webserver_group = config['webserver_group'] releasename, releaseversion, releaseextension = split_package_name( packagename) # Get the subdirectory (where all the files are place) of the archive, if any out = run('tar ztf %s' % packagename) subdir = os.path.commonprefix(out.stdout.splitlines()) run('tar zxf %s' % packagename) with cd('~/%s' % subdir): # Run the setup.py if is found if exists('setup.py'): logger.info( 'Installing python module from source, using: %s/setup.py' % releasename) sudo('python setup.py install %s' % opts) # Custom package, expect to find scripts/deploy.sh else: logger.info( 'Running deploy script ./scripts/deploy.sh at directory: %s' % subdir) with settings(show('stdout')): sudo('./scripts/deploy.sh %s' % opts) # Fix file permissions logger.info('Setting the permissions to deployment folder') sudo('chown -L -R %s:%s %s' % (webserver_user, webserver_group, join(root_dir, 'dist', 'current'))) # Cleanup - needs to be done with sudo because of sudo is being used at running deploy.sh (at the moment) with cd('~'): logger.info('Cleaning up...') if subdir: sudo('rm -rf ./%s' % subdir) sudo('rm -rf ./%s' % releasename)
def deploy_targz(packagename, opts): """ Run the deploy activities for source/custom tar.gz package. The script can deploy following kind of tar.gz packages: - Python source package: if setup.py is found from root folder, it is run with python setup.py install - Custom source package (created with build task): runs scripts/deploy.sh found from the package :param str packagename: Name of the package to deploy. Example 'mypackage-1.1.0.tar.gz' :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) """ root_dir = config['trac_root'] webserver_user = config['webserver_user'] webserver_group = config['webserver_group'] releasename, releaseversion, releaseextension = split_package_name(packagename) # Get the subdirectory (where all the files are place) of the archive, if any out = run('tar ztf %s' % packagename) subdir = os.path.commonprefix(out.stdout.splitlines()) run('tar zxf %s' % packagename) with cd('~/%s' % subdir): # Run the setup.py if is found if exists('setup.py'): logger.info('Installing python module from source, using: %s/setup.py' % releasename) sudo('python setup.py install %s' % opts) # Custom package, expect to find scripts/deploy.sh else: logger.info('Running deploy script ./scripts/deploy.sh at directory: %s' % subdir) with settings(show('stdout')): sudo('./scripts/deploy.sh %s' % opts) # Fix file permissions logger.info('Setting the permissions to deployment folder') sudo('chown -L -R %s:%s %s' % (webserver_user, webserver_group, join(root_dir, 'dist', 'current'))) # Cleanup - needs to be done with sudo because of sudo is being used at running deploy.sh (at the moment) with cd('~'): logger.info('Cleaning up...') if subdir: sudo('rm -rf ./%s' % subdir) sudo('rm -rf ./%s' % releasename)