Skip to content

Commit

Permalink
fix: remove auto self-contained build for .NET 8 beanstalk deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Jul 19, 2024
1 parent db9ec45 commit 24c3d67
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 7 deletions.
68 changes: 64 additions & 4 deletions src/AWS.Deploy.Orchestration/Data/AWSResourceQueryer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,9 @@ public async Task<List<PlatformSummary>> GetElasticBeanstalkPlatformArns(params
var allPlatformSummaries = new List<PlatformSummary>();
if (platformTypes.Contains(BeanstalkPlatformType.Linux))
{
allPlatformSummaries.AddRange(await fetchPlatforms(Constants.ElasticBeanstalk.LinuxPlatformType));
var linuxPlatforms = await fetchPlatforms(Constants.ElasticBeanstalk.LinuxPlatformType);
linuxPlatforms = SortElasticBeanstalkLinuxPlatforms(linuxPlatforms);
allPlatformSummaries.AddRange(linuxPlatforms);
}
if (platformTypes.Contains(BeanstalkPlatformType.Windows))
{
Expand Down Expand Up @@ -593,15 +595,73 @@ public async Task<PlatformSummary> GetLatestElasticBeanstalkPlatformArn(Beanstal
"or that the configured credentials lack permission to call ListPlatformVersions.");
}

return platforms.First();
var sortedPlatforms = SortElasticBeanstalkLinuxPlatforms(platforms);

return sortedPlatforms.First();
}

/// <summary>
/// For Linux beanstalk platforms the describe calls return a collection of .NET x and .NET Core based platforms.
/// The order returned will be sorted by .NET version in increasing order then by platform versions. So for example we could get a result like the following
///
/// .NET 6 running on 64bit Amazon Linux 2023 v3.1.3
/// .NET 6 running on 64bit Amazon Linux 2023 v3.1.2
/// .NET 6 running on 64bit Amazon Linux 2023 v3.0.6
/// .NET 6 running on 64bit Amazon Linux 2023 v3.0.5
/// .NET 8 running on 64bit Amazon Linux 2023 v3.1.3
/// .NET Core running on 64bit Amazon Linux 2 v2.8.0
/// .NET Core running on 64bit Amazon Linux 2 v2.7.3
/// .NET Core running on 64bit Amazon Linux 2 v2.6.0
///
/// We want the user to use the latest version of each platform first as well as the latest version of .NET first. Also .NET x should come before .NET Core.
/// The above example will be sorted into the following.
///
/// .NET 8 running on 64bit Amazon Linux 2023 v3.1.3
/// .NET 6 running on 64bit Amazon Linux 2023 v3.1.3
/// .NET 6 running on 64bit Amazon Linux 2023 v3.1.2
/// .NET 6 running on 64bit Amazon Linux 2023 v3.0.6
/// .NET 6 running on 64bit Amazon Linux 2023 v3.0.5
/// .NET Core running on 64bit Amazon Linux 2 v2.8.0
/// .NET Core running on 64bit Amazon Linux 2 v2.7.3
/// .NET Core running on 64bit Amazon Linux 2 v2.6.0
/// </summary>
/// <param name="platforms"></param>
public static List<PlatformSummary> SortElasticBeanstalkLinuxPlatforms(List<PlatformSummary> platforms)
{
var dotnetVersionMap = new Dictionary<string, int>();
foreach (var platform in platforms)
{
var runningIndexOf = platform.PlatformBranchName.IndexOf("running", StringComparison.InvariantCultureIgnoreCase);
if (runningIndexOf == -1)
{
dotnetVersionMap[platform.PlatformArn] = 0;
continue;
}

var framework = platform.PlatformBranchName.Substring(0, runningIndexOf).Trim();
var frameworkSplit = framework.Split(" ");
if (frameworkSplit.Length != 2)
{
dotnetVersionMap[platform.PlatformArn] = 0;
continue;
}

if (!int.TryParse(frameworkSplit[1], out var dotnetVersion))
{
dotnetVersionMap[platform.PlatformArn] = 0;
continue;
}

dotnetVersionMap[platform.PlatformArn] = dotnetVersion;
}

return platforms.OrderByDescending(x => new Version(x.PlatformVersion)).ThenByDescending(x => dotnetVersionMap[x.PlatformArn]).ToList();
}

