def delete_platform_version(platform_version, force=False): arn = _version_to_arn(platform_version) if not force: io.echo(prompts['platformdelete.confirm'].replace('{platform-arn}', arn)) io.validate_action(prompts['platformdelete.validate'], arn) environments = [] try: environments = [env for env in elasticbeanstalk.get_environments() if env.platform.version == arn] except NotFoundError: pass if len(environments) > 0: _, platform_name, platform_version = PlatformVersion.arn_to_platform(arn) raise ValidationError(strings['platformdeletevalidation.error'].format( platform_name, platform_version, '\n '.join([env.name for env in environments]) )) response = elasticbeanstalk.delete_platform(arn) request_id = response['ResponseMetadata']['RequestId'] timeout = 10 commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout, platform_arn=arn)
def restore(env_id): validate_restore(env_id) try: request_id = elasticbeanstalk.rebuild_environment(env_id=env_id) except InvalidParameterValueError as e: message = e.message.replace('rebuild', 'restore') raise InvalidParameterValueError(message) commonops.wait_for_success_events(request_id, timeout_in_minutes=None, can_abort=True)
def update_tags(self): request_id = elasticbeanstalk.update_tags_for_resource( self.env_name, self.taglist.additions + self.taglist.updates, self.taglist.deletions ) wait_for_success_events(request_id) if self.verbose: self.__communicate_changes_to_stdout()
def setenv(app_name, env_name, var_list, timeout=None): options, options_to_remove = create_environment_variables_list(var_list) request_id = elasticbeanstalk.update_environment(env_name, options, remove=options_to_remove) if timeout is None: # specify a lower timeout duration because the `UpdateEnvironment` # workflow does not take very long to just set environment variables. timeout = 4 commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout, can_abort=True)
def retrieve_beanstalk_logs(env_name, info_type, do_zip=False, instance_id=None): # Request info result = elasticbeanstalk.request_environment_info(env_name, info_type) # Wait for logs to finish request_id = result['ResponseMetadata']['RequestId'] io.echo(prompts['logs.retrieving']) commonops.wait_for_success_events(request_id, timeout_in_minutes=2, sleep_time=1, stream_events=False) get_logs(env_name, info_type, do_zip=do_zip, instance_id=instance_id)
def delete_app(app_name, force, nohang=False, cleanup=True, timeout=15): if not force: ask_for_customer_confirmation_to_delete_all_application_resources( app_name) cleanup_application_versions(app_name) request_id = elasticbeanstalk.delete_application_and_envs(app_name) if cleanup: cleanup_ignore_file() fileoperations.clean_up() if not nohang: commonops.wait_for_success_events(request_id, sleep_time=5, timeout_in_minutes=timeout)
def make_cloned_env(clone_request, nohang=False, timeout=None): io.log_info('Cloning environment') env = elasticbeanstalk.get_environment( app_name=clone_request.app_name, env_name=clone_request.original_name) clone_request.version_label = env.version_label result, request_id = clone_env(clone_request) 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)
def stream_platform_logs(response, platform_name, version, timeout): arn = response['PlatformSummary']['PlatformArn'] request_id = response['ResponseMetadata']['RequestId'] # Share streamer for platform events and builder events streamer = io.get_event_streamer() builder_events = threading.Thread(target=logsops.stream_platform_logs, args=(platform_name, version, streamer, 5, None, PackerStreamFormatter())) builder_events.daemon = True # Watch events from builder logs builder_events.start() commonops.wait_for_success_events(request_id, platform_arn=arn, streamer=streamer, timeout_in_minutes=timeout or 30)
def stream_build_configuration_app_version_creation(app_name, app_version_label, build_spec): # Get the CloudWatch logs link successfully_generated = wait_for_app_version_attribute( app_name, [app_version_label], 'BuildArn', timeout=1) app_version_response = elasticbeanstalk.get_application_versions( app_name, version_labels=[app_version_label])['ApplicationVersions'] build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \ if successfully_generated else None codebuild_timeout = build_spec.timeout or 60 if build_response is not None and 'logs' in build_response['builds'][0]: log_link_text = strings['codebuild.buildlogs'].replace( '{logs_link}', build_response['builds'][0]['logs']['deepLink']) io.echo(log_link_text) io.echo( "NOTE: The CodeBuild timeout is set to {0} minutes, so this operation may take upto '{0}' minutes to complete." .format(codebuild_timeout)) else: io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs") # Wait for the success events try: # Need to lazy-import `ebcli.lib.commonops` because `pytest` is unable to load it # at module load-time using Python 2.7 and Python 3.4 from ebcli.operations import commonops commonops.wait_for_success_events(app_name=app_name, can_abort=False, request_id=None, timeout_in_minutes=codebuild_timeout, version_label=app_version_label) except ServiceError as exception: LOG.debug( "Caught service error while creating application version '{0}' " "deleting the created application version as it is useless now.". format(app_version_label)) elasticbeanstalk.delete_application_version(app_name, app_version_label) raise exception
def scale(app_name, env_name, number, confirm, timeout=None): options = [] # get environment env = elasticbeanstalk.describe_configuration_settings( app_name, env_name)['OptionSettings'] # if single instance, offer to switch to load-balanced namespace = 'aws:elasticbeanstalk:environment' setting = next((n for n in env if n["Namespace"] == namespace), None) value = setting['Value'] if value == 'SingleInstance': if not confirm: ## prompt to switch to LoadBalanced environment type io.echo(prompts['scale.switchtoloadbalance']) io.log_warning(prompts['scale.switchtoloadbalancewarn']) switch = io.get_boolean_response() if not switch: return options.append({ 'Namespace': namespace, 'OptionName': 'EnvironmentType', 'Value': 'LoadBalanced' }) # change autoscaling min AND max to number namespace = 'aws:autoscaling:asg' max = 'MaxSize' min = 'MinSize' for name in [max, min]: options.append({ 'Namespace': namespace, 'OptionName': name, 'Value': str(number) }) request_id = elasticbeanstalk.update_environment(env_name, options) commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout or 5, can_abort=True)
def display_environments(environments, timeout_in_minutes=5): """Displays Environment in birth order in a table. Creates poller, screen, and table. Displays Deploy#, Version Label, Description, Date Created, Ago. Returns the current version deployment number. """ table_header_text = strings['restore.displayheader'] poller = EnvironmentDataPoller(environments) screen = EnvironmentScreen(poller, header_text=table_header_text) _create_environment_table(screen) data = poller.get_environment_data() try: screen.start_version_screen(data, 'environments') if hasattr(screen, 'request_id') and screen.request_id: io.echo("Restoring " + screen.env_id + ".") commonops.wait_for_success_events(screen.request_id, timeout_in_minutes, can_abort=True) finally: term.return_cursor_to_normal()
def stream_build_configuration_app_version_creation(app_name, app_version_label, build_spec): # Get the CloudWatch logs link successfully_generated = wait_for_app_version_attribute(app_name, [app_version_label], 'BuildArn', timeout=1) app_version_response = elasticbeanstalk.get_application_versions(app_name, version_labels=[app_version_label])['ApplicationVersions'] build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \ if successfully_generated else None codebuild_timeout = build_spec.timeout or 60 if build_response is not None and 'logs' in build_response['builds'][0]: log_link_text = strings['codebuild.buildlogs'].replace('{logs_link}', build_response['builds'][0]['logs']['deepLink']) io.echo(log_link_text) io.echo("NOTE: The CodeBuild timeout is set to {0} minutes, so this operation may take upto '{0}' minutes to complete.".format(codebuild_timeout)) else: io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs") # Wait for the success events try: # Need to lazy-import `ebcli.lib.commonops` because `pytest` is unable to load it # at module load-time using Python 2.7 and Python 3.4 from ebcli.operations import commonops timeout_error_message = ' '.join([ 'The CodeBuild build timed out after {} minute(s).'.format(codebuild_timeout), "To increase the time limit, use the 'Timeout' option in the 'buildspec.yml' file." ]) commonops.wait_for_success_events( app_name=app_name, can_abort=False, request_id=None, timeout_error_message=timeout_error_message, timeout_in_minutes=codebuild_timeout, version_label=app_version_label ) except ServiceError as exception: LOG.debug("Caught service error while creating application version '{0}' " "deleting the created application version as it is useless now.".format(app_version_label)) elasticbeanstalk.delete_application_version(app_name, app_version_label) raise exception
def retrieve_beanstalk_logs(env_name, info_type, do_zip=False, instance_id=None): """ Obtains the set of logs from ElasticBeanstalk for the environment `env_name`. :param env_name: An Elastic Beanstalk environment name :param info_type: The type of information to request. Possible values: tail, bundle :param do_zip: Whether the information retrieved should be zipped; works only with info_type 'bundle' :param instance_id: The specific EC2 instance associated with `env_name` whose log information to retrieve :return: None """ result = elasticbeanstalk.request_environment_info(env_name, info_type) request_id = result['ResponseMetadata']['RequestId'] io.echo(prompts['logs.retrieving']) commonops.wait_for_success_events( request_id, timeout_in_minutes=2, sleep_time=1, stream_events=False ) get_logs(env_name, info_type, do_zip=do_zip, instance_id=instance_id)
def stream_build_configuration_app_version_creation(app_name, app_version_label): # Get the cloudwatch logs link successfully_generated = wait_for_app_version_attribute(app_name, [app_version_label], 'BuildArn') app_version_response = elasticbeanstalk.get_application_versions(app_name, version_labels=[app_version_label]) build_response = codebuild.batch_get_builds([app_version_response[0]['BuildArn']]) \ if successfully_generated else None if build_response is not None and 'logs' in build_response['builds'][0]: log_link_text = "You can find logs for the CodeBuild build here: {0}".format(build_response['builds'][0]['logs']['deepLink']) io.echo(log_link_text) else: io.log_warning("Could not retrieve CloudWatch link for CodeBuild logs") # Wait for the success events try: from ebcli.operations import commonops commonops.wait_for_success_events(None, timeout_in_minutes=5, can_abort=False, version_label=app_version_label) except ServiceError as ex: LOG.debug("Caught service error while creating application version '{0}' " "deleting the created applicaiton version as it is useless now.") elasticbeanstalk.delete_application_version(app_name, app_version_label) raise ex
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 create_platform_version( version, major_increment, minor_increment, patch_increment, instance_type, vpc = None, staged=False, timeout=None): platform_name = fileoperations.get_platform_name() instance_profile = fileoperations.get_instance_profile(None) key_name = commonops.get_default_keyname() if version is None: version = _get_latest_version(platform_name=platform_name, owner=Constants.OWNED_BY_SELF, ignored_states=[]) if version is None: version = '1.0.0' else: major, minor, patch = version.split('.', 3) if major_increment: major = str(int(major) + 1) minor = '0' patch = '0' if minor_increment: minor = str(int(minor) + 1) patch = '0' if patch_increment or not(major_increment or minor_increment): patch = str(int(patch) + 1) version = "%s.%s.%s" % (major, minor, patch) if not VALID_PLATFORM_VERSION_FORMAT.match(version): raise InvalidPlatformVersionError(strings['exit.invalidversion']) cwd = os.getcwd() fileoperations._traverse_to_project_root() try: if heuristics.directory_is_empty(): raise PlatformWorkspaceEmptyError(strings['exit.platformworkspaceempty']) finally: os.chdir(cwd) if not heuristics.has_platform_definition_file(): raise PlatformWorkspaceEmptyError(strings['exit.no_pdf_file']) source_control = SourceControl.get_source_control() if source_control.untracked_changes_exist(): io.log_warning(strings['sc.unstagedchanges']) version_label = source_control.get_version_label() if staged: # Make a unique version label timestamp = datetime.now().strftime("%y%m%d_%H%M%S") version_label = version_label + '-stage-' + timestamp file_descriptor, original_platform_yaml = tempfile.mkstemp() os.close(file_descriptor) copyfile('platform.yaml', original_platform_yaml) s3_bucket = None s3_key = None try: # Add option settings to platform.yaml _enable_healthd() s3_bucket, s3_key = get_app_version_s3_location(platform_name, version_label) # Create zip file if the application version doesn't exist if s3_bucket is None and s3_key is None: file_name, file_path = _zip_up_project(version_label, source_control, staged=staged) else: file_name = None file_path = None finally: # Restore original platform.yaml move(original_platform_yaml, 'platform.yaml') # Use existing bucket if it exists bucket = elasticbeanstalk.get_storage_location() if s3_bucket is None else s3_bucket # Use existing key if it exists key = platform_name + '/' + file_name if s3_key is None else s3_key try: s3.get_object_info(bucket, key) io.log_info('S3 Object already exists. Skipping upload.') except NotFoundError: io.log_info('Uploading archive to s3 location: ' + key) s3.upload_platform_version(bucket, key, file_path) # Just deletes the local zip fileoperations.delete_app_versions() io.log_info('Creating Platform Version ' + version_label) response = elasticbeanstalk.create_platform_version( platform_name, version, bucket, key, instance_profile, key_name, instance_type, vpc) # TODO: Enable this once the API returns the name of the environment associated with a # CreatePlatformRequest, and remove hard coded value. There is currently only one type # of platform builder, we may support additional builders in the future. #environment_name = response['PlatformSummary']['EnvironmentName'] environment_name = 'eb-custom-platform-builder-packer' io.echo(colored( strings['platformbuildercreation.info'].format(environment_name), attrs=['reverse'])) fileoperations.update_platform_version(version) commonops.set_environment_for_current_branch(environment_name) arn = response['PlatformSummary']['PlatformArn'] request_id = response['ResponseMetadata']['RequestId'] if not timeout: timeout = 30 # Share streamer for platform events and builder events streamer = io.get_event_streamer() builder_events = threading.Thread( target=logsops.stream_platform_logs, args=(platform_name, version, streamer, 5, None, PackerStreamFormatter())) builder_events.daemon = True # Watch events from builder logs builder_events.start() commonops.wait_for_success_events( request_id, platform_arn=arn, streamer=streamer, timeout_in_minutes=timeout )
def create_platform_version(version, major_increment, minor_increment, patch_increment, instance_type, vpc=None, staged=False, timeout=None): platform_name = fileoperations.get_platform_name() instance_profile = fileoperations.get_instance_profile(None) key_name = commonops.get_default_keyname() if version is None: version = _get_latest_version(platform_name=platform_name, owner=Constants.OWNED_BY_SELF, ignored_states=[]) if version is None: version = '1.0.0' else: major, minor, patch = version.split('.', 3) if major_increment: major = str(int(major) + 1) minor = '0' patch = '0' if minor_increment: minor = str(int(minor) + 1) patch = '0' if patch_increment or not (major_increment or minor_increment): patch = str(int(patch) + 1) version = "%s.%s.%s" % (major, minor, patch) if not VALID_PLATFORM_VERSION_FORMAT.match(version): raise InvalidPlatformVersionError(strings['exit.invalidversion']) cwd = os.getcwd() fileoperations._traverse_to_project_root() try: if heuristics.directory_is_empty(): raise PlatformWorkspaceEmptyError( strings['exit.platformworkspaceempty']) finally: os.chdir(cwd) if not heuristics.has_platform_definition_file(): raise PlatformWorkspaceEmptyError(strings['exit.no_pdf_file']) source_control = SourceControl.get_source_control() if source_control.untracked_changes_exist(): io.log_warning(strings['sc.unstagedchanges']) version_label = source_control.get_version_label() if staged: # Make a unique version label timestamp = datetime.now().strftime("%y%m%d_%H%M%S") version_label = version_label + '-stage-' + timestamp file_descriptor, original_platform_yaml = tempfile.mkstemp() os.close(file_descriptor) copyfile('platform.yaml', original_platform_yaml) try: # Add option settings to platform.yaml _enable_healthd() s3_bucket, s3_key = get_app_version_s3_location( platform_name, version_label) # Create zip file if the application version doesn't exist if s3_bucket is None and s3_key is None: file_name, file_path = _zip_up_project(version_label, source_control, staged=staged) else: file_name = None file_path = None finally: # Restore original platform.yaml move(original_platform_yaml, 'platform.yaml') # Use existing bucket if it exists bucket = elasticbeanstalk.get_storage_location( ) if s3_bucket is None else s3_bucket # Use existing key if it exists key = platform_name + '/' + file_name if s3_key is None else s3_key try: s3.get_object_info(bucket, key) io.log_info('S3 Object already exists. Skipping upload.') except NotFoundError: io.log_info('Uploading archive to s3 location: ' + key) s3.upload_platform_version(bucket, key, file_path) # Just deletes the local zip fileoperations.delete_app_versions() io.log_info('Creating Platform Version ' + version_label) response = elasticbeanstalk.create_platform_version( platform_name, version, bucket, key, instance_profile, key_name, instance_type, vpc) # TODO: Enable this once the API returns the name of the environment associated with a # CreatePlatformRequest, and remove hard coded value. There is currently only one type # of platform builder, we may support additional builders in the future. #environment_name = response['PlatformSummary']['EnvironmentName'] environment_name = 'eb-custom-platform-builder-packer' io.echo( colored( strings['platformbuildercreation.info'].format(environment_name), attrs=['reverse'])) fileoperations.update_platform_version(version) commonops.set_environment_for_current_branch(environment_name) arn = response['PlatformSummary']['PlatformArn'] request_id = response['ResponseMetadata']['RequestId'] if not timeout: timeout = 30 # Share streamer for platform events and builder events streamer = io.get_event_streamer() builder_events = threading.Thread(target=logsops.stream_platform_logs, args=(platform_name, version, streamer, 5, None, PackerStreamFormatter())) builder_events.daemon = True # Watch events from builder logs builder_events.start() commonops.wait_for_success_events(request_id, platform_arn=arn, streamer=streamer, timeout_in_minutes=timeout)
def cname_swap(source_env, dest_env): request_id = elasticbeanstalk.swap_environment_cnames(source_env, dest_env) commonops.wait_for_success_events(request_id, timeout_in_minutes=1, sleep_time=2)
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 deploy(app_name, env_name, version, label, message, group_name=None, process_app_versions=False, staged=False, timeout=5, source=None): region_name = aws.get_region_name() # Parse and get Build Configuration from BuildSpec if it exists build_config = None if fileoperations.build_spec_exists() and version is None: build_config = fileoperations.get_build_configuration() LOG.debug("Retrieved build configuration from buildspec: {0}".format( build_config.__str__())) io.log_info('Deploying code to ' + env_name + " in region " + region_name) if version: app_version_label = version elif source is not None: app_version_label = commonops.create_app_version_from_source( app_name, source, process=process_app_versions, label=label, message=message, build_config=build_config) io.echo("Starting environment deployment via specified source") process_app_versions = True elif gitops.git_management_enabled() and not staged: app_version_label = commonops.create_codecommit_app_version( app_name, process=process_app_versions, label=label, message=message, build_config=build_config) io.echo("Starting environment deployment via CodeCommit") process_app_versions = True else: # Create app version app_version_label = commonops.create_app_version( app_name, process=process_app_versions, label=label, message=message, staged=staged, build_config=build_config) if build_config is not None: buildspecops.stream_build_configuration_app_version_creation( app_name, app_version_label, build_config) elif process_app_versions is True: success = commonops.wait_for_processed_app_versions( app_name, [app_version_label], timeout=timeout or 5) if not success: return # swap env to new app version request_id = elasticbeanstalk.update_env_application_version( env_name, app_version_label, group_name) commonops.wait_for_success_events(request_id, timeout_in_minutes=timeout, can_abort=True, env_name=env_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)