Beispiel #1
0
    def create_data_dir(self, root_dir: str) -> None:
        """Create data to be pushed to bucket used by cloudformation for resources."""
        # Create directory specific to that lambda
        package_dir = os.path.join(root_dir, name_to_id(self.name), "package")

        # Install the requirements
        if self.requirement_file is not None:
            p = Run(
                python_script("pip")
                + ["install", f"--target={package_dir}", "-r", self.requirement_file],
                output=None,
            )
            assert p.status == 0

        # Copy user code
        self.populate_package_dir(package_dir=package_dir)

        # Create an archive
        create_archive(
            f"{self.name}_lambda.zip",
            from_dir=package_dir,
            dest=root_dir,
            no_root_dir=True,
        )

        # Remove temporary directory
        rm(package_dir, recursive=True)
Beispiel #2
0
    def create_package(self, anod_instance: Anod) -> str:
        """Generate a package as a ZIP archive.

        :param anod_instance: the Anod instance that creates the package
        :return: the full path to the generated archive
        """
        pkg_name = self.pkg_name(anod_instance)
        pkg_path = self.pkg_path(anod_instance)

        # Reset binary dir
        rm(anod_instance.build_space.binary_dir, True)
        mkdir(anod_instance.build_space.binary_dir)

        # Create the zip archive
        create_archive(
            filename=os.path.basename(pkg_path),
            from_dir=anod_instance.build_space.pkg_dir,
            dest=os.path.dirname(pkg_path),
            from_dir_rename=pkg_name,
        )
        return pkg_path