Exemplo n.º 1
0
    def create_ecr_image(resources_info: Dict, supervisor_version: str) -> str:
        """Creates an ECR image using the user provided image adding the supervisor tools."""
        # If the user set an already prepared image return the image name
        image_name = ContainerImage._ecr_image_name_prepared(
            resources_info.get('lambda').get('container'))
        if image_name:
            return image_name

        tmp_folder = FileUtils.create_tmp_dir()

        # Create function config file
        FileUtils.write_yaml(
            FileUtils.join_paths(tmp_folder.name, "function_config.yaml"),
            create_function_config(resources_info))

        init_script_path = resources_info.get('lambda').get('init_script')
        # Copy the init script defined by the user to the payload folder
        if init_script_path:
            FileUtils.copy_file(
                init_script_path,
                FileUtils.join_paths(
                    tmp_folder.name,
                    FileUtils.get_file_name(init_script_path)))

        # Get supervisor zip
        supervisor_zip_path = ContainerImage.get_supervisor_zip(
            resources_info, supervisor_version)
        # Unzip the supervisor file to the temp file
        FileUtils.unzip_folder(supervisor_zip_path, tmp_folder.name)

        # Create dockerfile to generate the new ECR image
        FileUtils.create_file_with_content(
            "%s/Dockerfile" % tmp_folder.name,
            ContainerImage._create_dockerfile_ecr_image(
                resources_info.get('lambda')))

        # Create the ECR Repo and get the image uri
        ecr_cli = ECR(resources_info)
        repo_name = resources_info.get('lambda').get('name')
        ecr_image = ecr_cli.get_repository_uri(repo_name)
        if not ecr_image:
            logger.info('Creating ECR repository: %s' % repo_name)
            ecr_image = ecr_cli.create_repository(repo_name)

        # Build and push the image to the ECR repo
        platform = None
        arch = resources_info.get('lambda').get('architectures', ['x86_64'])[0]
        if arch == 'arm64':
            platform = 'linux/arm64'
        return ContainerImage._build_push_ecr_image(
            tmp_folder.name, ecr_image, platform,
            ecr_cli.get_authorization_token())
Exemplo n.º 2
0
 def _set_fdl(self):
     fdl = StrUtils.dict_to_base64_string(create_function_config(self.resources_info))
     self.function['environment']['Variables']['FDL'] = fdl
Exemplo n.º 3
0
 def _get_config_file(self) -> str:
     cfg_file = ''
     config = create_function_config(self.resources_info)
     yaml_str = yaml.safe_dump(config)
     cfg_file = StrUtils.utf8_to_base64_string(yaml_str)
     return cfg_file