Esempio n. 1
0
    def test_get_default_repository__could_not_find_repository(
            self,
            get_repo_default_for_current_environment_mock
    ):
        get_repo_default_for_current_environment_mock.return_value = None

        self.assertIsNone(gitops.get_default_repository())
Esempio n. 2
0
def _print_codecommit_repositories():
    default_branch = gitops.get_default_branch()
    default_repo = gitops.get_default_repository()
    if default_repo and default_branch:
        io.echo("Current CodeCommit settings:")
        io.echo("  Repository: " + str(default_repo))
        io.echo("  Branch: " + str(default_branch))
Esempio n. 3
0
def create_codecommit_app_version(app_name,
                                  process=False,
                                  label=None,
                                  message=None,
                                  build_config=None):
    fileoperations.ProjectRoot.traverse()

    source_control = SourceControl.get_source_control()
    if source_control.get_current_commit() is None:
        io.log_warning(
            'There are no commits for the current branch, attempting '
            'to create an empty commit and launching with the sample '
            'application')
        source_control.create_initial_commit()

    if source_control.untracked_changes_exist():
        io.log_warning(strings['sc.unstagedchanges'])

    if label:
        version_label = label
    else:
        version_label = source_control.get_version_label()

    if message:
        description = message
    else:
        description = source_control.get_message()

    if len(description) > 200:
        description = description[:195] + '...'

    try:
        source_control.push_codecommit_code()
    except CommandError as e:
        io.echo("Could not push code to the CodeCommit repository:")
        raise e

    from ebcli.operations import gitops
    repository = gitops.get_default_repository()
    commit_id = source_control.get_current_commit()

    if repository is None or commit_id is None:
        raise ServiceError(
            "Could not find repository or commit id to create an application version"
        )

    io.log_info('Creating AppVersion ' + version_label)
    return _create_application_version(app_name,
                                       version_label,
                                       description,
                                       None,
                                       None,
                                       process,
                                       repository=repository,
                                       commit_id=commit_id,
                                       build_config=build_config)
Esempio n. 4
0
    def test_get_default_repository(
            self,
            get_repo_default_for_current_environment_mock
    ):
        get_repo_default_for_current_environment_mock.return_value = 'my-repository'

        self.assertEqual(
            'my-repository',
            gitops.get_default_repository()
        )
Esempio n. 5
0
    def __attempt_to_checkout_branch_specified_in_source_input(source):
        source_location, repo, branch = utils.parse_source(source)

        source_control = SourceControl.get_source_control()
        source_control.is_setup()

        repo = repo or gitops.get_default_repository()

        useops.switch_default_repo_and_branch(repo, branch)
        successfully_checked_out_branch = source_control.checkout_branch(
            branch)

        if not successfully_checked_out_branch:
            raise NotFoundError(
                "Could not checkout branch {0}.".format(branch))
Esempio n. 6
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'])
Esempio n. 7
0
def create_codecommit_app_version(app_name,
                                  process=False,
                                  label=None,
                                  message=None,
                                  build_config=None):
    cwd = os.getcwd()
    fileoperations._traverse_to_project_root()

    source_control = SourceControl.get_source_control()
    if source_control.get_current_commit() is None:
        io.log_warning(
            'There are no commits for the current branch, attempting to create an empty commit and launching with the sample application'
        )
        source_control.create_initial_commit()

    if source_control.untracked_changes_exist():
        io.log_warning(strings['sc.unstagedchanges'])

    #get version_label
    if label:
        version_label = label
    else:
        version_label = source_control.get_version_label()

    # get description
    if message:
        description = message
    else:
        description = source_control.get_message()

    if len(description) > 200:
        description = description[:195] + '...'

    # Push code with git
    try:
        source_control.push_codecommit_code()
    except CommandError as e:
        io.echo("Could not push code to the CodeCommit repository:")
        raise e

    # Get additional arguments for deploying code commit and poll
    #  for the commit to propagate to code commit.
    from ebcli.operations import gitops
    repository = gitops.get_default_repository()
    commit_id = source_control.get_current_commit()

    if repository is None or commit_id is None:
        raise ServiceError(
            "Could not find repository or commit id to create an application version"
        )

    # Deploy Application version with freshly pushed git commit

    io.log_info('Creating AppVersion ' + version_label)
    return _create_application_version(app_name,
                                       version_label,
                                       description,
                                       None,
                                       None,
                                       process,
                                       repository=repository,
                                       commit_id=commit_id,
                                       build_config=build_config)
Esempio n. 8
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)
Esempio n. 9
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)