Skip to content

Commit

Permalink
Adding dotnet build method that is version agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
Beau-Gosse-dev committed Sep 20, 2024
1 parent 537f3ce commit bf7c162
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 7 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,8 @@ coverage.xml

# Temporary scratch directory used by the tests
tests/integration/buildcmd/scratch
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/buildcmd/Dotnet8/bin
tests/integration/testdata/buildcmd/Dotnet8/obj
tests/integration/testdata/buildcmd/Dotnet*/bin
tests/integration/testdata/buildcmd/Dotnet*/obj
tests/integration/testdata/invoke/credential_tests/inprocess/dotnet/STS/obj
tests/integration/testdata/sync/code/after/dotnet_function/src/HelloWorld/obj/
tests/integration/testdata/sync/code/before/dotnet_function/src/HelloWorld/obj/
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def get_workflow_config(
selectors_by_build_method = {
"makefile": BasicWorkflowSelector(PROVIDED_MAKE_CONFIG),
"dotnet7": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"dotnet": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"rust-cargolambda": BasicWorkflowSelector(RUST_CARGO_LAMBDA_CONFIG),
}

Expand Down
6 changes: 5 additions & 1 deletion tests/integration/buildcmd/test_build_cmd_dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestBuildCommand_Dotnet_cli_package(BuildIntegDotnetBase):
[
("provided.al2", "Dotnet7", None, None),
("provided.al2", "Dotnet7", None, MountMode.WRITE),
("provided.al2", "Dotnet", None, None),
]
)
@skipIf(SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD, SKIP_DOCKER_MESSAGE)
Expand All @@ -36,7 +37,10 @@ def test_dotnet_al2(self, runtime, code_uri, mode, mount_mode):
"Architectures": "x86_64",
}

self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")
if(mode == "Dotnet"):
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet.yaml")
else:
self.template_path = self.template_path.replace("template.yaml", "template_build_method_dotnet_7.yaml")

self.validate_build_command(overrides, mode, mount_mode)
self.validate_build_artifacts(self.EXPECTED_FILES_PROJECT_MANIFEST_PROVIDED)
Expand Down
20 changes: 20 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<OutputType>exe</OutputType>
<AssemblyName>bootstrap</AssemblyName>
<ImplicitUsings>enable</ImplicitUsings>
<SelfContained>true</SelfContained>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.1" />
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.3.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" />
</ItemGroup>

</Project>

38 changes: 38 additions & 0 deletions tests/integration/testdata/buildcmd/Dotnet/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.al2023",
"function-memory-size" : 256,
"function-timeout" : 30,
"function-handler" : "HelloWorld::HelloWorld.Function::FunctionHandler"
}
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: dotnet

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

0 comments on commit bf7c162

Please sign in to comment.