def create_config_file(app_name, region, solution_stack, dir_path=None, repository=None, branch=None): """ We want to make sure we do not override the file if it already exists, but we do want to fill in all missing pieces :param app_name: name of the application :return: VOID: no return value """ LOG.debug('Creating config file at ' + os.getcwd()) if not os.path.isdir( os.path.join(dir_path, beanstalk_directory ) if dir_path else beanstalk_directory): os.makedirs( os.path.join(dir_path, beanstalk_directory ) if dir_path else beanstalk_directory) # add to global without writing over any settings if they exist write_config_setting('global', 'application_name', app_name, dir_path=dir_path) write_config_setting('global', 'default_region', region, dir_path=dir_path) write_config_setting('global', 'default_platform', solution_stack, dir_path=dir_path) from ebcli.operations import gitops gitops.set_repo_default_for_current_environment(repository) gitops.set_branch_default_for_current_environment(branch)
def create_config_file(app_name, region, solution_stack, workspace_type=Constants.WorkSpaceTypes.APPLICATION, platform_name=None, platform_version=None, instance_profile=None, dir_path=None, repository=None, branch=None): """ We want to make sure we do not override the file if it already exists, but we do want to fill in all missing pieces :param app_name: name of the application :return: VOID: no return value """ LOG.debug('Creating config file at ' + os.getcwd()) if not os.path.isdir( os.path.join(dir_path, beanstalk_directory ) if dir_path else beanstalk_directory): os.makedirs( os.path.join(dir_path, beanstalk_directory ) if dir_path else beanstalk_directory) write_config_setting('global', 'application_name', app_name, dir_path=dir_path) write_config_setting('global', 'default_region', region, dir_path=dir_path) write_config_setting('global', 'default_platform', solution_stack, dir_path=dir_path) write_config_setting('global', 'workspace_type', workspace_type, dir_path=dir_path) write_config_setting('global', 'platform_name', platform_name, dir_path=dir_path) write_config_setting('global', 'platform_version', platform_version, dir_path=dir_path) write_config_setting('global', 'instance_profile', instance_profile, dir_path=dir_path) from ebcli.operations import gitops gitops.set_repo_default_for_current_environment(repository) gitops.set_branch_default_for_current_environment(branch)
def create_config_file( app_name, region, solution_stack, workspace_type=Constants.WorkSpaceTypes.APPLICATION, platform_name=None, platform_version=None, instance_profile=None, dir_path=None, repository=None, branch=None): """ We want to make sure we do not override the file if it already exists, but we do want to fill in all missing pieces :param app_name: name of the application :return: VOID: no return value """ LOG.debug('Creating config file at ' + os.getcwd()) if not os.path.isdir(os.path.join(dir_path, beanstalk_directory) if dir_path else beanstalk_directory): os.makedirs(os.path.join(dir_path, beanstalk_directory) if dir_path else beanstalk_directory) # add to global without writing over any settings if they exist write_config_setting('global', 'application_name', app_name, dir_path=dir_path) write_config_setting('global', 'default_region', region, dir_path=dir_path) write_config_setting('global', 'default_platform', solution_stack, dir_path=dir_path) write_config_setting('global', 'workspace_type', workspace_type, dir_path=dir_path) write_config_setting('global', 'platform_name', platform_name, dir_path=dir_path) write_config_setting('global', 'platform_version', platform_version, dir_path=dir_path) write_config_setting('global', 'instance_profile', instance_profile, dir_path=dir_path) from ebcli.operations import gitops gitops.set_repo_default_for_current_environment(repository) gitops.set_branch_default_for_current_environment(branch)
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'])
def test_set_branch_default_for_current_environment( self, write_setting_to_current_environment_or_default_mock ): gitops.set_branch_default_for_current_environment('my-branch') write_setting_to_current_environment_or_default_mock.assert_called_once_with('branch', 'my-branch')
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)
def switch_default_repo_and_branch(repo_name, branch_name): __verify_codecommit_branch_and_repository_exist(repo_name, branch_name) gitops.set_repo_default_for_current_environment(repo_name) gitops.set_branch_default_for_current_environment(branch_name)
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)