Skip to content

Commit

Permalink
chore: add ability to select a supported architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Sep 1, 2024
1 parent e6c18bf commit 65409d6
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 29 deletions.
35 changes: 18 additions & 17 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,28 +726,29 @@ private async Task ConfigureDeploymentFromCli(Recommendation recommendation, Opt

object currentValue = _optionSettingHandler.GetOptionSettingValue(recommendation, setting);
object? settingValue = null;
if (setting.AllowedValues?.Count > 0)
{
var userInputConfig = new UserInputConfiguration<string>(
idSelector: x => x,
displaySelector: x => setting.ValueMapping.ContainsKey(x) ? setting.ValueMapping[x] : x,
defaultSelector: x => x.Equals(currentValue))
{
CreateNew = false
};

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(setting.AllowedValues, string.Empty, userInputConfig);
settingValue = userResponse.SelectedOption;

// If they didn't change the value then don't store so we can rely on using the default in the recipe.
if (Equals(settingValue, currentValue))
return;
if (setting.TypeHint.HasValue && _typeHintCommandFactory.GetCommand(setting.TypeHint.Value) is var typeHintCommand && typeHintCommand != null)
{
settingValue = await typeHintCommand.Execute(recommendation, setting);

Check warning on line 732 in src/AWS.Deploy.CLI/Commands/DeployCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/DeployCommand.cs#L732

Added line #L732 was not covered by tests
}
else
{
if (setting.TypeHint.HasValue && _typeHintCommandFactory.GetCommand(setting.TypeHint.Value) is var typeHintCommand && typeHintCommand != null)
if (setting.AllowedValues?.Count > 0)
{
settingValue = await typeHintCommand.Execute(recommendation, setting);
var userInputConfig = new UserInputConfiguration<string>(
idSelector: x => x,

Check warning on line 739 in src/AWS.Deploy.CLI/Commands/DeployCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/DeployCommand.cs#L738-L739

Added lines #L738 - L739 were not covered by tests
displaySelector: x => setting.ValueMapping.ContainsKey(x) ? setting.ValueMapping[x] : x,
defaultSelector: x => x.Equals(currentValue))
{
CreateNew = false
};

Check warning on line 744 in src/AWS.Deploy.CLI/Commands/DeployCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/DeployCommand.cs#L741-L744

Added lines #L741 - L744 were not covered by tests

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(setting.AllowedValues, string.Empty, userInputConfig);
settingValue = userResponse.SelectedOption;

Check warning on line 747 in src/AWS.Deploy.CLI/Commands/DeployCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/DeployCommand.cs#L746-L747

Added lines #L746 - L747 were not covered by tests

// If they didn't change the value then don't store so we can rely on using the default in the recipe.
if (Equals(settingValue, currentValue))
return;

Check warning on line 751 in src/AWS.Deploy.CLI/Commands/DeployCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/DeployCommand.cs#L751

Added line #L751 was not covered by tests
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Recipes;
using AWS.Deploy.Common.TypeHintData;

namespace AWS.Deploy.CLI.Commands.TypeHints
{
public class EnvironmentArchitectureCommand : ITypeHintCommand
{
private readonly IConsoleUtilities _consoleUtilities;
private readonly IOptionSettingHandler _optionSettingHandler;

public EnvironmentArchitectureCommand(IConsoleUtilities consoleUtilities, IOptionSettingHandler optionSettingHandler)
{
_consoleUtilities = consoleUtilities;
_optionSettingHandler = optionSettingHandler;
}

public Task<TypeHintResourceTable> GetResources(Recommendation recommendation, OptionSettingItem optionSetting)
{
var resourceTable = new TypeHintResourceTable
{
Columns = new List<TypeHintResourceColumn>()
{
new TypeHintResourceColumn("Architecture")
}
};

foreach (var value in recommendation.Recipe.SupportedArchitectures ?? new List<SupportedArchitecture> { SupportedArchitecture.X86_64 })
{
var stringValue = value.ToString();
var row = new TypeHintResource(stringValue, stringValue);
row.ColumnValues.Add(stringValue);

resourceTable.Rows.Add(row);
}

return Task.FromResult(resourceTable);
}

public async Task<object> Execute(Recommendation recommendation, OptionSettingItem optionSetting)
{
var currentValue = _optionSettingHandler.GetOptionSettingValue(recommendation, optionSetting);
var resourceTable = await GetResources(recommendation, optionSetting);

Check warning on line 49 in src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs#L48-L49

Added lines #L48 - L49 were not covered by tests

var userInputConfiguration = new UserInputConfiguration<TypeHintResource>(
idSelector: platform => platform.SystemName,
displaySelector: platform => platform.DisplayName,
defaultSelector: platform => platform.SystemName.Equals(currentValue))
{
CreateNew = false
};

Check warning on line 57 in src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs#L51-L57

Added lines #L51 - L57 were not covered by tests

var userResponse = _consoleUtilities.AskUserToChooseOrCreateNew(resourceTable.Rows, "Select the Platform to use:", userInputConfiguration);

Check warning on line 59 in src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs#L59

Added line #L59 was not covered by tests

var result = userResponse.SelectedOption?.SystemName!;
recommendation.DeploymentBundle.EnvironmentArchitecture = Enum.Parse<SupportedArchitecture>(result);
return result;
}

Check warning on line 64 in src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.CLI/Commands/TypeHints/EnvironmentArchitectureCommand.cs#L62-L64

Added lines #L62 - L64 were not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public TypeHintCommandFactory(IServiceProvider serviceProvider, IToolInteractive
{ OptionSettingTypeHint.FilePath, ActivatorUtilities.CreateInstance<FilePathCommand>(serviceProvider) },
{ OptionSettingTypeHint.ElasticBeanstalkVpc, ActivatorUtilities.CreateInstance<ElasticBeanstalkVpcCommand>(serviceProvider) },
{ OptionSettingTypeHint.DockerHttpPort, ActivatorUtilities.CreateInstance<DockerHttpPortCommand>(serviceProvider) },
{ OptionSettingTypeHint.EnvironmentArchitecture, ActivatorUtilities.CreateInstance<EnvironmentArchitectureCommand>(serviceProvider) },
};
}

Expand Down
7 changes: 7 additions & 0 deletions src/AWS.Deploy.Common/DeploymentBundles/DeploymentBundle.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using AWS.Deploy.Common.Recipes;

namespace AWS.Deploy.Common
{
/// <summary>
Expand Down Expand Up @@ -63,5 +65,10 @@ public class DeploymentBundle
/// The list of additional dotnet publish args passed to the target application.
/// </summary>
public string DotnetPublishAdditionalBuildArguments { get; set; } = "";

/// <summary>
/// The CPU architecture of the environment to create.
/// </summary>
public SupportedArchitecture EnvironmentArchitecture { get; set; } = SupportedArchitecture.X86_64;
}
}
3 changes: 2 additions & 1 deletion src/AWS.Deploy.Common/Recipes/OptionSettingTypeHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum OptionSettingTypeHint
VPCConnector,
FilePath,
ElasticBeanstalkVpc,
DockerHttpPort
DockerHttpPort,
EnvironmentArchitecture
};
}
5 changes: 5 additions & 0 deletions src/AWS.Deploy.Common/Recipes/RecipeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public class RecipeDefinition
/// </summary>
public TargetPlatform? TargetPlatform { get; set; }

/// <summary>
/// The CPU architecture that is supported by the recipe.
/// </summary>
public List<SupportedArchitecture>? SupportedArchitectures { get; set; }

/// <summary>
/// The list of DisplayedResources that lists logical CloudFormation IDs with a description.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions src/AWS.Deploy.Common/Recipes/SupportedArchitecture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
// SPDX-License-Identifier: Apache-2.0

namespace AWS.Deploy.Common.Recipes;

public enum SupportedArchitecture
{
X86_64,
Arm64
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class RequiredValidator : IOptionSettingItemValidator
public Task<ValidationResult> Validate(object input, Recommendation recommendation, OptionSettingItem optionSettingItem)
{
var message = ValidationFailedMessage.Replace("{{OptionSetting}}", optionSettingItem.Name);
if (input?.TryDeserialize<SortedSet<string>>(out var inputList) ?? false && inputList != null)
if (input?.TryDeserialize<SortedSet<string>>(out var inputList) ?? false)
{
return Task.FromResult<ValidationResult>(new()
{
Expand Down
6 changes: 6 additions & 0 deletions src/AWS.Deploy.Constants/RecipeIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class RecipeIdentifier
public const string REPLACE_TOKEN_HAS_DEFAULT_VPC = "{HasDefaultVpc}";
public const string REPLACE_TOKEN_HAS_NOT_VPCS = "{HasNotVpcs}";
public const string REPLACE_TOKEN_DEFAULT_CONTAINER_PORT = "{DefaultContainerPort}";
public const string REPLACE_TOKEN_DEFAULT_ENVIRONMENT_ARCHITECTURE = "{DefaultEnvironmentArchitecture}";

/// <summary>
/// Id for the 'dotnet publish --configuration' recipe option
Expand All @@ -38,6 +39,11 @@ internal static class RecipeIdentifier
/// </summary>
public const string DotnetPublishSelfContainedBuildOptionId = "SelfContainedBuild";

/// <summary>
/// Id for the environment architecture recipe option
/// </summary>
public const string EnvironmentArchitectureOptionId = "EnvironmentArchitecture";

public const string TARGET_SERVICE_ELASTIC_BEANSTALK = "AWS Elastic Beanstalk";
}
}
3 changes: 3 additions & 0 deletions src/AWS.Deploy.Orchestration/OptionSettingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ private void SetDeploymentBundleProperty(Recommendation recommendation, OptionSe
case Constants.RecipeIdentifier.DotnetPublishSelfContainedBuildOptionId:
recommendation.DeploymentBundle.DotnetPublishSelfContainedBuild = Convert.ToBoolean(value);
break;
case Constants.RecipeIdentifier.EnvironmentArchitectureOptionId:
recommendation.DeploymentBundle.EnvironmentArchitecture = Enum.Parse<SupportedArchitecture>(value.ToString() ?? string.Empty);
break;
default:
return;
}
Expand Down
8 changes: 8 additions & 0 deletions src/AWS.Deploy.Orchestration/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ public async Task ApplyAllReplacementTokens(Recommendation recommendation, strin
recommendation.AddReplacementToken(Constants.RecipeIdentifier.REPLACE_TOKEN_DEFAULT_CONTAINER_PORT, defaultPort);
recommendation.DeploymentBundle.DockerfileHttpPort = defaultPort;
}
if (recommendation.ReplacementTokens.ContainsKey(Constants.RecipeIdentifier.REPLACE_TOKEN_DEFAULT_ENVIRONMENT_ARCHITECTURE))
{
if (_dockerEngine == null)
throw new InvalidOperationException($"{nameof(_dockerEngine)} is null as part of the Orchestrator object");

Check warning on line 250 in src/AWS.Deploy.Orchestration/Orchestrator.cs

View check run for this annotation

Codecov / codecov/patch

src/AWS.Deploy.Orchestration/Orchestrator.cs#L250

Added line #L250 was not covered by tests

recommendation.AddReplacementToken(Constants.RecipeIdentifier.REPLACE_TOKEN_DEFAULT_ENVIRONMENT_ARCHITECTURE, SupportedArchitecture.X86_64.ToString());
recommendation.DeploymentBundle.EnvironmentArchitecture = SupportedArchitecture.X86_64;
}
}

public async Task DeployRecommendation(CloudApplication cloudApplication, Recommendation recommendation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"Type": "Container",
"Parameters": [
{
"Id": "EnvironmentArchitecture",
"Name": "Environment Architecture",
"Description": "The CPU architecture of the environment to create.",
"TypeHint": "EnvironmentArchitecture",
"Type": "String",
"DefaultValue": "{DefaultEnvironmentArchitecture}",
"AdvancedSetting": false,
"Updatable": true
},
{
"Id": "DockerBuildArgs",
"Name": "Docker Build Args",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"Type": "DotnetPublishZipFile",
"Parameters": [
{
"Id": "EnvironmentArchitecture",
"Name": "Environment Architecture",
"Description": "The CPU architecture of the environment to create.",
"TypeHint": "EnvironmentArchitecture",
"Type": "String",
"DefaultValue": "{DefaultEnvironmentArchitecture}",
"AdvancedSetting": false,
"Updatable": true
},
{
"Id": "DotnetBuildConfiguration",
"Name": "Dotnet Build Configuration",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppAppRunner",
"Version": "1.0.2",
"Version": "1.0.3",
"Name": "ASP.NET Core App to AWS App Runner",
"DeploymentType": "CdkProject",
"DeploymentBundle": "Container",
Expand All @@ -11,6 +11,7 @@
"Description": "This ASP.NET Core application will be built as a container image on Linux and deployed to AWS App Runner, a fully managed service for web applications and APIs. If your project does not contain a Dockerfile, it will be automatically generated, otherwise an existing Dockerfile will be used. Recommended if you want to deploy your web application as a Linux container image on a fully managed environment.",
"TargetService": "AWS App Runner",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppEcsFargate",
"Version": "1.1.1",
"Version": "1.1.2",
"Name": "ASP.NET Core App to Amazon ECS using AWS Fargate",
"DeploymentType": "CdkProject",
"DeploymentBundle": "Container",
Expand All @@ -11,6 +11,7 @@
"Description": "This ASP.NET Core application will be deployed to Amazon Elastic Container Service (Amazon ECS) with compute power managed by AWS Fargate compute engine. If your project does not contain a Dockerfile, it will be automatically generated, otherwise an existing Dockerfile will be used. Recommended if you want to deploy your application as a container image on Linux.",
"TargetService": "Amazon Elastic Container Service",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppElasticBeanstalkLinux",
"Version": "1.0.2",
"Version": "1.0.3",
"Name": "ASP.NET Core App to AWS Elastic Beanstalk on Linux",
"DeploymentType": "CdkProject",
"DeploymentBundle": "DotnetPublishZipFile",
Expand All @@ -11,6 +11,7 @@
"Description": "This ASP.NET Core application will be built and deployed to AWS Elastic Beanstalk on Linux. Recommended if you want to deploy your application directly to EC2 hosts, not as a container image.",
"TargetService": "AWS Elastic Beanstalk",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppElasticBeanstalkWindows",
"Version": "1.0.2",
"Version": "1.0.3",
"Name": "ASP.NET Core App to AWS Elastic Beanstalk on Windows",
"DeploymentType": "CdkProject",
"DeploymentBundle": "DotnetPublishZipFile",
Expand All @@ -11,6 +11,7 @@
"ShortDescription": "ASP.NET Core application deployed to AWS Elastic Beanstalk on Windows.",
"TargetService": "AWS Elastic Beanstalk",
"TargetPlatform": "Windows",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppExistingBeanstalkEnvironment",
"Version": "1.0.1",
"Version": "1.0.2",
"Name": "ASP.NET Core App to Existing AWS Elastic Beanstalk Environment",
"DisableNewDeployments": true,
"DeploymentType": "BeanstalkEnvironment",
Expand All @@ -10,6 +10,7 @@
"Description": "This ASP.NET Core application will be built and deployed to an existing AWS Elastic Beanstalk environment. Recommended if you want to deploy your application directly to EC2 hosts, not as a container image.",
"TargetService": "AWS Elastic Beanstalk",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"RecipePriority": 0,
"RecommendationRules": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "AspNetAppExistingBeanstalkWindowsEnvironment",
"Version": "1.0.0",
"Version": "1.0.1",
"Name": "ASP.NET Core App to Existing AWS Elastic Beanstalk Windows Environment",
"DisableNewDeployments": true,
"DeploymentType": "BeanstalkEnvironment",
Expand All @@ -10,6 +10,7 @@
"Description": "This ASP.NET Core application will be built and deployed to an existing AWS Elastic Beanstalk Windows environment. Recommended if you want to deploy your application directly to EC2 hosts, not as a container image.",
"TargetService": "AWS Elastic Beanstalk",
"TargetPlatform": "Windows",
"SupportedArchitectures": [ "x86_64" ],

"RecipePriority": 0,
"RecommendationRules": [
Expand Down
3 changes: 2 additions & 1 deletion src/AWS.Deploy.Recipes/RecipeDefinitions/BlazorWasm.recipe
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "BlazorWasm",
"Version": "1.0.1",
"Version": "1.0.2",
"Name": "Blazor WebAssembly App",
"DeploymentType": "CdkProject",
"DeploymentBundle": "DotnetPublishZipFile",
Expand All @@ -11,6 +11,7 @@
"Description": "This Blazor WebAssembly application will be built and hosted in a new Amazon Simple Storage Service (Amazon S3) bucket. The Blazor application will be exposed publicly through a CloudFront distribution using the Amazon S3 bucket as the origin.",
"TargetService": "Amazon S3",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "ConsoleAppEcsFargateScheduleTask",
"Version": "1.0.2",
"Version": "1.0.3",
"Name": "Scheduled Task on Amazon Elastic Container Service (ECS) using AWS Fargate",
"DeploymentType": "CdkProject",
"DeploymentBundle": "Container",
Expand All @@ -11,6 +11,7 @@
"ShortDescription": "Deploys a scheduled task as a Linux container image to a fully managed container orchestration service. Dockerfile will be automatically generated if needed.",
"TargetService": "Amazon Elastic Container Service",
"TargetPlatform": "Linux",
"SupportedArchitectures": [ "x86_64" ],

"DisplayedResources": [
{
Expand Down
Loading

0 comments on commit 65409d6

Please sign in to comment.