Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
Archivo: types.py Proyecto: nkeilar/ops
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
Ejemplo n.º 3
0
def campfire_notify(deployed=False):
    """Hop in Campfire and notify your developers of the time and commit SHA of
    an app deploy.

    Requires the pinder Python package and the env keys:

        deployment_type - app environment
        release - the commit SHA or git tag of the deployed version
        scm_http_url - path to an HTTP view of the remote git repository
        campfire_subdomain - subdomain of your Campfire account
        campfire_token - API token for Campfire
        campfire_room - the room to join and notify (the string name, e.g.
                        "Developers")
    """
    require('deployment_type')
    require('release')

    if (deployed and env.campfire_subdomain and env.campfire_token
            and env.campfire_room):
        from pinder import Campfire
        deploying = local('git rev-list --abbrev-commit %s | head -n 1' %
                          env.release,
                          capture=True)
        branch = utils.branch(env.release)

        if env.tagged:
            require('release')
            branch = env.release

        name = env.unit
        deployer = os.getlogin()
        deployed = env.deployed_version
        target = env.deployment_type.lower()
        source_repo_url = env.scm_http_url
        compare_url = ('%s/compare/%s...%s' %
                       (source_repo_url, deployed, deploying))

        campfire = Campfire(env.campfire_subdomain,
                            env.campfire_token,
                            ssl=True)
        room = campfire.find_room_by_name(env.campfire_room)
        room.join()
        if deployed:
            message = ('%s is deploying %s %s (%s..%s) to %s %s' %
                       (deployer, name, branch, deployed, deploying, target,
                        compare_url))
        else:
            message = ('%s is deploying %s %s to %s' %
                       (deployer, name, branch, target))
        room.speak(message)
        print 'Campfire notified that %s' % message
Ejemplo n.º 4
0
def campfire_notify(deployed=False):
    """Hop in Campfire and notify your developers of the time and commit SHA of
    an app deploy.

    Requires the pinder Python package and the env keys:

        deployment_type - app environment
        release - the commit SHA or git tag of the deployed version
        scm_http_url - path to an HTTP view of the remote git repository
        campfire_subdomain - subdomain of your Campfire account
        campfire_token - API token for Campfire
        campfire_room - the room to join and notify (the string name, e.g.
                        "Developers")
    """
    require('deployment_type')
    require('release')

    if (deployed and env.campfire_subdomain and env.campfire_token
            and env.campfire_room):
        from pinder import Campfire
        deploying = local('git rev-list --abbrev-commit %s | head -n 1' %
                env.release, capture=True)
        branch = utils.branch(env.release)

        if env.tagged:
            require('release')
            branch = env.release

        name = env.unit
        deployer = os.getlogin()
        deployed = env.deployed_version
        target = env.deployment_type.lower()
        source_repo_url = env.scm_http_url
        compare_url = ('%s/compare/%s...%s' % (source_repo_url, deployed,
                deploying))

        campfire = Campfire(env.campfire_subdomain, env.campfire_token,
                ssl=True)
        room = campfire.find_room_by_name(env.campfire_room)
        room.join()
        if deployed:
            message = ('%s is deploying %s %s (%s..%s) to %s %s'
                % (deployer, name, branch, deployed, deploying, target,
                    compare_url))
        else:
            message = ('%s is deploying %s %s to %s' % (deployer, name,
                branch, target))
        room.speak(message)
        print 'Campfire notified that %s' % message
