Skip to content

Commit

Permalink
respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Aug 5, 2024
1 parent 559a00e commit a9ffccb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/AWS.Deploy.Common/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ public enum DeployToolErrorCode
FailedToSaveDeploymentSettings = 10010600,
InvalidWindowsManifestFile = 10010700,
UserDeploymentFileNotFound = 10010800,
DockerInspectFailed = 10004200,
InvalidElasticBeanstalkPlatform = 10010900
DockerInspectFailed = 10004200
}

public class ProjectFileNotFoundException : DeployToolException
Expand Down
11 changes: 9 additions & 2 deletions src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> { "net7.0" };
Expand All @@ -139,10 +144,12 @@ private void SwitchToSelfContainedBuildIfNeeded(Recommendation recommendation)
var beanstalkPlatformSettingValue = _optionSettingHandler.GetOptionSettingValue<string>(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'.
Expand Down
8 changes: 0 additions & 8 deletions src/AWS.Deploy.Orchestration/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,4 @@ public class InvalidWindowsManifestFileException : DeployToolException
{
public InvalidWindowsManifestFileException(DeployToolErrorCode errorCode, string message, Exception? innerException = null) : base(errorCode, message, innerException) { }
}

/// <summary>
/// Throw if the deploy tool encounters an invalid Elastic Beanstalk platform version.
/// </summary>
public class InvalidElasticBeanstalkPlatformException : DeployToolException
{
public InvalidElasticBeanstalkPlatformException(DeployToolErrorCode errorCode, string message, Exception? innerException = null) : base(errorCode, message, innerException) { }
}
}
46 changes: 43 additions & 3 deletions test/AWS.Deploy.CLI.UnitTests/DeploymentBundleHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>());

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")]
Expand All @@ -303,10 +337,16 @@ public async Task CreateDotnetPublishZip_InvalidPlatformArn(string platformArn)
});
var recommendation = new Recommendation(_recipeDefinition, project, 100, new Dictionary<string, object>());

var exception = await Assert.ThrowsAsync<InvalidElasticBeanstalkPlatformException>(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]
Expand Down

0 comments on commit a9ffccb

Please sign in to comment.