Beispiel #1
0
def make_new_env(
    env_request,
    branch_default=False,
    process_app_version=False,
    nohang=False,
    interactive=True,
    timeout=None,
    source=None,
):
    resolve_roles(env_request, interactive)

    build_config = None
    if fileoperations.build_spec_exists():
        build_config = fileoperations.get_build_configuration()
        LOG.debug("Retrieved build configuration from buildspec: {0}".format(
            build_config.__str__()))

    codecommit_setup = gitops.git_management_enabled()
    if not env_request.sample_application and not env_request.version_label:
        if source is not None:
            io.log_info('Creating new application version using remote source')
            io.echo("Starting environment deployment via remote source")
            env_request.version_label = commonops.create_app_version_from_source(
                env_request.app_name,
                source,
                process=process_app_version,
                label=env_request.version_label,
                build_config=build_config)
            process_app_version = True
        elif codecommit_setup:
            io.log_info('Creating new application version using CodeCommit')
            io.echo("Starting environment deployment via CodeCommit")
            env_request.version_label = \
                commonops.create_codecommit_app_version(env_request.app_name, process=process_app_version,
                                                        build_config=build_config)
            process_app_version = True
        else:
            io.log_info('Creating new application version using project code')
            env_request.version_label = \
                commonops.create_app_version(env_request.app_name, process=process_app_version,
                                             build_config=build_config)

        if build_config is not None:
            buildspecops.stream_build_configuration_app_version_creation(
                env_request.app_name, env_request.version_label, build_config)
        elif process_app_version is True:
            success = commonops.wait_for_processed_app_versions(
                env_request.app_name, [env_request.version_label],
                timeout=timeout or 5)
            if not success:
                return

    if env_request.version_label is None or env_request.sample_application:
        env_request.version_label = \
            commonops.create_dummy_app_version(env_request.app_name)

    if env_request.key_name:
        commonops.upload_keypair_if_needed(env_request.key_name)

    download_sample_app = None
    if interactive:
        download_sample_app = should_download_sample_app()

    io.log_info('Creating new environment')
    result, request_id = create_env(env_request, interactive=interactive)

    env_name = result.name

    default_env = commonops.get_current_branch_environment()
    if not default_env or branch_default:
        commonops.set_environment_for_current_branch(env_name)
        if codecommit_setup:
            io.echo("Setting up default branch")
            gitops.set_branch_default_for_current_environment(
                gitops.get_default_branch())
            gitops.set_repo_default_for_current_environment(
                gitops.get_default_repository())

    if download_sample_app:
        download_and_extract_sample_app(env_name)

    result.print_env_details(io.echo,
                             elasticbeanstalk.get_environments,
                             elasticbeanstalk.get_environment_resources,
                             health=False)

    statusops.alert_environment_status(result)

    if nohang:
        return

    io.echo('Printing Status:')

    commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout)
Beispiel #2
0
def make_new_env(env_request,
                 branch_default=False,
                 process_app_version=False,
                 nohang=False,
                 interactive=True,
                 timeout=None,
                 source=None):
    resolve_roles(env_request, interactive)

    # Parse and get Build Configuration from BuildSpec if it exists
    build_config = None
    if fileoperations.build_spec_exists():
        build_config = fileoperations.get_build_configuration()
        LOG.debug("Retrieved build configuration from buildspec: {0}".format(
            build_config.__str__()))

    # deploy code
    codecommit_setup = gitops.git_management_enabled()
    if not env_request.sample_application and not env_request.version_label:
        if source is not None:
            io.log_info('Creating new application version using remote source')
            io.echo("Starting environment deployment via remote source")
            env_request.version_label = commonops.create_app_version_from_source(
                env_request.app_name,
                source,
                process=process_app_version,
                label=env_request.version_label,
                build_config=build_config)
            process_app_version = True
        elif codecommit_setup:
            io.log_info('Creating new application version using CodeCommit')
            io.echo("Starting environment deployment via CodeCommit")
            env_request.version_label = \
                commonops.create_codecommit_app_version(env_request.app_name, process=process_app_version,
                                                        build_config=build_config)
            process_app_version = True
        else:
            io.log_info('Creating new application version using project code')
            env_request.version_label = \
                commonops.create_app_version(env_request.app_name, process=process_app_version,
                                             build_config=build_config)

        if build_config is not None:
            buildspecops.stream_build_configuration_app_version_creation(
                env_request.app_name, env_request.version_label, build_config)
        elif process_app_version is True:
            success = commonops.wait_for_processed_app_versions(
                env_request.app_name, [env_request.version_label])
            if not success:
                return

    if env_request.version_label is None or env_request.sample_application:
        env_request.version_label = \
            commonops.create_dummy_app_version(env_request.app_name)

    # Create env
    if env_request.key_name:
        commonops.upload_keypair_if_needed(env_request.key_name)

    io.log_info('Creating new environment')
    result, request_id = create_env(env_request, interactive=interactive)

    env_name = result.name  # get the (possibly) updated name

    # Edit configurations
    ## Get default environment
    default_env = commonops.get_current_branch_environment()
    ## Save env as branch default if needed
    if not default_env or branch_default:
        commonops.set_environment_for_current_branch(env_name)
        if codecommit_setup:
            io.echo("Setting up default branch")
            gitops.set_branch_default_for_current_environment(
                gitops.get_default_branch())
            gitops.set_repo_default_for_current_environment(
                gitops.get_default_repository())

    # Print status of env
    commonops.print_env_details(result, health=False)

    if nohang:
        return

    io.echo('Printing Status:')
    try:
        commonops.wait_for_success_events(request_id,
                                          timeout_in_minutes=timeout)
    except TimeoutError:
        io.log_error(strings['timeout.error'])
