def setup_app(): # Ubuntu 13.10 only if distrib_codename() == 'saucy': sudo('apt-get install php5-json') sudo('ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/') sudo('php5enmod mcrypt') if distrib_codename() == 'quantal': sudo('apt-get install php-apc') else: sudo('apt-get install php5-apcu') with cd(env.projects_dir): sudo('rm -rf {}'.format(env.project)) run('git clone https://github.com/akeneo/pim-community-standard.git {}' .format(env.project)) with cd(env.project): run('git checkout tags/v1.5.0') setup_config() setup_composer() with settings(abort_exception=FabricException): try: run('php composer.phar install') except FabricException: pass run('php app/console cache:clear --env=prod') run('php app/console pim:install --env=prod')
def setup_app(): # Ubuntu 13.10 only if distrib_codename() == 'saucy': sudo('apt-get install php5-json') sudo('ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/') sudo('php5enmod mcrypt') if distrib_codename() == 'quantal': sudo('apt-get install php-apc') else: sudo('apt-get install php5-apcu') with cd(env.projects_dir): sudo('rm -rf {}'.format(env.project)) run('git clone {repo} {project}'.format(**env.app)) with cd(env.project): run('git checkout tags/1.9.3') setup_composer() setup_config() with settings(abort_exception=FabricException): try: run('export COMPOSER_PROCESS_TIMEOUT=3000;php composer.phar install --prefer-dist --no-dev' ) except FabricException: pass run('php app/console cache:clear --env=prod') setup_config() run('php app/console pim:install --env=prod')
def ppa(name, auto_yes=False): """ Require a `PPA`_ package source. Example:: from fabtools import require # Node.js packages by Chris Lea require.deb.ppa('ppa:chris-lea/node.js', auto_yes=True) .. _PPA: https://help.launchpad.net/Packaging/PPA """ assert name.startswith('ppa:') user, repo = name[4:].split('/', 2) distrib = distrib_codename() source = '%(user)s-%(repo)s-%(distrib)s.list' % locals() if not is_file(source): package('python-software-properties') if auto_yes: prompt = '-y ' else: prompt = '' run_as_root('add-apt-repository %s %s' % (prompt, name), pty=False) update_index()
def setup_mongo(): sudo('apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10') sudo( 'echo deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen | sudo tee /etc/apt/sources.list.d/mongodb-10gen.list > /dev/null' ) sudo('apt-get update') sudo('apt-get install mongodb-10gen=2.4.14') sudo('echo "mongodb-10gen hold" | sudo dpkg --set-selections') if distrib_codename() == 'trusty': sudo('apt-get install php5-mongo') else: sudo('apt-get install php-pear build-essential php5-dev') sudo('pecl install mongo') sudo( 'echo "extension=mongo.so" | sudo tee /etc/php5/conf.d/mongo.ini > /dev/null' ) with cd('env.project_dir'): run('php ../composer.phar --prefer-dist require doctrine/mongodb-odm-bundle 3.0.1' ) # In app/AppKernel.php, uncomment the following line (this will enable DoctrineMongoDBBundle and will load and enable the MongoDB configuration): # gedit app/AppKernel.php # new Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle(), get('app/config/pim_parameters.yml') env.db_str = """ pim_catalog_product_storage_driver: doctrine/mongodb-odm mongodb_server: 'mongodb://{host}:{port}' mongodb_database: {name} """.format(**env.mongo)
def ppa(name, auto_accept=True, keyserver=None): """ Require a `PPA`_ package source. Example:: from fabtools import require # Node.js packages by Chris Lea require.deb.ppa('ppa:chris-lea/node.js', keyserver='my.keyserver.com') .. _PPA: https://help.launchpad.net/Packaging/PPA """ assert name.startswith('ppa:') user, repo = name[4:].split('/', 2) # For ubuntu based distribution with their own version system # e.g. Elementary OS Luna version returned by lsb_release is 0.2.1 # which raise ValueError exception on float() call try: release = float(distrib_release()) except ValueError: release = 12.04 if release >= 12.04: repo = repo.replace('.', '_') auto_accept = '--yes' if auto_accept else '' else: auto_accept = '' if not isinstance(keyserver, basestring) and keyserver: keyserver = keyserver[0] if keyserver: keyserver = '--keyserver ' + keyserver else: keyserver = '' distrib = distrib_codename() source = '/etc/apt/sources.list.d/%(user)s-%(repo)s-%(distrib)s.list' % locals() if not is_file(source): if release >= 14.04: # add-apt-repository moved to software-properties-common in 14.04 package('software-properties-common') else: package('python-software-properties') run_as_root('add-apt-repository %(auto_accept)s %(keyserver)s %(name)s' % locals(), pty=False) update_index()
def capabilities(): """Test capabilities functions in new distrition For openwrt: mv /etc/banner /etc/banner.disable fab -s "/bin/ash -l -c" capabilities """ print ("SYSTEM") print ("======") print("Distribution: %s" % system.distrib_id()) print("Release: %s" % system.distrib_release()) print("Codename: %s" % system.distrib_codename()) print("Desc: %s" % system.distrib_desc()) print("Arch: %s" % system.get_arch()) print("Hostname: %s" % system.get_hostname())
def capabilities(): """Test capabilities functions in new distrition For openwrt: mv /etc/banner /etc/banner.disable fab -s "/bin/ash -l -c" capabilities """ print("SYSTEM") print("======") print("Distribution: %s" % system.distrib_id()) print("Release: %s" % system.distrib_release()) print("Codename: %s" % system.distrib_codename()) print("Desc: %s" % system.distrib_desc()) print("Arch: %s" % system.get_arch()) print("Hostname: %s" % system.get_hostname())
def ppa(name, auto_accept=True, keyserver=None): """ Require a `PPA`_ package source. Example:: from fabtools import require # Node.js packages by Chris Lea require.deb.ppa('ppa:chris-lea/node.js', keyserver='my.keyserver.com') .. _PPA: https://help.launchpad.net/Packaging/PPA """ assert name.startswith('ppa:') user, repo = name[4:].split('/', 2) release = float(distrib_release()) if release >= 12.04: repo = repo.replace('.', '_') auto_accept = '--yes' if auto_accept else '' else: auto_accept = '' if not isinstance(keyserver, basestring) and keyserver: keyserver = keyserver[0] if keyserver: keyserver = '--keyserver ' + keyserver else: keyserver = '' distrib = distrib_codename() source = '/etc/apt/sources.list.d/%(user)s-%(repo)s-%(distrib)s.list' % locals( ) if not is_file(source): if release >= 14.04: # add-apt-repository moved to software-properties-common in 14.04 package('software-properties-common') else: package('python-software-properties') run_as_root( 'add-apt-repository %(auto_accept)s %(keyserver)s %(name)s' % locals(), pty=False) update_index()
def setup(): print(">>>>>>>>> Setup docker phase 1. ") sudo('sudo apt-get update') sudo('sudo apt-get -y install apt-transport-https ca-certificates') sudo( 'sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D' ) # On Ubuntu Precise 12.04(LTS) if distrib_codename() == 'precise': out = 'deb https://apt.dockerproject.org/repo ubuntu-precise main' # On Ubuntu Trusty 14.04(LTS) if distrib_codename() == 'trusty': out = 'deb https://apt.dockerproject.org/repo ubuntu-trusty main' # Ubuntu Wily 15.10 if distrib_codename() == 'wily': out = 'deb https://apt.dockerproject.org/repo ubuntu-wily main' # Ubuntu Xenial 16.04(LTS) if distrib_codename() == 'xenial': out = 'deb https://apt.dockerproject.org/repo ubuntu-xenial main' # On Debian Wheezy if distrib_codename() == 'wheezy': out = 'deb https://apt.dockerproject.org/repo debian-wheezy main' # On Debian Jessie if distrib_codename() == 'jessie': out = 'deb https://apt.dockerproject.org/repo debian-jessie main' #On Debian Stretch/Sid if distrib_codename() == 'sid': out = 'deb https://apt.dockerproject.org/repo debian-stretch main' print('Distro %s' % out) sudo('echo ' + out + ' > /etc/apt/sources.list.d/docker.list') with settings(abort_exception=FabricException): try: sudo('apt-get update && apt-get purge lxc-docker') except FabricException: pass sudo('apt-cache policy docker-engine') sudo('apt-get -y install linux-image-extra-$(uname -r)') sudo('reboot')
def ppa(name): """ Require a `PPA`_ package source. Example:: from fabtools import require # Node.js packages by Chris Lea require.deb.ppa('ppa:chris-lea/node.js') .. _PPA: https://help.launchpad.net/Packaging/PPA """ assert name.startswith('ppa:') user, repo = name[4:].split('/', 2) distrib = distrib_codename() source = '%(user)s-%(repo)s-%(distrib)s.list' % locals() if not is_file(source): package('python-software-properties') run_as_root('add-apt-repository %s' % name, pty=False) update_index()
def ppa(name, auto_accept=True, keyserver=None): """ Require a `PPA`_ package source. Example:: from fabtools import require # Node.js packages by Chris Lea require.deb.ppa('ppa:chris-lea/node.js', keyserver='my.keyserver.com') .. _PPA: https://help.launchpad.net/Packaging/PPA """ assert name.startswith('ppa:') user, repo = name[4:].split('/', 2) release = float(distrib_release()) if release >= 12.04: repo = repo.replace('.', '_') auto_accept = '--yes' if auto_accept else '' else: auto_accept = '' if not isinstance(keyserver, basestring) and keyserver: keyserver = keyserver[0] if keyserver: keyserver = '--keyserver ' + keyserver else: keyserver = '' distrib = distrib_codename() source = '/etc/apt/sources.list.d/%(user)s-%(repo)s-%(distrib)s.list' % locals() if not is_file(source): package('python-software-properties') run_as_root('add-apt-repository %(auto_accept)s %(keyserver)s %(name)s' % locals(), pty=False) update_index()
def deploy(app, with_blog=None, with_alembic=False): """deploy the app""" assert system.distrib_id() == 'Ubuntu' lsb_codename = system.distrib_codename() if lsb_codename != 'xenial': raise ValueError('unsupported platform: %s' % lsb_codename) # See whether the local appconfig clone is up-to-date with the remot master: remote_repo = local('git ls-remote [email protected]:shh-dlce/appconfig.git HEAD | awk \'{ print $1}\'') local_clone = local('git rev-parse HEAD') if remote_repo != local_clone: if confirm('Local appconfig clone is not up-to-date ' 'with remote master, continue?', default=False): print("Continuing deployment.") else: print("Deployment aborted.") return require.deb.packages(getattr(app, 'require_deb_%s' % lsb_codename) + app.require_deb) require.users.user(app.name, create_home=True, shell='/bin/bash') require.directory(str(app.www_dir), use_sudo=True) require.directory(str(app.www_dir / 'files'), use_sudo=True) require_logging(app.log_dir, logrotate=app.logrotate, access_log=app.access_log, error_log=app.error_log) workers = 3 if app.workers > 3 and env.environment == 'test' else app.workers with_blog = with_blog if with_blog is not None else app.with_blog if env.environment != 'staging': # Test and production instances are publicly accessible over HTTPS. letsencrypt.require_certbot() letsencrypt.require_cert(env.host) if env.environment == 'production': letsencrypt.require_cert(app) ctx = template_context(app, workers=workers, with_blog=with_blog) if app.stack == 'soundcomparisons': # pragma: no cover require.git.working_copy( 'https://github.com/{0}/{1}.git'.format(app.github_org, app.github_repos), path=str(app.home_dir / app.name), use_sudo=True, user=app.name) require_bower(app, d=app.home_dir / app.name / 'site' / 'js') require_grunt(app, d=app.home_dir / app.name / 'site' / 'js') require_php(app) require_mysql(app) with shell_env(SYSTEMD_PAGER=''): require.nginx.server() sudo_upload_template('nginx-php-fpm-app.conf', str(app.nginx_site), app=app, env=env) nginx.enable(app.name) if env.environment == 'production': # We only enable systemd services when deploying to production, because we don't want # to start and run things like backup to CDSTAR from non-production systems. systemd.enable(app, pathlib.Path(os.getcwd()) / 'systemd') service.reload('nginx') return # # Create a virtualenv for the app and install the app package in development mode, i.e. with # repository working copy in /usr/venvs/<APP>/src # require_venv( app.venv_dir, require_packages=[app.app_pkg] + app.require_pip, assets_name=app.name if app.stack == 'clld' else None) # # If some of the static assets are managed via bower, update them. # require_bower(app) require_grunt(app) require_nginx(ctx) if app.stack == 'clld': require_bibutils() require_postgres(app) require_config(app.config, app, ctx) # if gunicorn runs, make it gracefully reload the app by sending HUP # TODO: consider 'supervisorctl signal HUP $name' instead (xenial+) sudo('( [ -f {0} ] && kill -0 $(cat {0}) 2> /dev/null ' '&& kill -HUP $(cat {0}) ) || echo no reload '.format(app.gunicorn_pid)) if not with_alembic and confirm('Recreate database?', default=False): stop.execute_inner(app) upload_sqldump(app) elif exists(str(app.src_dir / 'alembic.ini')) and confirm('Upgrade database?', default=False): # Note: stopping the app is not strictly necessary, because # the alembic revisions run in separate transactions! stop.execute_inner(app, maintenance_hours=app.deploy_duration) alembic_upgrade_head(app, ctx) pip_freeze(app) start.execute_inner(app) check(app) if env.environment == 'production': systemd.enable(app, pathlib.Path(os.getcwd()) / 'systemd')