Skip to content

Commit

Permalink
feat: add .NET8 support for Beanstalk web apps and ECS Fargate consol…
Browse files Browse the repository at this point in the history
…e apps
  • Loading branch information
philasmar committed Oct 16, 2023
1 parent c060951 commit 52f4a6c
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/AWS.Deploy.DockerEngine/Properties/DockerFileConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"SdkType": "Microsoft.NET.Sdk.Web",
"ImageMapping": [
{
"TargetFramework": "net8.0",
"BaseImage": "mcr.microsoft.com/dotnet/aspnet:8.0",
"BuildImage": "mcr.microsoft.com/dotnet/sdk:8.0"
}, {
"TargetFramework": "net7.0",
"BaseImage": "mcr.microsoft.com/dotnet/aspnet:7.0",
"BuildImage": "mcr.microsoft.com/dotnet/sdk:7.0"
Expand All @@ -27,6 +31,11 @@
{
"SdkType": "Microsoft.NET.Sdk",
"ImageMapping": [
{
"TargetFramework": "net8.0",
"BaseImage": "mcr.microsoft.com/dotnet/runtime:8.0",
"BuildImage": "mcr.microsoft.com/dotnet/sdk:8.0"
},
{
"TargetFramework": "net7.0",
"BaseImage": "mcr.microsoft.com/dotnet/runtime:7.0",
Expand Down
10 changes: 7 additions & 3 deletions src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ public async Task<string> CreateDotnetPublishZip(Recommendation recommendation)
_interactiveService.LogInfoMessage(string.Empty);
_interactiveService.LogInfoMessage("Creating Dotnet Publish Zip file...");

// Since Beanstalk doesn't currently have .NET 7 preinstalled we need to make sure we are doing a self contained publish when creating the deployment bundle.
if (recommendation.Recipe.TargetService == RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK && recommendation.ProjectDefinition.TargetFramework == "net7.0")
// Since Beanstalk doesn't currently have .NET 7 and .NET 8 preinstalled we need to make sure we are doing a self-contained publish when creating the deployment bundle.
var targetFramework = recommendation.ProjectDefinition.TargetFramework ?? string.Empty;
var unavailableFramework = new List<string> { "net7.0", "net8.0" };
var frameworkNames = new Dictionary<string, string> { { "net7.0", ".NET 7" }, { "net8.0", ".NET 8" } };
if (recommendation.Recipe.TargetService == RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK &&
unavailableFramework.Contains(targetFramework))
{
_interactiveService.LogInfoMessage("Using self contained publish since AWS Elastic Beanstalk does not currently have .NET 7 preinstalled");
_interactiveService.LogInfoMessage($"Using self-contained publish since AWS Elastic Beanstalk does not currently have {frameworkNames[targetFramework]} preinstalled");
recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"Type": "MSProperty",
"Condition": {
"PropertyName": "TargetFramework",
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0" ]
"AllowedValues": [ "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" ]
}
}
],
Expand Down
33 changes: 33 additions & 0 deletions test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using AWS.Deploy.Common.IO;
using AWS.Deploy.Common.Recipes;
using AWS.Deploy.Common.Recipes.Validation;
using AWS.Deploy.Constants;
using AWS.Deploy.Orchestration;
using AWS.Deploy.Orchestration.RecommendationEngine;
using AWS.Deploy.Recipes;
Expand Down Expand Up @@ -208,6 +209,38 @@ public async Task CreateDotnetPublishZip_SelfContained()
Assert.Equal(expectedCommand, _commandLineWrapper.CommandsToExecute.First().Command);
}

/// <summary>
/// Since Beanstalk doesn't currently have .NET 7 and .NET 8 preinstalled we need to make sure we are doing a self-contained publish when creating the deployment bundle.
/// This test checks when the target framework is net7.0 or net8.0, then we are performing a self-contained build.
/// </summary>
[Fact]
public async Task CreateDotnetPublishZip_SelfContained_Net7_Net8()
{
var projectPath = SystemIOUtilities.ResolvePath(Path.Combine("docker", "WebAppNet8"));
var project = await _projectDefinitionParser.Parse(projectPath);
_recipeDefinition.TargetService = RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK;
var recommendation = new Recommendation(_recipeDefinition, project, 100, new Dictionary<string, object>());

recommendation.DeploymentBundle.DotnetPublishBuildConfiguration = "Release";
recommendation.DeploymentBundle.DotnetPublishAdditionalBuildArguments = "--nologo";

Assert.False(recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild);

await _deploymentBundleHandler.CreateDotnetPublishZip(recommendation);

Assert.True(recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild);

var expectedCommand =
$"dotnet publish \"{project.ProjectPath}\"" +
$" -o \"{_directoryManager.CreatedDirectories.First()}\"" +
" -c Release" +
" --runtime linux-x64" +
" --nologo" +
" --self-contained true";

Assert.Equal(expectedCommand, _commandLineWrapper.CommandsToExecute.First().Command);
}

private async Task<RecommendationEngine> BuildRecommendationEngine(string testProjectName)
{
var fullPath = SystemIOUtilities.ResolvePath(testProjectName);
Expand Down
1 change: 1 addition & 0 deletions test/AWS.Deploy.CLI.UnitTests/DockerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class DockerTests
[InlineData("ConsoleSdkType", "")]
[InlineData("WorkerServiceExample", "")]
[InlineData("WebAppNet7", "")]
[InlineData("WebAppNet8", "")]
public async Task DockerGenerate(string topLevelFolder, string projectName)
{
await DockerGenerateTestHelper(topLevelFolder, projectName);
Expand Down
27 changes: 27 additions & 0 deletions testapps/docker/WebAppNet8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["WebAppNet8.csproj", ""]
RUN dotnet restore "WebAppNet8.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build

FROM build AS publish
RUN apt-get update -yq \
&& apt-get install -yq ca-certificates curl gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebAppNet8.dll"]
6 changes: 6 additions & 0 deletions testapps/docker/WebAppNet8/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", () => "Test .NET 8");
app.Run();
27 changes: 27 additions & 0 deletions testapps/docker/WebAppNet8/ReferenceDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["WebAppNet8.csproj", ""]
RUN dotnet restore "WebAppNet8.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "WebAppNet8.csproj" -c Release -o /app/build

FROM build AS publish
RUN apt-get update -yq \
&& apt-get install -yq ca-certificates curl gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update -yq \
&& apt-get install nodejs -yq
RUN dotnet publish "WebAppNet8.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebAppNet8.dll"]
9 changes: 9 additions & 0 deletions testapps/docker/WebAppNet8/WebAppNet8.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
8 changes: 8 additions & 0 deletions testapps/docker/WebAppNet8/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions testapps/docker/WebAppNet8/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 52f4a6c

Please sign in to comment.