Ejemplo n.º 5
0
def make_release(release=None):
    """Based on the deployment type and any arguments from the command line,
    determine the proper identifier for the commit to deploy.

    If a tag is required (e.g. when in the production app environment), the
    deploy must be coming from the master branch, and cannot proceed without
    either creating a new tag or specifing and existing one.

    Requires the env keys:
        allow_no_tag - whether or not to require the release to be tagged in git
        default_revision - the commit ref for HEAD
    """
    require('allow_no_tag')
    require('default_revision')

    env.release = release
    env.tagged = False
    if not env.release or env.release == 'latest_tag':
        if not env.allow_no_tag:
            branch = utils.branch()
            if branch != "master":
                abort("Make sure to checkout the master branch and merge in the"
                        " development branch before deploying to production.")
            local('git checkout master', capture=True)
        description = local('git describe master' % env, capture=True
                ).rstrip('\n')
        if '-' in description:
            env.latest_tag = description[:description.find('-')]
        else:
            env.latest_tag = description
        if not re.match(env.version_pattern, env.latest_tag):
            env.latest_tag = None
        env.release = env.release or env.latest_tag
        env.commit = 'HEAD'
        if not env.allow_no_tag:
            if confirm(yellow("Tag this release?"), default=False):
                require('master_remote')
                from prettyprint import pp
                print(green("The last 5 tags were: "))
                tags = local('git tag | tail -n 20', capture=True)
                pp(sorted(tags.split('\n'), utils.compare_versions,
                        reverse=True))
                prompt("New release tag in the format vX.Y[.Z]?",
                        'tag',
                        validate=env.version_pattern)
                require('commit')
                local('git tag -s %(tag)s %(commit)s' % env)
                local('git push --tags %(master_remote)s' % env, capture=True)
                env.tagged = True
                env.release = env.tag
                local('git fetch --tags %(master_remote)s' % env, capture=True)
            else:
                print(green("Using latest tag %(latest_tag)s" % env))
                env.release = env.latest_tag
        else:
            make_head_commit()
            env.release = env.head_commit
            print(green("Using the HEAD commit %s" % env.head_commit))
    else:
        local('git checkout %s' % env.release, capture=True)
        env.tagged = re.match(env.version_pattern, env.release)
    make_pretty_release()
Ejemplo n.º 6
0
def make_release(release=None):
    """Based on the deployment type and any arguments from the command line,
    determine the proper identifier for the commit to deploy.

    If a tag is required (e.g. when in the production app environment), the
    deploy must be coming from the master branch, and cannot proceed without
    either creating a new tag or specifing and existing one.

    Requires the env keys:
        allow_no_tag - whether or not to require the release to be tagged in git
        default_revision - the commit ref for HEAD
    """
    require('allow_no_tag')
    require('default_revision')

    env.release = release
    env.tagged = False
    if not env.release or env.release == 'latest_tag':
        if not env.allow_no_tag:
            branch = utils.branch()
            if branch != "master":
                abort(
                    "Make sure to checkout the master branch and merge in the"
                    " development branch before deploying to production.")
            local('git checkout master', capture=True)
        description = local('git describe master' % env,
                            capture=True).rstrip('\n')
        if '-' in description:
            env.latest_tag = description[:description.find('-')]
        else:
            env.latest_tag = description
        if not re.match(env.version_pattern, env.latest_tag):
            env.latest_tag = None
        env.release = env.release or env.latest_tag
        env.commit = 'HEAD'
        if not env.allow_no_tag:
            if confirm(yellow("Tag this release?"), default=False):
                require('master_remote')
                from prettyprint import pp
                print(green("The last 5 tags were: "))
                tags = local('git tag | tail -n 20', capture=True)
                pp(
                    sorted(tags.split('\n'),
                           utils.compare_versions,
                           reverse=True))
                prompt("New release tag in the format vX.Y[.Z]?",
                       'tag',
                       validate=env.version_pattern)
                require('commit')
                local('git tag -s %(tag)s %(commit)s' % env)
                local('git push --tags %(master_remote)s' % env, capture=True)
                env.tagged = True
                env.release = env.tag
                local('git fetch --tags %(master_remote)s' % env, capture=True)
            else:
                print(green("Using latest tag %(latest_tag)s" % env))
                env.release = env.latest_tag
        else:
            make_head_commit()
            env.release = env.head_commit
            print(green("Using the HEAD commit %s" % env.head_commit))
    else:
        local('git checkout %s' % env.release, capture=True)
        env.tagged = re.match(env.version_pattern, env.release)
    make_pretty_release()