def _get_build_graph(self): """ Converts list of functions and layers into a build graph, where we can iterate on each unique build and trigger build :return: BuildGraph, which represents list of unique build definitions """ build_graph = BuildGraph(self._build_dir) functions = self._resources_to_build.functions layers = self._resources_to_build.layers for function in functions: function_build_details = FunctionBuildDefinition( function.runtime, function.codeuri, function.packagetype, function.metadata) build_graph.put_function_build_definition(function_build_details, function) for layer in layers: layer_build_details = LayerBuildDefinition( layer.name, layer.codeuri, layer.build_method, layer.compatible_runtimes) build_graph.put_layer_build_definition(layer_build_details, layer) build_graph.clean_redundant_definitions_and_update( not self._is_building_specific_resource) return build_graph
def test_should_instantiate_first_time_and_update(self): with osutils.mkdir_temp() as temp_base_dir: build_dir = Path(temp_base_dir, ".aws-sam", "build") build_dir.mkdir(parents=True) # create a build graph and persist it build_graph1 = BuildGraph(str(build_dir)) build_definition1 = FunctionBuildDefinition( TestBuildGraph.RUNTIME, TestBuildGraph.CODEURI, TestBuildGraph.ZIP, TestBuildGraph.METADATA, TestBuildGraph.SOURCE_MD5, ) function1 = generate_function(runtime=TestBuildGraph.RUNTIME, codeuri=TestBuildGraph.CODEURI, metadata=TestBuildGraph.METADATA) build_graph1.put_function_build_definition(build_definition1, function1) build_graph1.clean_redundant_definitions_and_update(True) # read previously persisted graph and compare build_graph2 = BuildGraph(str(build_dir)) self.assertEqual( len(build_graph1.get_function_build_definitions()), len(build_graph2.get_function_build_definitions())) self.assertEqual( list(build_graph1.get_function_build_definitions())[0], list(build_graph2.get_function_build_definitions())[0], )
def test_should_instantiate_first_time(self): with osutils.mkdir_temp() as temp_base_dir: build_dir = Path(temp_base_dir, ".aws-sam", "build") build_dir.mkdir(parents=True) build_graph1 = BuildGraph(str(build_dir.resolve())) build_graph1.clean_redundant_definitions_and_update(True) build_graph2 = BuildGraph(str(build_dir.resolve())) self.assertEqual(build_graph1.get_function_build_definitions(), build_graph2.get_function_build_definitions())
def _get_build_graph(self, inline_env_vars: Optional[Dict] = None, env_vars_file: Optional[str] = None) -> BuildGraph: """ Converts list of functions and layers into a build graph, where we can iterate on each unique build and trigger build :return: BuildGraph, which represents list of unique build definitions """ build_graph = BuildGraph(self._build_dir) functions = self._resources_to_build.functions layers = self._resources_to_build.layers file_env_vars = {} if env_vars_file: try: with open(env_vars_file, "r", encoding="utf-8") as fp: file_env_vars = json.load(fp) except Exception as ex: raise IOError( "Could not read environment variables overrides from file {}: {}" .format(env_vars_file, str(ex))) from ex for function in functions: container_env_vars = self._make_env_vars(function, file_env_vars, inline_env_vars) function_build_details = FunctionBuildDefinition( function.runtime, function.codeuri, function.packagetype, function.metadata, env_vars=container_env_vars) build_graph.put_function_build_definition(function_build_details, function) for layer in layers: container_env_vars = self._make_env_vars(layer, file_env_vars, inline_env_vars) layer_build_details = LayerBuildDefinition( layer.name, layer.codeuri, layer.build_method, layer.compatible_runtimes, env_vars=container_env_vars) build_graph.put_layer_build_definition(layer_build_details, layer) build_graph.clean_redundant_definitions_and_update( not self._is_building_specific_resource) return build_graph