Skip to content

Commit

Permalink
feat: add dotnet7 build method (#428)
Browse files Browse the repository at this point in the history
* # This is a combination of 2 commits.
# This is the 1st commit message:

Add dotnet7 build method for provided

* Added 'BuildMethod: dotnet7' using 'Runtime:provided'
* 'Runtime:provided' is only for the provided runtime and not the dotnet runtime

Testing with sample SAM template:
 ( See BuildMethod and Runtime below )
...
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Metadata:
      BuildMethod: dotnet7
    Properties:
      CodeUri: ./src/HelloWorld/
      Handler: HelloWorld::HelloWorld.Function::FunctionHandler
      Runtime: provided
      Architectures:
        - x86_64
...

# This is the commit message #2:

Add dotnet7 build method for provided

* Added 'BuildMethod: dotnet7' using 'Runtime:provided'
* 'Runtime:provided' is only for the provided runtime and not the dotnet runtime

Testing with sample SAM template:
 ( See BuildMethod and Runtime below )
...
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Metadata:
      BuildMethod: dotnet7
    Properties:
      CodeUri: ./src/HelloWorld/
      Handler: HelloWorld::HelloWorld.Function::FunctionHandler
      Runtime: provided
      Architectures:
        - x86_64
...

* run black reformat

Co-authored-by: Samiullah Mohammed <[email protected]>
Co-authored-by: Wing Fung Lau <[email protected]>
Co-authored-by: Mehmet Nuri Deveci <[email protected]>
  • Loading branch information
4 people authored Nov 11, 2022
1 parent 4580762 commit c13391d
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ tests/integration/testdata/buildcmd/Dotnetcore3.1/bin
tests/integration/testdata/buildcmd/Dotnetcore3.1/obj
tests/integration/testdata/buildcmd/Dotnet6/bin
tests/integration/testdata/buildcmd/Dotnet6/obj
tests/integration/testdata/buildcmd/Dotnet7/bin
tests/integration/testdata/buildcmd/Dotnet7/obj
tests/integration/testdata/invoke/credential_tests/inprocess/dotnet/STS/obj

# End of https://www.gitignore.io/api/osx,node,macos,linux,python,windows,pycharm,intellij,sublimetext,visualstudiocode
Expand Down
5 changes: 4 additions & 1 deletion samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ def get_workflow_config(
namedtuple that represents the Builder Workflow Config
"""

selectors_by_build_method = {"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG)}
selectors_by_build_method = {
"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG),
"dotnet7": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
}

selectors_by_runtime = {
"python3.6": BasicWorkflowSelector(PYTHON_PIP_CONFIG),
Expand Down
16 changes: 14 additions & 2 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase):
FUNCTION_LOGICAL_ID = "Function"
EXPECTED_FILES_PROJECT_MANIFEST = {
"Amazon.Lambda.APIGatewayEvents.dll",
"HelloWorld.pdb",
"Amazon.Lambda.Core.dll",
"HelloWorld.runtimeconfig.json",
"Amazon.Lambda.Serialization.Json.dll",
Expand All @@ -959,12 +958,17 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegBase):
"HelloWorld.dll",
}

EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED = {
"bootstrap",
}

@parameterized.expand(
[
("dotnetcore3.1", "Dotnetcore3.1", None),
("dotnet6", "Dotnet6", None),
("dotnetcore3.1", "Dotnetcore3.1", "debug"),
("dotnet6", "Dotnet6", "debug"),
("provided", "Dotnet7", None),
]
)
@pytest.mark.flaky(reruns=3)
Expand All @@ -975,6 +979,10 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"):
"Handler": "HelloWorld::HelloWorld.Function::FunctionHandler",
"Architectures": architecture,
}

if runtime == "provided":
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")

cmdlist = self.get_command_list(use_container=False, parameter_overrides=overrides)

LOG.info("Running Command: {}".format(cmdlist))
Expand All @@ -987,7 +995,11 @@ def test_with_dotnetcore(self, runtime, code_uri, mode, architecture="x86_64"):
run_command(cmdlist, cwd=self.working_dir, env=newenv)

self._verify_built_artifact(
self.default_build_dir, self.FUNCTION_LOGICAL_ID, self.EXPECTED_FILES_PROJECT_MANIFEST
self.default_build_dir,
self.FUNCTION_LOGICAL_ID,
self.EXPECTED_FILES_PROJECT_MANIFEST
if runtime != "provided"
else self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED,
)

self._verify_resource_property(
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet7/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PublishAot>true</PublishAot>
<StripSymbols>true</StripSymbols>
<OutputType>exe</OutputType>
<AssemblyName>bootstrap</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.5.0" />
<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>

<ItemGroup>
<RdXmlFile Include="rd.xml" />
</ItemGroup>

</Project>

38 changes: 38 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet7/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Amazon.Lambda.APIGatewayEvents;
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using System.Text.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;

namespace HelloWorld;

public class Function
{
/// <summary>
/// The main entry point for the custom runtime.
/// </summary>
/// <param name="args"></param>
private static async Task Main(string[] args)
{
Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, string> handler = FunctionHandler;
await LambdaBootstrapBuilder.Create(handler, new SourceGeneratorLambdaJsonSerializer<MyCustomJsonSerializerContext>())
.Build()
.RunAsync();
}

public static string FunctionHandler(APIGatewayHttpApiV2ProxyRequest apigProxyEvent, ILambdaContext context)
{
return "{'message': 'Hello World'}";
}
}

[JsonSerializable(typeof(APIGatewayHttpApiV2ProxyRequest))]
public partial class MyCustomJsonSerializerContext : JsonSerializerContext
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"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",
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"
}
6 changes: 6 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet7/rd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="bootstrap" Dynamic="Required All">
</Assembly>
</Application>
</Directives>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
iAWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Parameteres:
Runtime:
Type: String
CodeUri:
Type: String
Handler:
Type: String

Resources:

Function:
Type: AWS::Serverless::Function
Properties:
Handler: !Ref Handler
Runtime: !Ref Runtime
CodeUri: !Ref CodeUri
Timeout: 600
Metadata:
BuildMethod: dotnet7

OtherRelativePathResource:
Type: AWS::ApiGateway::RestApi
Properties:
BodyS3Location: SomeRelativePath

GlueResource:
Type: AWS::Glue::Job
Properties:
Command:
ScriptLocation: SomeRelativePath

ExampleNestedStack:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.amazonaws.com/examplebucket/exampletemplate.yml
11 changes: 11 additions & 0 deletions tests/unit/lib/build_module/test_workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def test_must_work_for_provided(self, runtime):
self.assertEqual(len(EventTracker.get_tracked_events()), 1)
self.assertIn(Event("BuildWorkflowUsed", "provided-None"), EventTracker.get_tracked_events())

@parameterized.expand([("provided",)])
def test_must_work_for_provided_with_build_method_dotnet7(self, runtime):
result = get_workflow_config(runtime, self.code_dir, self.project_dir, specified_workflow="dotnet7")
self.assertEqual(result.language, "dotnet")
self.assertEqual(result.dependency_manager, "cli-package")
self.assertEqual(result.application_framework, None)
self.assertEqual(result.manifest_name, ".csproj")
self.assertIsNone(result.executable_search_paths)
self.assertEqual(len(EventTracker.get_tracked_events()), 1)
self.assertIn(Event("BuildWorkflowUsed", "dotnet-cli-package"), EventTracker.get_tracked_events())

@parameterized.expand([("provided",)])
def test_must_work_for_provided_with_no_specified_workflow(self, runtime):
# Implicitly look for makefile capability.
Expand Down

0 comments on commit c13391d

Please sign in to comment.