def _git_deploy(release, skip_tests): starting_branch = utils.branch() print(green("Deploying from git branch '%s'" % starting_branch)) # Ideally, tests would run on the version you are deploying exactly. # There is no easy way to require that without allowing users to go # through the entire tagging process before failing tests. if not skip_tests and testing.test(): abort(red("Unit tests did not pass -- must fix before deploying")) local('git push %(master_remote)s' % env, capture=True) deploy.release.make_release(release) require('pretty_release') require('path') require('hosts') print(green("Deploying version %s" % env.pretty_release)) put( os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'files', 'ssh_config'), '.ssh/config') deployed = False hard_reset = False deployed_versions = {} deploy.release.bootstrap_release_folders() for release_path in env.release_paths: with cd(os.path.join(env.path, env.releases_root, release_path)): deployed_versions[run('git describe')] = release_path print( green("The host '%s' currently has the revisions: %s" % (env.host, deployed_versions))) if env.pretty_release not in deployed_versions: env.release_path = os.path.join( env.path, env.releases_root, deploy.release.alternative_release_path()) with cd(env.release_path): run('git fetch %(master_remote)s' % env, forward_agent=True) run('git reset --hard %(release)s' % env) deploy.cron.conditional_install_crontab(env.release_path, env.crontab, env.deploy_user) deployed = True else: warn(red("%(pretty_release)s is already deployed" % env)) env.release_path = os.path.join(env.path, env.releases_root, deployed_versions[env.pretty_release]) with cd(env.release_path): run('git submodule update --init --recursive', forward_agent=True) hard_reset = deploy.packages.install_requirements(deployed) deploy.utils.run_extra_deploy_tasks(deployed) local('git checkout %s' % starting_branch, capture=True) chmod(os.path.join(env.path, env.releases_root), 'g+w', use_sudo=True) return deployed, hard_reset
def _git_deploy(release, skip_tests): starting_branch = utils.branch() print(green("Deploying from git branch '%s'" % starting_branch)) # Ideally, tests would run on the version you are deploying exactly. # There is no easy way to require that without allowing users to go # through the entire tagging process before failing tests. if not skip_tests and testing.test(): abort(red("Unit tests did not pass -- must fix before deploying")) #local('git push %(master_remote)s' % env, capture=True) #buedafab.deploy.release.make_release(release) make_release(release) require('pretty_release') require('path') require('hosts') print(green("Deploying version %s" % env.pretty_release)) put(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'files', 'ssh_config'), '.ssh/config') deployed = False hard_reset = False deployed_versions = {} bootstrap_release_folders() for release_path in env.release_paths: with cd(os.path.join(env.path, env.releases_root, release_path)): deployed_versions[run('git describe')] = release_path print(green("The host '%s' currently has the revisions: %s" % (env.host, deployed_versions))) if env.pretty_release not in deployed_versions: env.release_path = os.path.join(env.path, env.releases_root, alternative_release_path()) with cd(env.release_path): run('git fetch %(master_remote)s --tag' % env, forward_agent=False) run('git fetch %(master_remote)s' % env, forward_agent=False) run("git reset --hard %(release)s" % env) cron.conditional_install_crontab(env.release_path, env.crontab, env.deploy_user) deployed = True else: warn(red("%(pretty_release)s is already deployed" % env)) env.release_path = os.path.join(env.path, env.releases_root, deployed_versions[env.pretty_release]) with cd(env.release_path): run('git submodule update --init --recursive', forward_agent=False) hard_reset = packages.install_requirements(deployed) run_extra_deploy_tasks(deployed) local('git checkout %s' % starting_branch, capture=True) chmod(os.path.join(env.path, env.releases_root), 'g+w', use_sudo=True) return deployed, hard_reset
def bootstrap_release_folders(): """Create the target deploy directories if they don't exist and clone a fresh copy of the project's repository into each of the release directories. """ require('path') require('deploy_group') conditional_mkdir(os.path.join(env.path, env.releases_root), env.deploy_group, 'g+w', use_sudo=True) with cd(os.path.join(env.path, env.releases_root)): first_exists = exists(env.release_paths[0]) if not first_exists: run('git clone %s %s' % (env.scm, env.release_paths[0]), forward_agent=True) with cd(os.path.join(env.path, env.releases_root)): if not exists(env.release_paths[1]): run('cp -R %s %s' % (env.release_paths[0], env.release_paths[1])) chmod(os.path.join(env.path, env.releases_root), 'g+w', use_sudo=True)
def update_and_restart_celery(): """Render a celeryd init.d script template and upload it to the remote server, then restart the celeryd process to reload the configuration. In addition to any env keys required by the celeryd template, requires: celeryd -- relateive path to the celeryd init.d script template from the project root unit -- project's brief name, used to give each celeryd script and process a unique name, if more than one are running on the same host deployment_type -- app environment, to differentiate between celeryd processes for the same app in different environments on the same host (e.g. if staging and development run on the same physical server) The template is uploaded to: /etc/init.d/celeryd-%(unit)s_%(deployment_type)s which in final form might look like: /etc/init.d/celeryd-five_DEV """ require('path') require('celeryd') require('unit') require('deployment_type') if env.celeryd: celeryd_path = os.path.join(env.root_dir, env.celeryd) celeryd_remote_path = ( '/etc/init.d/celeryd-%(unit)s_%(deployment_type)s' % env) upload_template(celeryd_path, celeryd_remote_path, env, use_sudo=True) # Wipe the -B option so it only happens once env.celeryd_beat_option = "" chmod(celeryd_remote_path, 'u+x') sudo(celeryd_remote_path + ' restart')
def update_and_restart_celery(): """Render a celeryd init.d script template and upload it to the remote server, then restart the celeryd process to reload the configuration. In addition to any env keys required by the celeryd template, requires: celeryd -- relateive path to the celeryd init.d script template from the project root unit -- project's brief name, used to give each celeryd script and process a unique name, if more than one are running on the same host deployment_type -- app environment, to differentiate between celeryd processes for the same app in different environments on the same host (e.g. if staging and development run on the same physical server) The template is uploaded to: /etc/init.d/celeryd-%(unit)s_%(deployment_type)s which in final form might look like: /etc/init.d/celeryd-five_DEV """ require("path") require("celeryd") require("unit") require("deployment_type") if env.celeryd: celeryd_path = os.path.join(env.root_dir, env.celeryd) celeryd_remote_path = "/etc/init.d/celeryd-%(unit)s_%(deployment_type)s" % env upload_template(celeryd_path, celeryd_remote_path, env, use_sudo=True) # Wipe the -B option so it only happens once env.celeryd_beat_option = "" chmod(celeryd_remote_path, "u+x") sudo(celeryd_remote_path + " restart")