예제 #1
0
    def resources_to_build(self):
        """
        Function return resources that should be build by current build command. This function considers
        Lambda Functions and Layers with build method as buildable resources.
        Returns
        -------
        ResourcesToBuildCollector
        """
        result = ResourcesToBuildCollector()
        if self._resource_identifier:
            self._collect_single_function_and_dependent_layers(
                self._resource_identifier, result)
            self._collect_single_buildable_layer(self._resource_identifier,
                                                 result)

            if not result.functions and not result.layers:
                all_resources = [
                    f.name for f in self._function_provider.get_all()
                ]
                all_resources.extend(
                    [l.name for l in self._layer_provider.get_all()])

                available_resource_message = f"{self._resource_identifier} not found. Possible options in your " \
                                             f"template: {all_resources}"
                LOG.info(available_resource_message)
                raise ResourceNotFound(
                    f"Unable to find a function or layer with name '{self._resource_identifier}'"
                )
            return result
        result.add_functions(self._function_provider.get_all())
        result.add_layers([
            l for l in self._layer_provider.get_all()
            if l.build_method is not None
        ])
        return result
예제 #2
0
 def setUp(self):
     self.layer1 = Mock()
     self.layer2 = Mock()
     self.container_manager = Mock()
     resources_to_build_collector = ResourcesToBuildCollector()
     resources_to_build_collector.add_layers([self.layer1, self.layer2])
     self.builder = ApplicationBuilder(resources_to_build_collector, "builddir", "basedir")
예제 #3
0
    def setUp(self):
        self.func1 = Mock()
        self.func2 = Mock()
        self.layer1 = Mock()
        self.layer2 = Mock()

        resources_to_build_collector = ResourcesToBuildCollector()
        resources_to_build_collector.add_functions([self.func1, self.func2])
        resources_to_build_collector.add_layers([self.layer1, self.layer2])
        self.builder = ApplicationBuilder(resources_to_build_collector, "builddir", "basedir")
예제 #4
0
    def _collect_single_function_and_dependent_layers(
        self, resource_identifier: str, resource_collector: ResourcesToBuildCollector
    ) -> None:
        """
        Populate resource_collector with function with provided identifier and all layers that function need to be
        build in resource_collector
        Parameters
        ----------
        resource_collector: Collector that will be populated with resources.
        """
        function = self.function_provider.get(resource_identifier)
        if not function:
            # No function found
            return

        resource_collector.add_function(function)
        resource_collector.add_layers([l for l in function.layers if l.build_method is not None])
예제 #5
0
    def setUp(self):
        self.func1 = Mock()
        self.func1.packagetype = ZIP
        self.func1.name = "function_name1"
        self.func2 = Mock()
        self.func2.packagetype = ZIP
        self.func2.name = "function_name2"
        self.imageFunc1 = Mock()
        self.imageFunc1.name = "function_name3"

        self.layer1 = Mock()
        self.layer2 = Mock()

        self.imageFunc1.packagetype = IMAGE
        self.layer1.build_method = "build_method"
        self.layer2.build_method = "build_method"

        resources_to_build_collector = ResourcesToBuildCollector()
        resources_to_build_collector.add_functions(
            [self.func1, self.func2, self.imageFunc1])
        resources_to_build_collector.add_layers([self.layer1, self.layer2])
        self.builder = ApplicationBuilder(resources_to_build_collector,
                                          "builddir", "basedir", "cachedir")