def compose_multiple_apps(self): module_names = self.app.pargs.modules group = self.app.pargs.env_group_suffix or 'dev' nohang = self.app.pargs.nohang timeout = self.app.pargs.timeout root_dir = os.getcwd() version_labels = [] grouped_env_names = [] app_name = None for module in module_names: if not os.path.isdir(os.path.join(root_dir, module)): io.log_warning(strings['create.appdoesntexist'].replace( '{app_name}', module)) continue os.chdir(os.path.join(root_dir, module)) if not fileoperations.env_yaml_exists(): io.log_warning(strings['compose.noenvyaml'].replace( '{module}', module)) continue io.echo( '--- Creating application version for module: {0} ---'.format( module)) # Re-run hooks to get values from .elasticbeanstalk folders of modules hooks.set_region(None) hooks.set_ssl(None) hooks.set_profile(None) commonops.set_group_suffix_for_current_branch(group) if not app_name: app_name = self.get_app_name() process_app_version = fileoperations.env_yaml_exists() version_label = commonops.create_app_version( app_name, process=process_app_version) version_labels.append(version_label) environment_name = fileoperations.get_env_name_from_env_yaml() if environment_name is not None: commonops.set_environment_for_current_branch( environment_name.replace('+', '-{0}'.format(group))) grouped_env_names.append( environment_name.replace('+', '-{0}'.format(group))) os.chdir(root_dir) if len(version_labels) > 0: composeops.compose(app_name, version_labels, grouped_env_names, group, nohang, timeout) else: io.log_warning(strings['compose.novalidmodules'])
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() 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: 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 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) 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 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 compose_deploy(self): app_name = None modules = self.app.pargs.modules group_name = self.app.pargs.env_group_suffix env_names = [] stages_version_labels = {} stages_env_names = {} top_dir = getcwd() for module in modules: if not path.isdir(path.join(top_dir, module)): io.log_error(strings['deploy.notadirectory'].replace('{module}', module)) continue chdir(path.join(top_dir, module)) if not group_name: group_name = commonops.get_current_branch_group_suffix() if group_name not in stages_version_labels.keys(): stages_version_labels[group_name] = [] stages_env_names[group_name] = [] if not app_name: app_name = self.get_app_name() io.echo('--- Creating application version for module: {0} ---'.format(module)) hooks.set_region(None) hooks.set_ssl(None) hooks.set_profile(None) if not app_name: app_name = self.get_app_name() process_app_version = fileoperations.env_yaml_exists() version_label = commonops.create_app_version(app_name, process=process_app_version) stages_version_labels[group_name].append(version_label) environment_name = fileoperations.get_env_name_from_env_yaml() if environment_name is not None: commonops.set_environment_for_current_branch(environment_name. replace('+', '-{0}'. format(group_name))) env_name = commonops.get_current_branch_environment() stages_env_names[group_name].append(env_name) env_names.append(env_name) else: io.echo(strings['deploy.noenvname'].replace('{module}', module)) stages_version_labels[group_name] = [ v for v in stages_version_labels[group_name] if v != version_label ] chdir(top_dir) if len(stages_version_labels) > 0: for stage in stages_version_labels.keys(): request_id = composeops.compose_no_events(app_name, stages_version_labels[stage], group_name=stage) if request_id is None: io.log_error("Unable to compose modules.") return commonops.wait_for_compose_events(request_id, app_name, env_names, self.timeout) else: io.log_warning(strings['compose.novalidmodules'])
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)