Skip to content

Commit

Permalink
feat: add dotnet8 support (#587)
Browse files Browse the repository at this point in the history
* feat: add dotnet8 support

* Fix dotnet test, remove collections.Counter

---------

Co-authored-by: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com>
  • Loading branch information
Beau-Gosse-dev and mndeveci authored Feb 16, 2024
1 parent 57b74ab commit c5d5c83
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 36 deletions.
1 change: 1 addition & 0 deletions aws_lambda_builders/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"java21": [ARM64, X86_64],
"go1.x": [ARM64, X86_64],
"dotnet6": [ARM64, X86_64],
"dotnet8": [ARM64, X86_64],
"provided": [ARM64, X86_64],
}

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_copy_dependencies_action(self, source_folder):
copy_dependencies_action = CopyDependenciesAction(empty_source, test_folder, target)
copy_dependencies_action.execute()

self.assertEqual(os.listdir(test_folder), os.listdir(target))
self.assertEqual(set(os.listdir(test_folder)), set(os.listdir(target)))

def test_must_maintain_symlinks_if_enabled(self):
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -116,4 +116,4 @@ def test_move_dependencies_action(self, source_folder):
move_dependencies_action = MoveDependenciesAction(empty_source, test_source, target)
move_dependencies_action.execute()

self.assertEqual(os.listdir(test_folder), os.listdir(target))
self.assertEqual(set(os.listdir(test_folder)), set(os.listdir(target)))
74 changes: 45 additions & 29 deletions tests/integration/workflows/dotnet_clipackage/test_dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import tempfile
import json
from parameterized import parameterized

try:
import pathlib
Expand All @@ -25,21 +26,19 @@ def setUp(self):
self.artifacts_dir = tempfile.mkdtemp()
self.scratch_dir = tempfile.mkdtemp()
self.builder = LambdaBuilder(language="dotnet", dependency_manager="cli-package", application_framework=None)
self.runtime = "dotnet6"

def tearDown(self):
shutil.rmtree(self.artifacts_dir)
shutil.rmtree(self.scratch_dir)

def verify_architecture(self, deps_file_name, expected_architecture, version=None):
def verify_architecture(self, deps_file_name, expected_architecture, version):
deps_file = pathlib.Path(self.artifacts_dir, deps_file_name)

if not deps_file.exists():
self.fail("Failed verifying architecture, {} file not found".format(deps_file_name))

with open(str(deps_file)) as f:
deps_json = json.loads(f.read())
version = version or self.runtime[-3:]
target_name = ".NETCoreApp,Version=v{}/{}".format(version, expected_architecture)
target = deps_json.get("runtimeTarget").get("name")

Expand All @@ -50,19 +49,24 @@ def verify_execute_permissions(self, entrypoint_file_name):
self.assertTrue(os.access(entrypoint_file_path, os.X_OK))


class TestDotnet6(TestDotnetBase):
class TestDotnet(TestDotnetBase):
"""
Tests for dotnet 6
Tests for dotnet
"""

def setUp(self):
super(TestDotnet6, self).setUp()
self.runtime = "dotnet6"
super(TestDotnet, self).setUp()

def test_with_defaults_file(self):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
@parameterized.expand(
[
("dotnet6", "6.0", "WithDefaultsFile6"),
("dotnet8", "8.0", "WithDefaultsFile8"),
]
)
def test_with_defaults_file(self, runtime, version, test_project):
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)

self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime)
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime)

expected_files = {
"Amazon.Lambda.Core.dll",
Expand All @@ -77,14 +81,18 @@ def test_with_defaults_file(self):
output_files = set(os.listdir(self.artifacts_dir))

self.assertEqual(expected_files, output_files)
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version="6.0")
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version)

def test_with_defaults_file_x86(self):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
@parameterized.expand(
[
("dotnet6", "6.0", "WithDefaultsFile6"),
("dotnet8", "8.0", "WithDefaultsFile8"),
]
)
def test_with_defaults_file_x86(self, runtime, version, test_project):
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)

self.builder.build(
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=X86_64
)
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=X86_64)

expected_files = {
"Amazon.Lambda.Core.dll",
Expand All @@ -99,14 +107,18 @@ def test_with_defaults_file_x86(self):
output_files = set(os.listdir(self.artifacts_dir))

self.assertEqual(expected_files, output_files)
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version="6.0")
self.verify_architecture("WithDefaultsFile.deps.json", "linux-x64", version)

