From ed6cf43ee588d4703b029e61a866fc640fc4d7d9 Mon Sep 17 00:00:00 2001 From: Ke Deng Date: Thu, 11 May 2023 10:24:31 -0700 Subject: [PATCH 1/5] add func architecture and unit tests --- .../workflows/dotnet_clipackage/actions.py | 32 ++++++++++++++++--- .../dotnet_clipackage/test_actions.py | 14 ++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 5a3907a32..8a6665685 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -7,7 +7,7 @@ import threading from aws_lambda_builders.actions import ActionFailedError, BaseAction, Purpose -from aws_lambda_builders.architecture import ARM64 +from aws_lambda_builders.architecture import ARM64, X86_64 from aws_lambda_builders.workflow import BuildMode from .dotnetcli import DotnetCLIExecutionError @@ -62,13 +62,35 @@ def execute(self): class RunPackageAction(BaseAction): """ A Lambda Builder Action which builds the .NET Core project using the Amazon.Lambda.Tools .NET Core Global Tool + + :param source_dir: str + Path to a folder containing the source code + + :param subprocess_dotnet: + An instance of the dotnet process wrapper + + :param artifacts_dir: str + Path to a folder where the built artifacts should be placed + + :param options: + Dictionary of options ot pass to build action + + :param mode: str + Mode the build should produce + + :param architecture: str + Architecture to build for. Default value is X86_64 which is consistent with Amazon Lambda Tools + + :param os_utils: + Optional, OS utils + """ NAME = "RunPackageAction" DESCRIPTION = "Execute the `dotnet lambda package` command." PURPOSE = Purpose.COMPILE_SOURCE - def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=None, os_utils=None): + def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=X86_64, os_utils=None): super(RunPackageAction, self).__init__() self.source_dir = source_dir self.subprocess_dotnet = subprocess_dotnet @@ -90,9 +112,9 @@ def execute(self): "package", "--output-package", zipfullpath, - # Specify the architecture with the --runtime MSBuild parameter - "--msbuild-parameters", - "--runtime " + self._get_runtime(), + # pass function architecture to Amazon Lambda Tools. + "--function-architecture", + self.architecture, ] if self.mode and self.mode.lower() == BuildMode.DEBUG: diff --git a/tests/unit/workflows/dotnet_clipackage/test_actions.py b/tests/unit/workflows/dotnet_clipackage/test_actions.py index 34045d8cb..50596ff85 100644 --- a/tests/unit/workflows/dotnet_clipackage/test_actions.py +++ b/tests/unit/workflows/dotnet_clipackage/test_actions.py @@ -89,7 +89,7 @@ def test_build_package(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], + ["lambda", "package", "--output-package", zip_path, "--function-architecture", X86_64], cwd="/source_dir", ) @@ -106,7 +106,7 @@ def test_build_package_x86(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], + ["lambda", "package", "--output-package", zip_path, "--function-architecture", X86_64], cwd="/source_dir", ) @@ -123,7 +123,7 @@ def test_build_package_arm64(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-arm64"], + ["lambda", "package", "--output-package", zip_path, "--function-architecture", ARM64], cwd="/source_dir", ) @@ -144,8 +144,8 @@ def test_build_package_arguments(self): "package", "--output-package", zip_path, - "--msbuild-parameters", - "--runtime linux-x64", + "--function-architecture", + X86_64, "--framework", "netcoreapp2.1", ], @@ -180,8 +180,8 @@ def test_debug_configuration_set(self): "package", "--output-package", zip_path, - "--msbuild-parameters", - "--runtime linux-x64", + "--function-architecture", + X86_64, "--configuration", "Debug", ], From 2b120d88a6c9e50f83bb7bbbbffe3c3615b0ef93 Mon Sep 17 00:00:00 2001 From: Ke Deng Date: Thu, 11 May 2023 11:57:25 -0700 Subject: [PATCH 2/5] Update aws-lambda-tools-defaults.json in test project self contained is not necessary for dotnet6 functions, since the runtime has been provided by Lambda --- .../testdata/CustomRuntime6/aws-lambda-tools-defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json b/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json index 9c44274ae..fe5e57fb3 100644 --- a/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json +++ b/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json @@ -12,5 +12,5 @@ "function-memory-size": 256, "function-timeout": 30, "function-handler": "bootstrap", - "msbuild-parameters": "--self-contained true" + "msbuild-parameters": "--self-contained false" } \ No newline at end of file From cfa00be08650030ba45284574c78bc445688d10c Mon Sep 17 00:00:00 2001 From: Ke Deng Date: Thu, 11 May 2023 15:51:02 -0700 Subject: [PATCH 3/5] Revert "Update aws-lambda-tools-defaults.json in test project" This reverts commit 2b120d88a6c9e50f83bb7bbbbffe3c3615b0ef93. --- .../testdata/CustomRuntime6/aws-lambda-tools-defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json b/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json index fe5e57fb3..9c44274ae 100644 --- a/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json +++ b/tests/integration/workflows/dotnet_clipackage/testdata/CustomRuntime6/aws-lambda-tools-defaults.json @@ -12,5 +12,5 @@ "function-memory-size": 256, "function-timeout": 30, "function-handler": "bootstrap", - "msbuild-parameters": "--self-contained false" + "msbuild-parameters": "--self-contained true" } \ No newline at end of file From 0785847b11d14a7fc71b939dad7005fe38dbabda Mon Sep 17 00:00:00 2001 From: Ke Deng Date: Thu, 11 May 2023 15:54:00 -0700 Subject: [PATCH 4/5] Revert "add func architecture and unit tests" This reverts commit ed6cf43ee588d4703b029e61a866fc640fc4d7d9. --- .../workflows/dotnet_clipackage/actions.py | 32 +++---------------- .../dotnet_clipackage/test_actions.py | 14 ++++---- 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 8a6665685..5a3907a32 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -7,7 +7,7 @@ import threading from aws_lambda_builders.actions import ActionFailedError, BaseAction, Purpose -from aws_lambda_builders.architecture import ARM64, X86_64 +from aws_lambda_builders.architecture import ARM64 from aws_lambda_builders.workflow import BuildMode from .dotnetcli import DotnetCLIExecutionError @@ -62,35 +62,13 @@ def execute(self): class RunPackageAction(BaseAction): """ A Lambda Builder Action which builds the .NET Core project using the Amazon.Lambda.Tools .NET Core Global Tool - - :param source_dir: str - Path to a folder containing the source code - - :param subprocess_dotnet: - An instance of the dotnet process wrapper - - :param artifacts_dir: str - Path to a folder where the built artifacts should be placed - - :param options: - Dictionary of options ot pass to build action - - :param mode: str - Mode the build should produce - - :param architecture: str - Architecture to build for. Default value is X86_64 which is consistent with Amazon Lambda Tools - - :param os_utils: - Optional, OS utils - """ NAME = "RunPackageAction" DESCRIPTION = "Execute the `dotnet lambda package` command." PURPOSE = Purpose.COMPILE_SOURCE - def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=X86_64, os_utils=None): + def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=None, os_utils=None): super(RunPackageAction, self).__init__() self.source_dir = source_dir self.subprocess_dotnet = subprocess_dotnet @@ -112,9 +90,9 @@ def execute(self): "package", "--output-package", zipfullpath, - # pass function architecture to Amazon Lambda Tools. - "--function-architecture", - self.architecture, + # Specify the architecture with the --runtime MSBuild parameter + "--msbuild-parameters", + "--runtime " + self._get_runtime(), ] if self.mode and self.mode.lower() == BuildMode.DEBUG: diff --git a/tests/unit/workflows/dotnet_clipackage/test_actions.py b/tests/unit/workflows/dotnet_clipackage/test_actions.py index 50596ff85..34045d8cb 100644 --- a/tests/unit/workflows/dotnet_clipackage/test_actions.py +++ b/tests/unit/workflows/dotnet_clipackage/test_actions.py @@ -89,7 +89,7 @@ def test_build_package(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--function-architecture", X86_64], + ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], cwd="/source_dir", ) @@ -106,7 +106,7 @@ def test_build_package_x86(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--function-architecture", X86_64], + ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], cwd="/source_dir", ) @@ -123,7 +123,7 @@ def test_build_package_arm64(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--function-architecture", ARM64], + ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-arm64"], cwd="/source_dir", ) @@ -144,8 +144,8 @@ def test_build_package_arguments(self): "package", "--output-package", zip_path, - "--function-architecture", - X86_64, + "--msbuild-parameters", + "--runtime linux-x64", "--framework", "netcoreapp2.1", ], @@ -180,8 +180,8 @@ def test_debug_configuration_set(self): "package", "--output-package", zip_path, - "--function-architecture", - X86_64, + "--msbuild-parameters", + "--runtime linux-x64", "--configuration", "Debug", ], From 86553dca1e2d0a68acc862b38e5ab213e3896335 Mon Sep 17 00:00:00 2001 From: Ke Deng Date: Thu, 11 May 2023 16:06:20 -0700 Subject: [PATCH 5/5] provide function architecture --- .../workflows/dotnet_clipackage/actions.py | 29 ++++++++++++++- .../dotnet_clipackage/test_actions.py | 37 +++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 5a3907a32..2f9f31601 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -7,7 +7,7 @@ import threading from aws_lambda_builders.actions import ActionFailedError, BaseAction, Purpose -from aws_lambda_builders.architecture import ARM64 +from aws_lambda_builders.architecture import ARM64, X86_64 from aws_lambda_builders.workflow import BuildMode from .dotnetcli import DotnetCLIExecutionError @@ -62,13 +62,35 @@ def execute(self): class RunPackageAction(BaseAction): """ A Lambda Builder Action which builds the .NET Core project using the Amazon.Lambda.Tools .NET Core Global Tool + + :param source_dir: str + Path to a folder containing the source code + + :param subprocess_dotnet: + An instance of the dotnet process wrapper + + :param artifacts_dir: str + Path to a folder where the built artifacts should be placed + + :param options: + Dictionary of options ot pass to build action + + :param mode: str + Mode the build should produce + + :param architecture: str + Architecture to build for. Default value is X86_64 which is consistent with Amazon Lambda Tools + + :param os_utils: + Optional, OS utils + """ NAME = "RunPackageAction" DESCRIPTION = "Execute the `dotnet lambda package` command." PURPOSE = Purpose.COMPILE_SOURCE - def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=None, os_utils=None): + def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, architecture=X86_64, os_utils=None): super(RunPackageAction, self).__init__() self.source_dir = source_dir self.subprocess_dotnet = subprocess_dotnet @@ -90,6 +112,9 @@ def execute(self): "package", "--output-package", zipfullpath, + # Pass function architecture to Amazon Lambda Tools. + "--function-architecture", + self.architecture, # Specify the architecture with the --runtime MSBuild parameter "--msbuild-parameters", "--runtime " + self._get_runtime(), diff --git a/tests/unit/workflows/dotnet_clipackage/test_actions.py b/tests/unit/workflows/dotnet_clipackage/test_actions.py index 34045d8cb..d4f3380c4 100644 --- a/tests/unit/workflows/dotnet_clipackage/test_actions.py +++ b/tests/unit/workflows/dotnet_clipackage/test_actions.py @@ -89,7 +89,16 @@ def test_build_package(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], + [ + "lambda", + "package", + "--output-package", + zip_path, + "--function-architecture", + X86_64, + "--msbuild-parameters", + "--runtime linux-x64", + ], cwd="/source_dir", ) @@ -106,7 +115,16 @@ def test_build_package_x86(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-x64"], + [ + "lambda", + "package", + "--output-package", + zip_path, + "--function-architecture", + X86_64, + "--msbuild-parameters", + "--runtime linux-x64", + ], cwd="/source_dir", ) @@ -123,7 +141,16 @@ def test_build_package_arm64(self): zip_path = os.path.join(self.artifacts_dir, "source_dir.zip") self.subprocess_dotnet.run.assert_called_once_with( - ["lambda", "package", "--output-package", zip_path, "--msbuild-parameters", "--runtime linux-arm64"], + [ + "lambda", + "package", + "--output-package", + zip_path, + "--function-architecture", + ARM64, + "--msbuild-parameters", + "--runtime linux-arm64", + ], cwd="/source_dir", ) @@ -144,6 +171,8 @@ def test_build_package_arguments(self): "package", "--output-package", zip_path, + "--function-architecture", + X86_64, "--msbuild-parameters", "--runtime linux-x64", "--framework", @@ -180,6 +209,8 @@ def test_debug_configuration_set(self): "package", "--output-package", zip_path, + "--function-architecture", + X86_64, "--msbuild-parameters", "--runtime linux-x64", "--configuration",