Example #1
0
def setup(branch=None):
    """
    Setup a fresh virtualenv as well as a few useful directories, install the requirements.
    """
    require('path')
    with env.cd_cmd(PROJECT_PATH):
        env.gitbranch = branch or local('git rev-parse --abbrev-ref HEAD', capture=True)

    make_dirs()

    # create user & add to group
    sudo('grep "{server_owner:s}" /etc/passwd > /dev/null || adduser {server_owner:s} && usermod -G {server_group:s} {server_owner:s}'.format(**env))

    # create virtualenv, clone repo
    sudo('test -e /srv/myapp/env/bin/activate || /usr/local/bin/virtualenv /srv/myapp/env'.format(**env), user=env.server_owner)

    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo('test -e /srv/myapp/repo/.git || /usr/bin/git clone -q -b {gitbranch:s} {gitsource:s} .'.format(**env))

    # install requirements into virtualenv - do it from the repo on setup; subsequent installs should be from the release
    deploy_secrets(False)
    deploy_manage_wrapper()
    deploy()

    restart_webserver()
    restart_supervisor()
    start_celery()
Example #2
0
def run_puppet():
    '''Installs puppet, and runs the puppet manifests.'''

    # Install puppet
    if run('test -e /usr/bin/puppet', warn_only=True).return_code != 0:
        sudo(
            'apt-get install -qq -y apt-transport-https python-software-properties'
        )
        sudo('apt-get update -qq')
        sudo('apt-get install -qq -y puppet')

    fd, filename = tempfile.mkstemp(suffix='.tar.gz')
    os.close(fd)

    repo_root = os.path.dirname(os.path.abspath(__file__))
    with lcd(repo_root):
        # Upload a copy of the current branch
        local(
            'git archive `git rev-parse --abbrev-ref HEAD` --prefix=puppet/ | gzip > {filename:s}'
            .format(filename=filename))
        put(filename, '/root/puppet.tar.gz', use_sudo=True)
        local('rm {}'.format(filename))

    with env.cd_cmd('/root'):
        sudo('tar xzf puppet.tar.gz')

    with env.cd_cmd('/root/puppet'):
        sudo(
            'puppet apply --modulepath=/root/puppet/provisioning/puppet/modules/ /root/puppet/provisioning/puppet/manifests/{}.pp'
            .format(env.puppet_manifest))

    install_ssl_cert()

    sudo('rm /root/puppet.tar.gz && rm -rf /root/puppet')
Example #3
0
def run_puppet():
    '''Installs puppet, and runs the puppet manifests.'''

    # Install puppet
    if run('test -e /usr/bin/puppet', warn_only=True).return_code != 0:
        sudo('apt-get install -qq -y apt-transport-https python-software-properties')
        sudo('apt-get update -qq')
        sudo('apt-get install -qq -y puppet')

    fd, filename = tempfile.mkstemp(suffix='.tar.gz')
    os.close(fd)

    repo_root = os.path.dirname(os.path.abspath(__file__))
    with lcd(repo_root):
        # Upload a copy of the current branch
        local('git archive `git rev-parse --abbrev-ref HEAD` --prefix=puppet/ | gzip > {filename:s}'.format(filename=filename))
        put(filename, '/root/puppet.tar.gz', use_sudo=True)
        local('rm {}'.format(filename))

    with env.cd_cmd('/root'):
        sudo('tar xzf puppet.tar.gz')

    with env.cd_cmd('/root/puppet'):
        sudo('puppet apply --modulepath=/root/puppet/provisioning/puppet/modules/ /root/puppet/provisioning/puppet/manifests/{}.pp'.format(env.puppet_manifest))

    install_ssl_cert()

    sudo('rm /root/puppet.tar.gz && rm -rf /root/puppet')
Example #4
0
def symlink_current_release():
    "Symlink our current release"
    require('release')
    require('server_owner')

    # all the "if" stuff in case there *is* no current or prev release
    with env.cd_cmd('/srv/myapp/releases'):
        sudo('rm -f previous', user=env.server_owner)
        sudo('test -e current && mv current previous || echo ""', user=env.server_owner)
        sudo('ln -s {release:s} current;'.format(**env), user=env.server_owner)
Example #5
0
def symlink_current_release():
    "Symlink our current release"
    require('release')
    require('server_owner')

    # all the "if" stuff in case there *is* no current or prev release
    with env.cd_cmd('/srv/myapp/releases'):
        sudo('rm -f previous', user=env.server_owner)
        sudo('test -e current && mv current previous || echo ""',
             user=env.server_owner)
        sudo('ln -s {release:s} current;'.format(**env), user=env.server_owner)
Example #6
0
def create_release():
    require('release')

    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo('/usr/bin/git checkout-index -a -f --prefix=/srv/myapp/releases/{release:s}/'.format(**env))
            sudo('/usr/bin/git submodule foreach --recursive \'/usr/bin/git checkout-index -a -f --prefix=/srv/myapp/releases/{release:s}/$path/\''.format(**env))
    else:
        sudo('ln -s /vagrant /srv/myapp/releases/{release:s}'.format(**env), user=env.server_owner)

    sudo('chown -R {server_owner:s}:{server_group:s} /srv/myapp'.format(**env))
Example #7
0
def setup(branch=None):
    """
    Setup a fresh virtualenv as well as a few useful directories, install the requirements.
    """
    require('path')
    with env.cd_cmd(PROJECT_PATH):
        env.gitbranch = branch or local('git rev-parse --abbrev-ref HEAD',
                                        capture=True)

    make_dirs()

    # create user & add to group
    sudo(
        'grep "{server_owner:s}" /etc/passwd > /dev/null || adduser {server_owner:s} && usermod -G {server_group:s} {server_owner:s}'
        .format(**env))

    # create virtualenv, clone repo
    sudo(
        'test -e /srv/myapp/env/bin/activate || /usr/local/bin/virtualenv /srv/myapp/env'
        .format(**env),
        user=env.server_owner)

    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo(
                'test -e /srv/myapp/repo/.git || /usr/bin/git clone -q -b {gitbranch:s} {gitsource:s} .'
                .format(**env))

    # install requirements into virtualenv - do it from the repo on setup; subsequent installs should be from the release
    deploy_secrets(False)
    deploy_manage_wrapper()
    deploy()

    restart_webserver()
    restart_supervisor()
    start_celery()
Example #8
0
def create_release():
    require('release')

    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo(
                '/usr/bin/git checkout-index -a -f --prefix=/srv/myapp/releases/{release:s}/'
                .format(**env))
            sudo(
                '/usr/bin/git submodule foreach --recursive \'/usr/bin/git checkout-index -a -f --prefix=/srv/myapp/releases/{release:s}/$path/\''
                .format(**env))
    else:
        sudo('ln -s /vagrant /srv/myapp/releases/{release:s}'.format(**env),
             user=env.server_owner)

    sudo('chown -R {server_owner:s}:{server_group:s} /srv/myapp'.format(**env))
Example #9
0
def git_checkout(branch):
    with env.cd_cmd('/srv/myapp/repo'):
        sudo('/usr/bin/git pull --rebase')
        sudo('/usr/bin/git checkout {}'.format(branch))
Example #10
0
def update_from_git():
    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo('/usr/bin/git pull --rebase')
Example #11
0
def git_checkout(branch):
    with env.cd_cmd('/srv/myapp/repo'):
        sudo('/usr/bin/git pull --rebase')
        sudo('/usr/bin/git checkout {}'.format(branch))
Example #12
0
def update_from_git():
    if env.gitsource:
        with env.cd_cmd('/srv/myapp/repo'):
            sudo('/usr/bin/git pull --rebase')