예제 #1
0
    def do_command(self):
        commonops.raise_if_inside_platform_workspace()

        interactive = self.app.pargs.interactive
        region_name = self.app.pargs.region
        noverify = self.app.pargs.no_verify_ssl
        keyname = self.app.pargs.keyname
        profile = self.app.pargs.profile
        platform = self.app.pargs.platform
        source = self.app.pargs.source
        app_name = self.app.pargs.application_name
        modules = self.app.pargs.modules
        force_non_interactive = _customer_is_avoiding_interactive_flow(
            self.app.pargs)
        tags = self.app.pargs.tags

        # The user specifies directories to initialize
        if modules and len(modules) > 0:
            self.initialize_multiple_directories(modules, region_name,
                                                 interactive,
                                                 force_non_interactive,
                                                 keyname, profile, noverify,
                                                 platform)
            return

        fileoperations.touch_config_folder()
        region_name = commonops.set_region_for_application(
            interactive, region_name, force_non_interactive, platform)
        commonops.set_up_credentials(profile, region_name, interactive)
        app_name = get_app_name(app_name, interactive, force_non_interactive)
        default_env = set_default_env(interactive, force_non_interactive)
        tags = tagops.get_and_validate_tags(tags)

        platform_arn, keyname_of_existing_application = create_app_or_use_existing_one(
            app_name, default_env, tags)
        platform = _determine_platform(customer_provided_platform=platform,
                                       existing_app_platform=platform_arn,
                                       force_interactive=interactive
                                       and not force_non_interactive)

        handle_buildspec_image(platform, force_non_interactive)

        prompt_codecommit = should_prompt_customer_to_opt_into_codecommit(
            force_non_interactive, region_name, source)
        repository, branch = None, None
        if prompt_codecommit:
            repository, branch = configure_codecommit(source)
        initializeops.setup(app_name,
                            region_name,
                            platform,
                            dir_path=None,
                            repository=repository,
                            branch=branch)
        configure_keyname(platform, keyname, keyname_of_existing_application,
                          interactive, force_non_interactive)
        fileoperations.write_config_setting('global', 'include_git_submodules',
                                            True)
        if noverify:
            fileoperations.write_config_setting('global', 'no-verify-ssl',
                                                True)
예제 #2
0
    def initialize_multiple_directories(
            self,
            modules,
            region,
            interactive,
            force_non_interactive,
            keyname,
            profile,
            noverify,
            platform
    ):
        application_created = False
        app_name = None
        cwd = os.getcwd()
        for module in modules:
            if os.path.exists(module) and os.path.isdir(module):
                os.chdir(module)
                fileoperations.touch_config_folder()

                # Region should be set once for all modules
                region = region or commonops.set_region_for_application(interactive, region, force_non_interactive)
                commonops.set_up_credentials(profile, region, interactive)

                # App name should be set once for all modules
                if not app_name:
                    # Switching back to the root dir will suggest the root dir name
                    # as the application name
                    os.chdir(cwd)
                    app_name = get_app_name(None, interactive, force_non_interactive)
                    os.chdir(module)

                if noverify:
                    fileoperations.write_config_setting('global', 'no-verify-ssl', True)

                default_env = '/ni' if force_non_interactive else None

                if not application_created:
                    platform_arn, keyname_of_existing_application = commonops.create_app(
                        app_name,
                        default_env=default_env
                    )
                    application_created = True
                else:
                    platform_arn, keyname_of_existing_application = commonops.pull_down_app_info(
                        app_name,
                        default_env=default_env
                    )
                io.echo('\n--- Configuring module: {0} ---'.format(module))
                module_platform = _determine_platform(
                    customer_provided_platform=platform,
                    existing_app_platform=platform_arn,
                    force_interactive=interactive)

                initializeops.setup(app_name, region, module_platform)
                configure_keyname(module_platform, keyname, keyname_of_existing_application, interactive, force_non_interactive)
                os.chdir(cwd)
예제 #3
0
    def initialize_multiple_directories(self, modules, region, interactive,
                                        force_non_interactive, keyname,
                                        profile, noverify, platform):
        application_created = False
        app_name = None
        cwd = os.getcwd()
        for module in modules:
            if os.path.exists(module) and os.path.isdir(module):
                os.chdir(module)
                fileoperations.touch_config_folder()

                # Region should be set once for all modules
                region = region or commonops.set_region_for_application(
                    interactive, region, force_non_interactive)
                commonops.set_up_credentials(profile, region, interactive)

                # App name should be set once for all modules
                if not app_name:
                    # Switching back to the root dir will suggest the root dir name
                    # as the application name
                    os.chdir(cwd)
                    app_name = get_app_name(None, interactive,
                                            force_non_interactive)
                    os.chdir(module)

                if noverify:
                    fileoperations.write_config_setting(
                        'global', 'no-verify-ssl', True)

                default_env = '/ni' if force_non_interactive else None

                if not application_created:
                    sstack, keyname_of_existing_application = commonops.create_app(
                        app_name, default_env=default_env)
                    application_created = True
                else:
                    sstack, keyname_of_existing_application = commonops.pull_down_app_info(
                        app_name, default_env=default_env)
                solution = get_solution_stack(platform, sstack, interactive)
                io.echo('\n--- Configuring module: {0} ---'.format(module))

                solution = solution or sstack

                if not solution and fileoperations.env_yaml_exists():
                    solution = extract_solution_stack_from_env_yaml()
                    if solution:
                        io.echo(strings['init.usingenvyamlplatform'].replace(
                            '{platform}', solution))
                solution = solution or solution_stack_ops.get_solution_stack_from_customer(
                )
                initializeops.setup(app_name, region, solution)
                configure_keyname(solution, keyname,
                                  keyname_of_existing_application, interactive,
                                  force_non_interactive)
                os.chdir(cwd)