From a9ffccbcc61bd534c89d081af1a2f2a1cb77c494 Mon Sep 17 00:00:00 2001 From: Phil Asmar Date: Fri, 2 Aug 2024 15:26:00 -0400 Subject: [PATCH] respond to comments --- src/AWS.Deploy.Common/Exceptions.cs | 3 +- .../DeploymentBundleHandler.cs | 11 ++++- src/AWS.Deploy.Orchestration/Exceptions.cs | 8 ---- .../DeploymentBundleHandlerTests.cs | 46 +++++++++++++++++-- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/AWS.Deploy.Common/Exceptions.cs b/src/AWS.Deploy.Common/Exceptions.cs index f6992b17..badedb7a 100644 --- a/src/AWS.Deploy.Common/Exceptions.cs +++ b/src/AWS.Deploy.Common/Exceptions.cs @@ -128,8 +128,7 @@ public enum DeployToolErrorCode FailedToSaveDeploymentSettings = 10010600, InvalidWindowsManifestFile = 10010700, UserDeploymentFileNotFound = 10010800, - DockerInspectFailed = 10004200, - InvalidElasticBeanstalkPlatform = 10010900 + DockerInspectFailed = 10004200 } public class ProjectFileNotFoundException : DeployToolException diff --git a/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs b/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs index 5bb56870..a23669d6 100644 --- a/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs +++ b/src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs @@ -121,7 +121,12 @@ private void SwitchToSelfContainedBuildIfNeeded(Recommendation recommendation) { if (recommendation.Recipe.TargetService == RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK) { + if (recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild) + return; + var targetFramework = recommendation.ProjectDefinition.TargetFramework ?? string.Empty; + if (string.IsNullOrEmpty(targetFramework)) + return; // Elastic Beanstalk doesn't currently have .NET 7 preinstalled. var unavailableFramework = new List { "net7.0" }; @@ -139,10 +144,12 @@ private void SwitchToSelfContainedBuildIfNeeded(Recommendation recommendation) var beanstalkPlatformSettingValue = _optionSettingHandler.GetOptionSettingValue(recommendation, beanstalkPlatformSetting); var beanstalkPlatformSettingValueSplit = beanstalkPlatformSettingValue?.Split("/"); if (beanstalkPlatformSettingValueSplit?.Length != 3) - throw new InvalidElasticBeanstalkPlatformException(DeployToolErrorCode.InvalidElasticBeanstalkPlatform, $"The selected Elastic Beanstalk platform version '{beanstalkPlatformSettingValue}' is invalid."); + // If the platform is not in the expected format, we will proceed normally to allow users to manually set the self-contained build to true. + return; var beanstalkPlatformName = beanstalkPlatformSettingValueSplit[1]; if (!Version.TryParse(beanstalkPlatformSettingValueSplit[2], out var beanstalkPlatformVersion)) - throw new InvalidElasticBeanstalkPlatformException(DeployToolErrorCode.InvalidElasticBeanstalkPlatform, $"The selected Elastic Beanstalk platform version '{beanstalkPlatformSettingValue}' is invalid."); + // If the platform is not in the expected format, we will proceed normally to allow users to manually set the self-contained build to true. + return; // Elastic Beanstalk recently added .NET8 support in // platform '.NET 8 on AL2023 version 3.1.1' and '.NET Core on AL2 version 2.8.0'. diff --git a/src/AWS.Deploy.Orchestration/Exceptions.cs b/src/AWS.Deploy.Orchestration/Exceptions.cs index dd13a9ff..fc7ec56d 100644 --- a/src/AWS.Deploy.Orchestration/Exceptions.cs +++ b/src/AWS.Deploy.Orchestration/Exceptions.cs @@ -276,12 +276,4 @@ public class InvalidWindowsManifestFileException : DeployToolException { public InvalidWindowsManifestFileException(DeployToolErrorCode errorCode, string message, Exception? innerException = null) : base(errorCode, message, innerException) { } } - - /// - /// Throw if the deploy tool encounters an invalid Elastic Beanstalk platform version. - /// - public class InvalidElasticBeanstalkPlatformException : DeployToolException - { - public InvalidElasticBeanstalkPlatformException(DeployToolErrorCode errorCode, string message, Exception? innerException = null) : base(errorCode, message, innerException) { } - } } diff --git a/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs b/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs index 2b91bc77..91c1018e 100644 --- a/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs +++ b/test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs @@ -284,6 +284,40 @@ public async Task CreateDotnetPublishZip_SelfContained_Net7() Assert.Equal(expectedCommand, _commandLineWrapper.CommandsToExecute.First().Command); } + [Fact] + public async Task CreateDotnetPublishZip_UnsupportedFramework_AlreadySetAsSelfContained() + { + var projectPath = SystemIOUtilities.ResolvePath(Path.Combine("docker", "WebAppNet7")); + var project = await _projectDefinitionParser.Parse(projectPath); + _recipeDefinition.TargetService = RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK; + _recipeDefinition.OptionSettings.Add( + new OptionSettingItem( + "ElasticBeanstalkPlatformArn", + "ElasticBeanstalkPlatformArn", + "Beanstalk Platform", + "The name of the Elastic Beanstalk platform to use with the environment.") + { DefaultValue = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 8 running on 64bit Amazon Linux 2023/3.1.3" }); + var recommendation = new Recommendation(_recipeDefinition, project, 100, new Dictionary()); + + recommendation.DeploymentBundle.DotnetPublishBuildConfiguration = "Release"; + recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild = true; + + Assert.True(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 " + + " --self-contained true"; + + Assert.Equal(expectedCommand, _commandLineWrapper.CommandsToExecute.First().Command); + } + [Theory] [InlineData("arn:aws:elasticbeanstalk:us-west-2::platform/.NET 8 running on 64bit Amazon Linux 2023")] [InlineData("arn:aws:elasticbeanstalk:us-west-2::platform/.NET 8 running on 64bit Amazon Linux 2023/invalidversion")] @@ -303,10 +337,16 @@ public async Task CreateDotnetPublishZip_InvalidPlatformArn(string platformArn) }); var recommendation = new Recommendation(_recipeDefinition, project, 100, new Dictionary()); - var exception = await Assert.ThrowsAsync(async () => await _deploymentBundleHandler.CreateDotnetPublishZip(recommendation)); + await _deploymentBundleHandler.CreateDotnetPublishZip(recommendation); - Assert.Equal(DeployToolErrorCode.InvalidElasticBeanstalkPlatform, exception.ErrorCode); - Assert.Equal($"The selected Elastic Beanstalk platform version '{platformArn}' is invalid.", exception.Message); + Assert.False(recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild); + + var expectedCommand = + $"dotnet publish \"{project.ProjectPath}\"" + + $" -o \"{_directoryManager.CreatedDirectories.First()}\"" + + " -c Release "; + + Assert.Equal(expectedCommand, _commandLineWrapper.CommandsToExecute.First().Command); } [Theory]