From 4783ec0adb6598d99a1148c9f2b0fdc37b404bed Mon Sep 17 00:00:00 2001 From: Philippe El Asmar Date: Thu, 16 Sep 2021 12:35:57 -0400 Subject: [PATCH 1/2] fix: integration tests failing due to invalid resource output --- .../RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe | 2 +- .../ConfigFileDeployment/ElasticBeanStalkDeploymentTest.cs | 4 ++-- .../DisplayedResourcesHandlerTests.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe index d1d2148fe..96a5643f6 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe @@ -13,7 +13,7 @@ "DisplayedResources": [ { - "LogicalId": "RecipeEnvironment0DFE4D35", + "LogicalId": "RecipeBeanstalkEnvironment83CC12DE", "Description": "Application Endpoint" } ], diff --git a/test/AWS.Deploy.CLI.IntegrationTests/ConfigFileDeployment/ElasticBeanStalkDeploymentTest.cs b/test/AWS.Deploy.CLI.IntegrationTests/ConfigFileDeployment/ElasticBeanStalkDeploymentTest.cs index d717652f5..20be36f54 100644 --- a/test/AWS.Deploy.CLI.IntegrationTests/ConfigFileDeployment/ElasticBeanStalkDeploymentTest.cs +++ b/test/AWS.Deploy.CLI.IntegrationTests/ConfigFileDeployment/ElasticBeanStalkDeploymentTest.cs @@ -72,8 +72,8 @@ public async Task PerformDeployment() var deployStdOut = _interactiveService.StdOutReader.ReadAllLines(); // Example: Endpoint: http://52.36.216.238/ - var applicationUrl = deployStdOut.First(line => line.StartsWith($"\tEndpoint")) - .Split(":")[1] + var applicationUrl = deployStdOut.First(line => line.Trim().StartsWith("Endpoint:")) + .Split(" ")[1] .Trim(); // URL could take few more minutes to come live, therefore, we want to wait and keep trying for a specified timeout diff --git a/test/AWS.Deploy.Orchestration.UnitTests/DisplayedResourcesHandlerTests.cs b/test/AWS.Deploy.Orchestration.UnitTests/DisplayedResourcesHandlerTests.cs index f8678e05e..fea1ac46a 100644 --- a/test/AWS.Deploy.Orchestration.UnitTests/DisplayedResourcesHandlerTests.cs +++ b/test/AWS.Deploy.Orchestration.UnitTests/DisplayedResourcesHandlerTests.cs @@ -66,7 +66,7 @@ public async Task GetDeploymentOutputs_ElasticBeanstalkEnvironment() var recommendations = await engine.ComputeRecommendations(); var recommendation = recommendations.First(r => r.Recipe.Id.Equals("AspNetAppElasticBeanstalkLinux")); - _stackResource.LogicalResourceId = "RecipeEnvironment0DFE4D35"; + _stackResource.LogicalResourceId = "RecipeBeanstalkEnvironment83CC12DE"; _stackResource.PhysicalResourceId = "PhysicalResourceId"; _stackResource.ResourceType = "AWS::ElasticBeanstalk::Environment"; _environmentDescription.CNAME = "www.website.com"; From 59d77ec0e547c2c83c253ccaea4ed341156af05f Mon Sep 17 00:00:00 2001 From: Malhar Khimsaria Date: Fri, 17 Sep 2021 13:38:05 -0400 Subject: [PATCH 2/2] fix: Replace default values for option setting items with stack name as prefix --- src/AWS.Deploy.CLI/Commands/DeployCommand.cs | 10 ++++++---- .../Controllers/DeploymentController.cs | 3 +++ src/AWS.Deploy.Common/Recommendation.cs | 18 +++++------------- .../ASP.NETAppAppRunner.recipe | 2 +- .../ASP.NETAppECSFargate.recipe | 4 ++-- .../ASP.NETAppElasticBeanstalk.recipe | 4 ++-- .../ConsoleAppECSFargateScheduleTask.recipe | 2 +- .../ConsoleAppECSFargateService.recipe | 4 ++-- .../RecommendationTests.cs | 11 ++++++++--- 9 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/AWS.Deploy.CLI/Commands/DeployCommand.cs b/src/AWS.Deploy.CLI/Commands/DeployCommand.cs index 2280f0a16..2b5390ed4 100644 --- a/src/AWS.Deploy.CLI/Commands/DeployCommand.cs +++ b/src/AWS.Deploy.CLI/Commands/DeployCommand.cs @@ -25,6 +25,8 @@ namespace AWS.Deploy.CLI.Commands { public class DeployCommand { + public const string REPLACE_TOKEN_STACK_NAME = "{StackName}"; + private readonly IToolInteractiveService _toolInteractiveService; private readonly IOrchestratorInteractiveService _orchestratorInteractiveService; private readonly ICdkProjectHandler _cdkProjectHandler; @@ -162,7 +164,7 @@ private void DisplayOutputResources(List displayedResourc // Get Cloudformation stack name. var cloudApplicationName = GetCloudApplicationName(stackName, userDeploymentSettings, compatibleApplications); - + // Find existing application with the same CloudFormation stack name. var deployedApplication = allDeployedApplications.FirstOrDefault(x => string.Equals(x.Name, cloudApplicationName)); @@ -191,6 +193,9 @@ private void DisplayOutputResources(List displayedResourc } } + // Apply the user entered stack name to the recommendation so that any default settings based on stack name are applied. + selectedRecommendation.AddReplacementToken(REPLACE_TOKEN_STACK_NAME, cloudApplicationName); + var cloudApplication = new CloudApplication(cloudApplicationName, selectedRecommendation.Recipe.Id); return (orchestrator, selectedRecommendation, cloudApplication); @@ -222,9 +227,6 @@ public async Task EvaluateSystemCapabilities(Recommendation selectedRecommendati /// public async Task ConfigureDeployment(CloudApplication cloudApplication, Orchestrator orchestrator, Recommendation selectedRecommendation, UserDeploymentSettings? userDeploymentSettings) { - // Apply the user entered project name to the recommendation so that any default settings based on project name are applied. - selectedRecommendation.OverrideProjectName(cloudApplication.Name); - var configurableOptionSettings = selectedRecommendation.GetConfigurableOptionSettingItems(); if (userDeploymentSettings != null) diff --git a/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs b/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs index 4be9fd617..23b8ab220 100644 --- a/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs +++ b/src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs @@ -28,6 +28,7 @@ using AWS.Deploy.Orchestration.DisplayedResources; using AWS.Deploy.Common.IO; using AWS.Deploy.Orchestration.LocalUserSettings; +using AWS.Deploy.CLI.Commands; namespace AWS.Deploy.CLI.ServerMode.Controllers { @@ -284,6 +285,7 @@ public async Task SetDeploymentTarget(string sessionId, [FromBody state.ApplicationDetails.Name = input.NewDeploymentName; state.ApplicationDetails.RecipeId = input.NewDeploymentRecipeId; + state.SelectedRecommendation.AddReplacementToken(DeployCommand.REPLACE_TOKEN_STACK_NAME, input.NewDeploymentName); } else if(!string.IsNullOrEmpty(input.ExistingDeploymentName)) { @@ -307,6 +309,7 @@ public async Task SetDeploymentTarget(string sessionId, [FromBody state.ApplicationDetails.Name = input.ExistingDeploymentName; state.ApplicationDetails.RecipeId = existingDeployment.RecipeId; + state.SelectedRecommendation.AddReplacementToken(DeployCommand.REPLACE_TOKEN_STACK_NAME, input.ExistingDeploymentName); } return Ok(); diff --git a/src/AWS.Deploy.Common/Recommendation.cs b/src/AWS.Deploy.Common/Recommendation.cs index 2267523f4..5a8a95a66 100644 --- a/src/AWS.Deploy.Common/Recommendation.cs +++ b/src/AWS.Deploy.Common/Recommendation.cs @@ -11,8 +11,6 @@ namespace AWS.Deploy.Common { public class Recommendation : IUserInputOption { - private const string REPLACE_TOKEN_PROJECT_NAME = "{ProjectName}"; - public string ProjectPath => ProjectDefinition.ProjectPath; public ProjectDefinition ProjectDefinition { get; } @@ -46,8 +44,6 @@ public Recommendation(RecipeDefinition recipe, ProjectDefinition projectDefiniti DeploymentBundle = new DeploymentBundle(); DeploymentBundleSettings = deploymentBundleSettings; - _replacementTokens[REPLACE_TOKEN_PROJECT_NAME] = Path.GetFileNameWithoutExtension(projectDefinition.ProjectPath); - foreach (var replacement in additionalReplacements) { if (!_replacementTokens.ContainsKey(replacement.Key)) @@ -55,15 +51,6 @@ public Recommendation(RecipeDefinition recipe, ProjectDefinition projectDefiniti } } - /// - /// Overrides the project name used as a replacement token in default setting values. - /// - /// - public void OverrideProjectName(string name) - { - _replacementTokens[REPLACE_TOKEN_PROJECT_NAME] = name; - } - public Recommendation ApplyPreviousSettings(IDictionary previousSettings) { var recommendation = this.DeepCopy(); @@ -73,6 +60,11 @@ public Recommendation ApplyPreviousSettings(IDictionary previous return recommendation; } + public void AddReplacementToken(string key, string value) + { + _replacementTokens[key] = value; + } + private void ApplyPreviousSettings(Recommendation recommendation, IDictionary previousSettings) { recommendation.IsExistingCloudApplication = true; diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppAppRunner.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppAppRunner.recipe index 26725386c..50c057bab 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppAppRunner.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppAppRunner.recipe @@ -63,7 +63,7 @@ "TypeHint": "AppRunnerService", "AdvancedSetting": false, "Updatable": false, - "DefaultValue": "{ProjectName}-service" + "DefaultValue": "{StackName}-service" }, { "Id": "Port", diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppECSFargate.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppECSFargate.recipe index 47cebd63a..c8b6e28b7 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppECSFargate.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppECSFargate.recipe @@ -116,7 +116,7 @@ "Name": "New Cluster Name", "Description": "The name of the new cluster to create.", "Type": "String", - "DefaultValue": "{ProjectName}", + "DefaultValue": "{StackName}", "AdvancedSetting": false, "Updatable": false, "Validators": [ @@ -145,7 +145,7 @@ "Description": "The name of the ECS service running in the cluster.", "Type": "String", "TypeHint": "ECSService", - "DefaultValue": "{ProjectName}-service", + "DefaultValue": "{StackName}-service", "AdvancedSetting": false, "Updatable": false, "Validators": [ diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe index 96a5643f6..03e66c06f 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ASP.NETAppElasticBeanstalk.recipe @@ -100,7 +100,7 @@ "Name": "Application Name", "Description": "The Elastic Beanstalk application name.", "Type": "String", - "DefaultValue": "{ProjectName}", + "DefaultValue": "{StackName}", "AdvancedSetting": false, "Updatable": false, "Validators": [ @@ -122,7 +122,7 @@ "Description": "The Elastic Beanstalk environment name.", "Type": "String", "TypeHint": "BeanstalkEnvironment", - "DefaultValue": "{ProjectName}-dev", + "DefaultValue": "{StackName}-dev", "AdvancedSetting": false, "Updatable": false, "Validators": [ diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateScheduleTask.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateScheduleTask.recipe index 9a9682fc9..2fe9dc730 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateScheduleTask.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateScheduleTask.recipe @@ -143,7 +143,7 @@ "Name": "New Cluster Name", "Description": "The name of the new cluster to create.", "Type": "String", - "DefaultValue": "{ProjectName}", + "DefaultValue": "{StackName}", "AdvancedSetting": false, "Updatable": false, "Validators": [ diff --git a/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateService.recipe b/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateService.recipe index d7d91bc9c..8d7e32839 100644 --- a/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateService.recipe +++ b/src/AWS.Deploy.Recipes/RecipeDefinitions/ConsoleAppECSFargateService.recipe @@ -143,7 +143,7 @@ "Name": "New Cluster Name", "Description": "The name of the new cluster to create.", "Type": "String", - "DefaultValue": "{ProjectName}", + "DefaultValue": "{StackName}", "AdvancedSetting": false, "Updatable": false, "Validators": [ @@ -172,7 +172,7 @@ "Description": "The name of the ECS service running in the cluster.", "Type": "String", "TypeHint": "ECSService", - "DefaultValue": "{ProjectName}-service", + "DefaultValue": "{StackName}-service", "AdvancedSetting": false, "Updatable": false, "Validators": [ diff --git a/test/AWS.Deploy.CLI.UnitTests/RecommendationTests.cs b/test/AWS.Deploy.CLI.UnitTests/RecommendationTests.cs index fd13055a9..861473d92 100644 --- a/test/AWS.Deploy.CLI.UnitTests/RecommendationTests.cs +++ b/test/AWS.Deploy.CLI.UnitTests/RecommendationTests.cs @@ -169,6 +169,8 @@ public async Task ResetOptionSettingValue_String() var recommendations = await engine.ComputeRecommendations(); var fargateRecommendation = recommendations.First(r => r.Recipe.Id == Constants.ASPNET_CORE_ASPNET_CORE_FARGATE_RECIPE_ID); + fargateRecommendation.AddReplacementToken("{StackName}", "MyAppStack"); + var ecsServiceNameOptionSetting = fargateRecommendation.Recipe.OptionSettings.First(optionSetting => optionSetting.Id.Equals("ECSServiceName")); var originalDefaultValue = fargateRecommendation.GetOptionSettingDefaultValue(ecsServiceNameOptionSetting); @@ -252,11 +254,14 @@ public async Task ApplyProjectNameToSettings() var recommendations = await engine.ComputeRecommendations(); var beanstalkRecommendation = recommendations.FirstOrDefault(r => r.Recipe.Id == Constants.ASPNET_CORE_BEANSTALK_RECIPE_ID); + var beanstalEnvNameSetting = beanstalkRecommendation.Recipe.OptionSettings.FirstOrDefault(x => string.Equals("EnvironmentName", x.Id)); - Assert.Equal("WebAppNoDockerFile-dev", beanstalkRecommendation.GetOptionSettingValue(beanstalEnvNameSetting)); - beanstalkRecommendation.OverrideProjectName("CustomName"); - Assert.Equal("CustomName-dev", beanstalkRecommendation.GetOptionSettingValue(beanstalEnvNameSetting)); + beanstalkRecommendation.AddReplacementToken("{StackName}", "MyAppStack"); + Assert.Equal("MyAppStack-dev", beanstalkRecommendation.GetOptionSettingValue(beanstalEnvNameSetting)); + + beanstalkRecommendation.AddReplacementToken("{StackName}", "CustomAppStack"); + Assert.Equal("CustomAppStack-dev", beanstalkRecommendation.GetOptionSettingValue(beanstalEnvNameSetting)); } [Theory]