/// <summary>
/// For Windows beanstalk platforms the describe calls return a collection of Windows Server Code and Windows Server based platforms.
/// The order return will be sorted by platform versions but not OS. So for example we could get a result like the following
///
///
/// IIS 10.0 running on 64bit Windows Server 2016 (1.1.0)
/// IIS 10.0 running on 64bit Windows Server 2016 (1.0.0)
/// IIS 10.0 running on 64bit Windows Server Core 2016 (1.1.0)
Expand All @@ -613,7 +673,7 @@ public async Task<PlatformSummary> GetLatestElasticBeanstalkPlatformArn(Beanstal
///
/// We want the user to use the latest version of each OS first as well as the latest version of Windows first. Also Windows Server should come before Windows Server Core.
/// This matches the behavior of the existing VS toolkit picker. The above example will be sorted into the following.
///
///
/// IIS 10.0 running on 64bit Windows Server 2019 (1.1.0)
/// IIS 10.0 running on 64bit Windows Server Core 2019 (1.1.0)
/// IIS 10.0 running on 64bit Windows Server 2016 (1.1.0)
Expand Down
6 changes: 3 additions & 3 deletions src/AWS.Deploy.Orchestration/DeploymentBundleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ 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 and .NET 8 preinstalled we need to make sure we are doing a self-contained publish when creating the deployment bundle.
// 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.
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" } };
var unavailableFramework = new List<string> { "net7.0" };
var frameworkNames = new Dictionary<string, string> { { "net7.0", ".NET 7" } };
if (recommendation.Recipe.TargetService == RecipeIdentifier.TARGET_SERVICE_ELASTIC_BEANSTALK &&
unavailableFramework.Contains(targetFramework))
{
Expand Down
79 changes: 79 additions & 0 deletions test/AWS.Deploy.Orchestration.UnitTests/AWSResourceQueryerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,85 @@ public void SortElasticBeanstalkWindowsPlatforms()
}
}

[Fact]
public void SortElasticBeanstalkLinuxPlatforms()
{
// Use PlatformOwner as a placeholder to store where the summary should be sorted to.
var platforms = new List<PlatformSummary>()
{
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 6 running on 64bit Amazon Linux 2023/3.1.3",
PlatformBranchName = ".NET 6 running on 64bit Amazon Linux 2023",
PlatformVersion = "3.1.3",
PlatformOwner = "1"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 6 running on 64bit Amazon Linux 2023/3.1.2",
PlatformBranchName = ".NET 6 running on 64bit Amazon Linux 2023",
PlatformVersion = "3.1.2",
PlatformOwner = "2"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 6 running on 64bit Amazon Linux 2023/3.0.6",
PlatformBranchName = ".NET 6 running on 64bit Amazon Linux 2023",
PlatformVersion = "3.0.6",
PlatformOwner = "3"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 6 running on 64bit Amazon Linux 2023/3.0.5",
PlatformBranchName = ".NET 6 running on 64bit Amazon Linux 2023",
PlatformVersion = "3.0.5",
PlatformOwner = "4"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET 8 running on 64bit Amazon Linux 2023/3.1.3",
PlatformBranchName = ".NET 8 running on 64bit Amazon Linux 2023",
PlatformVersion = "3.1.3",
PlatformOwner = "0"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET Core running on 64bit Amazon Linux 2/2.8.0",
PlatformBranchName = ".NET Core running on 64bit Amazon Linux 2",
PlatformVersion = "2.8.0",
PlatformOwner = "5"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET Core running on 64bit Amazon Linux 2/2.7.3",
PlatformBranchName = ".NET Core running on 64bit Amazon Linux 2",
PlatformVersion = "2.7.3",
PlatformOwner = "6"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET Core running on 64bit Amazon Linux 2/2.6.0",
PlatformBranchName = ".NET Core running on 64bit Amazon Linux 2",
PlatformVersion = "2.6.0",
PlatformOwner = "7"
},
new PlatformSummary
{
PlatformArn = "arn:aws:elasticbeanstalk:us-west-2::platform/.NET Core running on 64bit Amazon Linux 2/2.5.7",
PlatformBranchName = ".NET Core running on 64bit Amazon Linux 2",
PlatformVersion = "2.5.7",
PlatformOwner = "8"
}
};

var sortedPlatforms = AWSResourceQueryer.SortElasticBeanstalkLinuxPlatforms(platforms);

for (var i = 0; i < sortedPlatforms.Count; i++)
{
Assert.Equal(i.ToString(), sortedPlatforms[i].PlatformOwner);
}
}

[Fact]
public async Task CreateRepository_TagsWithRecipeName_Success()
{
Expand Down

0 comments on commit 24c3d67

Please sign in to comment.