From 8520316861608f417c925fb64a7a3b1f9df7e0dc Mon Sep 17 00:00:00 2001 From: Norm Johanson Date: Thu, 2 Mar 2023 16:19:27 -0800 Subject: [PATCH] fix: Set container memory limit to the same as the task to ensure the .NET GC knows the correct amount of available heap space. --- .../CdkTemplates/AspNetAppEcsFargate/Generated/Recipe.cs | 3 ++- .../ConsoleAppECSFargateScheduleTask/Generated/Recipe.cs | 3 ++- .../ConsoleAppECSFargateService/Generated/Recipe.cs | 3 ++- .../AWS.Deploy.CLI.IntegrationTests.csproj | 3 ++- test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs | 8 ++++++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppEcsFargate/Generated/Recipe.cs b/src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppEcsFargate/Generated/Recipe.cs index 26c5fff44..b1b7d588f 100644 --- a/src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppEcsFargate/Generated/Recipe.cs +++ b/src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppEcsFargate/Generated/Recipe.cs @@ -151,7 +151,8 @@ private void ConfigureECSClusterAndService(IRecipeProps recipeCon { Image = ContainerImage.FromEcrRepository(EcrRepository, recipeConfiguration.ECRImageTag), Logging = AppLogging, - Environment = settings.ECSEnvironmentVariables + Environment = settings.ECSEnvironmentVariables, + MemoryLimitMiB = settings.TaskMemory })); AppContainerDefinition.AddPortMappings(new PortMapping diff --git a/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateScheduleTask/Generated/Recipe.cs b/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateScheduleTask/Generated/Recipe.cs index 14ecbfeed..5e36729ec 100644 --- a/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateScheduleTask/Generated/Recipe.cs +++ b/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateScheduleTask/Generated/Recipe.cs @@ -126,7 +126,8 @@ private void ConfigureTaskDefinition(IRecipeProps props) { Image = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag), Logging = AppLogging, - Environment = settings.ECSEnvironmentVariables + Environment = settings.ECSEnvironmentVariables, + MemoryLimitMiB = settings.TaskMemory }; AppTaskDefinition.AddContainer(nameof(AppContainerDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppContainerDefinition), this, AppContainerDefinition)); diff --git a/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateService/Generated/Recipe.cs b/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateService/Generated/Recipe.cs index 600bd3972..047a1dab6 100644 --- a/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateService/Generated/Recipe.cs +++ b/src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateService/Generated/Recipe.cs @@ -133,7 +133,8 @@ private void ConfigureTaskDefinition(IRecipeProps props) { Image = ContainerImage.FromEcrRepository(ecrRepository, props.ECRImageTag), Logging = AppLogging, - Environment = settings.ECSEnvironmentVariables + Environment = settings.ECSEnvironmentVariables, + MemoryLimitMiB = settings.TaskMemory }; AppTaskDefinition.AddContainer(nameof(AppContainerDefinition), InvokeCustomizeCDKPropsEvent(nameof(AppContainerDefinition), this, AppContainerDefinition)); diff --git a/test/AWS.Deploy.CLI.IntegrationTests/AWS.Deploy.CLI.IntegrationTests.csproj b/test/AWS.Deploy.CLI.IntegrationTests/AWS.Deploy.CLI.IntegrationTests.csproj index b4da1a357..67e212590 100644 --- a/test/AWS.Deploy.CLI.IntegrationTests/AWS.Deploy.CLI.IntegrationTests.csproj +++ b/test/AWS.Deploy.CLI.IntegrationTests/AWS.Deploy.CLI.IntegrationTests.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -8,6 +8,7 @@ + diff --git a/test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs b/test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs index b8355ecc7..d65eca697 100644 --- a/test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs +++ b/test/AWS.Deploy.CLI.IntegrationTests/ServerModeTests.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Amazon.CloudFormation; +using Amazon.ECS; using Amazon.Runtime; using AWS.Deploy.CLI.Commands; using AWS.Deploy.CLI.Common.UnitTests.IO; @@ -245,6 +246,13 @@ public async Task WebFargateDeploymentNoConfigChanges() Assert.True(logOutput.Length > 0); + // Check to make sure the task memory setting was copied to the container defintion memory limit; + var taskDefinitionId = await _cloudFormationHelper.GetResourceId(_stackName, "RecipeAppTaskDefinitionAC7F53DB"); + using var ecsClient = new AmazonECSClient(Amazon.RegionEndpoint.GetBySystemName(_awsRegion)); + var taskDefinition = (await ecsClient.DescribeTaskDefinitionAsync(new Amazon.ECS.Model.DescribeTaskDefinitionRequest { TaskDefinition = taskDefinitionId })).TaskDefinition; + var containerDefinition = taskDefinition.ContainerDefinitions[0]; + Assert.Equal(int.Parse(taskDefinition.Memory), containerDefinition.Memory); + // Make sure section header is return to output log Assert.Contains("Creating deployment image", logOutput.ToString());