Beispiel #3
0
def make_new_env(
        env_request,
        branch_default=False,
        process_app_version=False,
        nohang=False,
        interactive=True,
        timeout=None,
        source=None,
):
    resolve_roles(env_request, interactive)

    # Parse and get Build Configuration from BuildSpec if it exists
    build_config = None
    if fileoperations.build_spec_exists():
        build_config = fileoperations.get_build_configuration()
        LOG.debug("Retrieved build configuration from buildspec: {0}".format(build_config.__str__()))

    # deploy code
    codecommit_setup = gitops.git_management_enabled()
    if not env_request.sample_application and not env_request.version_label:
        if source is not None:
            io.log_info('Creating new application version using remote source')
            io.echo("Starting environment deployment via remote source")
            env_request.version_label = commonops.create_app_version_from_source(
                env_request.app_name, source, process=process_app_version, label=env_request.version_label,
                build_config=build_config)
            process_app_version = True
        elif codecommit_setup:
            io.log_info('Creating new application version using CodeCommit')
            io.echo("Starting environment deployment via CodeCommit")
            env_request.version_label = \
                commonops.create_codecommit_app_version(env_request.app_name, process=process_app_version,
                                                        build_config=build_config)
            process_app_version = True
        else:
            io.log_info('Creating new application version using project code')
            env_request.version_label = \
                commonops.create_app_version(env_request.app_name, process=process_app_version,
                                             build_config=build_config)

        if build_config is not None:
            buildspecops.stream_build_configuration_app_version_creation(env_request.app_name, env_request.version_label, build_config)
        elif process_app_version is True:
            success = commonops.wait_for_processed_app_versions(env_request.app_name,
                                                                [env_request.version_label])
            if not success:
                return

    if env_request.version_label is None or env_request.sample_application:
        env_request.version_label = \
            commonops.create_dummy_app_version(env_request.app_name)

    # Create env
    if env_request.key_name:
        commonops.upload_keypair_if_needed(env_request.key_name)

    download_sample_app = None
    if interactive:
        download_sample_app = should_download_sample_app()

    io.log_info('Creating new environment')
    result, request_id = create_env(env_request,
                                    interactive=interactive)

    env_name = result.name  # get the (possibly) updated name

    # Edit configurations
    ## Get default environment
    default_env = commonops.get_current_branch_environment()
    ## Save env as branch default if needed
    if not default_env or branch_default:
        commonops.set_environment_for_current_branch(env_name)
        if codecommit_setup:
            io.echo("Setting up default branch")
            gitops.set_branch_default_for_current_environment(gitops.get_default_branch())
            gitops.set_repo_default_for_current_environment(gitops.get_default_repository())

    if download_sample_app:
        download_and_extract_sample_app(env_name)

    # Print status of env
    result.print_env_details(
        io.echo,
        elasticbeanstalk.get_environments,
        elasticbeanstalk.get_environment_resources,
        health=False
    )

    if nohang:
        return

    io.echo('Printing Status:')

    commonops.wait_for_success_events(request_id,
                                      timeout_in_minutes=timeout)