def test_with_defaults_file_arm64(self):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "WithDefaultsFile6")
@parameterized.expand(
[
("dotnet6", "6.0", "WithDefaultsFile6"),
("dotnet8", "8.0", "WithDefaultsFile8"),
]
)
def test_with_defaults_file_arm64(self, runtime, version, test_project):
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)

self.builder.build(
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=ARM64
)
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=ARM64)

expected_files = {
"Amazon.Lambda.Core.dll",
Expand All @@ -121,14 +133,18 @@ def test_with_defaults_file_arm64(self):
output_files = set(os.listdir(self.artifacts_dir))

self.assertEqual(expected_files, output_files)
self.verify_architecture("WithDefaultsFile.deps.json", "linux-arm64", version="6.0")
self.verify_architecture("WithDefaultsFile.deps.json", "linux-arm64", version)

def test_with_custom_runtime(self):
source_dir = os.path.join(self.TEST_DATA_FOLDER, "CustomRuntime6")
@parameterized.expand(
[
("dotnet6", "6.0", "CustomRuntime6"),
("dotnet8", "8.0", "CustomRuntime8"),
]
)
def test_with_custom_runtime(self, runtime, version, test_project):
source_dir = os.path.join(self.TEST_DATA_FOLDER, test_project)

self.builder.build(
source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime=self.runtime, architecture=X86_64
)
self.builder.build(source_dir, self.artifacts_dir, self.scratch_dir, source_dir, runtime, architecture=X86_64)

expected_files = {
"Amazon.Lambda.Core.dll",
Expand All @@ -144,7 +160,7 @@ def test_with_custom_runtime(self):
output_files = set(os.listdir(self.artifacts_dir))

self.assertEqual(expected_files, output_files)
self.verify_architecture("bootstrap.deps.json", "linux-x64", version="6.0")
self.verify_architecture("bootstrap.deps.json", "linux-x64", version)
# Execute permissions are required for custom runtimes which bootstrap themselves, otherwise `sam local invoke`
# won't have permission to run the file
self.verify_execute_permissions("bootstrap")
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AWSProjectType>Lambda</AWSProjectType>
<AssemblyName>bootstrap</AssemblyName>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.8.2" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.3.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;

namespace CustomRuntime6;

public class Function
{
private static async Task Main(string[] args)
{
Func<string, ILambdaContext, string> handler = FunctionHandler;
await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer())
.Build()
.RunAsync();
}

public static string FunctionHandler(string input, ILambdaContext context)
{
return input.ToUpper();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "",
"region": "",
"configuration": "Release",
"function-runtime": "provided.al2",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "bootstrap",
"msbuild-parameters": "--self-contained true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

namespace RequireParameters
namespace WithDefaultsFile
{
public class Function
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "",
"region": "",
"configuration": "Release",
"framework": "net8.0",
"function-runtime": "dotnet8",
"function-memory-size": 256,
"function-timeout": 30,
"function-handler": "WithDefaultsFile::WithDefaultsFile.Function::FunctionHandler"
}
13 changes: 10 additions & 3 deletions tests/unit/workflows/dotnet_clipackage/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
from concurrent.futures import ThreadPoolExecutor
from unittest.mock import patch
from parameterized import parameterized

from aws_lambda_builders.actions import ActionFailedError
from aws_lambda_builders.architecture import ARM64, X86_64
Expand Down Expand Up @@ -154,9 +155,15 @@ def test_build_package_arm64(self):
cwd="/source_dir",
)

def test_build_package_arguments(self):
@parameterized.expand(
[
("net6.0"),
("net8.0"),
]
)
def test_build_package_arguments(self, dotnet_version):
mode = "Release"
options = {"--framework": "net6.0"}
options = {"--framework": dotnet_version}
action = RunPackageAction(
self.source_dir, self.subprocess_dotnet, self.artifacts_dir, options, mode, os_utils=self.os_utils
)
Expand All @@ -176,7 +183,7 @@ def test_build_package_arguments(self):
"--msbuild-parameters",
"--runtime linux-x64",
"--framework",
"net6.0",
dotnet_version,
],
cwd="/source_dir",
)
Expand Down

0 comments on commit c5d5c83

Please sign in to comment.