Exemplo n.º 1
0
def setup_remote(quiet=True):
    ''' Setup remote environment before we can proceed with the deployment process. '''
    base_dir = get_deploy_dir()
    release_dir = get_release_dir()
    current_path = get_current_path()
    build_history_path = get_builds_file()
    preset = get_config()['deployment']['preset']
    did_setup = False
    stage = shell.get_stage()

    # If the release directory does not exist, create it.
    if not fs.exists(release_dir):
        remote_info('Setting up {} server for {} deployment'.format(
            stage, preset))
        remote_info('Creating the releases directory {}'.format(
            cyan(release_dir)))
        fs.mkdir(release_dir, nested=True)

        # Add build history file.
        remote_info('Creating new build meta file {}'.format(
            cyan(build_history_path)))
        save_history(merge(INITIAL_BUILD_HISTORY, {'preset': preset}))

        # Setup a default web page for web deployment.
        if preset == presets.WEB:
            setup_default_html(base_dir)

        did_setup = True

    if not did_setup and not quiet:
        remote_info('Remote already setup for deployment')

    return (release_dir, current_path)
Exemplo n.º 2
0
def upload_included_files(files, remote_path):
    ''' Upload the local files if they were to be included. '''
    for filename in files:
        # Skip upload if the file doesn't exist.
        if not fs.exists(filename, remote=False):
            continue

        fs.upload(filename, remote_path)
Exemplo n.º 3
0
def run_deploy_script(stage, branch):
    ''' Run the deployment script on the remote host. '''
    script_path = get_deploy_dir() + REMOTE_SCRIPT
    init_script_path = get_deploy_dir() + REMOTE_INIT_SCRIPT
    repo_path = get_repo_path()

    # Check if the script exists (with version) on the remote.
    if not fs.exists(script_path):
        with hide('everything'):
            runner.run('mkdir -p ' + repo_path)
            fs.upload(BASE_PATH + '/misc/scripts/init.sh', init_script_path)
            fs.upload(BASE_PATH + '/misc/scripts/remote-source-deploy.sh',
                      script_path)

    env_vars = dict(
        STAGE=stage,
        BRANCH=branch,
        BASE_DIR=get_deploy_dir(),
        INIT_SCRIPT_PATH=init_script_path,
        REPOSITORY_PATH=repo_path,
        REPOSITORY_URL=get_config()['repository_url'],
        SCRIPT_BUILD=runner.get_script_cmd(known_scripts.BUILD),
        SCRIPT_RELOAD=runner.get_script_cmd(known_scripts.RELOAD),
        SCRIPT_INSTALL=runner.get_script_cmd(known_scripts.INSTALL),
        SCRIPT_STATUS_CHECK=runner.get_script_cmd(known_scripts.STATUS_CHECK),
        SCRIPT_PRE_BUILD=runner.get_script_cmd(known_scripts.PRE_BUILD),
        SCRIPT_POST_BUILD=runner.get_script_cmd(known_scripts.POST_BUILD),
        SCRIPT_PRE_INSTALL=runner.get_script_cmd(known_scripts.PRE_INSTALL),
        SCRIPT_POST_INSTALL=runner.get_script_cmd(known_scripts.POST_INSTALL),
        SCRIPT_PRE_DEPLOY=runner.get_script_cmd(known_scripts.PRE_DEPLOY),
        SCRIPT_POST_DEPLOY=runner.get_script_cmd(known_scripts.POST_DEPLOY))

    # Change None to ''
    # TODO: Create a util function map for dictionary
    for k, v in env_vars.iteritems():
        if v is None:
            env_vars[k] = ''

    with hide('running'):
        with shell_env(**env_vars):
            # Run the sync script on the remote
            runner.run('sh ' + script_path)
Exemplo n.º 4
0
def is_remote_setup():
    ''' Check if the remote is setup for deployment. '''
    release_dir = get_release_dir()
    return fs.exists(release_dir)