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 2, 2024
1 parent e6c18bf commit 651d33b
Show file tree
Hide file tree
Showing 41 changed files with 316 additions and 30 deletions.
6 changes: 5 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
codecov:
branch: dev # set the default branch to 'dev'. This branch provides the coverage baselines during pull requests.
branch: dev # set the default branch to 'dev'. This branch provides the coverage baselines during pull requests.

coverage:
exclude:
- "test/**"
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
* ID: AppRunnerEnvironmentVariables
* Description: Configure environment properties for your application.
* Type: KeyValue
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Docker Build Args**
* ID: DockerBuildArgs
* Description: The list of additional options to append to the `docker build` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
* ID: SecurityGroups
* Description: Lists the Amazon EC2 security groups to assign to the EC2 instances in the Auto Scaling group to define firewall rules for the instances.
* Type: List
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Dotnet Build Configuration**
* ID: DotnetBuildConfiguration
* Description: The build configuration to use for the dotnet build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@
* ID: SecurityGroups
* Description: Lists the Amazon EC2 security groups to assign to the EC2 instances in the Auto Scaling group to define firewall rules for the instances.
* Type: List
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Dotnet Build Configuration**
* ID: DotnetBuildConfiguration
* Description: The build configuration to use for the dotnet build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
* ID: ECSEnvironmentVariables
* Description: Configure environment properties for your application.
* Type: KeyValue
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Docker Build Args**
* ID: DockerBuildArgs
* Description: The list of additional options to append to the `docker build` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* ID: HealthCheckURL
* Description: Customize the load balancer health check to ensure that your application, and not just the web server, is in a good state.
* Type: String
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Dotnet Build Configuration**
* ID: DotnetBuildConfiguration
* Description: The build configuration to use for the dotnet build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* ID: HealthCheckURL
* Description: Customize the load balancer health check to ensure that your application, and not just the web server, is in a good state.
* Type: String
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Dotnet Build Configuration**
* ID: DotnetBuildConfiguration
* Description: The build configuration to use for the dotnet build
Expand Down
4 changes: 4 additions & 0 deletions site/content/docs/cicd/recipes/Blazor WebAssembly App.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
* ID: WebAclId
* Description: The AWS WAF (web application firewall) ACL arn
* Type: String
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Dotnet Build Configuration**
* ID: DotnetBuildConfiguration
* Description: The build configuration to use for the dotnet build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* ID: ImageTag
* Description: This tag will be associated to the container images which are pushed to Amazon Elastic Container Registry.
* Type: String
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Docker Build Args**
* ID: DockerBuildArgs
* Description: The list of additional options to append to the `docker build` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
* ID: ECSEnvironmentVariables
* Description: Configure environment properties for your application.
* Type: KeyValue
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Docker Build Args**
* ID: DockerBuildArgs
* Description: The list of additional options to append to the `docker build` command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
* ID: ECSEnvironmentVariables
* Description: Configure environment properties for your application.
* Type: KeyValue
* **Environment Architecture**
* ID: EnvironmentArchitecture
* Description: The CPU architecture of the environment to create.
* Type: String
* **Docker Build Args**
* ID: DockerBuildArgs
* Description: The list of additional options to append to the `docker build` command.
Expand Down
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);
}
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#L739

Added line #L739 was not covered by tests
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;

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);

var userInputConfiguration = new UserInputConfiguration<TypeHintResource>(
idSelector: platform => platform.SystemName,

Check warning on line 52 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#L52

Added line #L52 was not covered by tests
displaySelector: platform => platform.DisplayName,
defaultSelector: platform => platform.SystemName.Equals(currentValue))
{
CreateNew = false
};

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

var result = userResponse.SelectedOption?.SystemName!;
recommendation.DeploymentBundle.EnvironmentArchitecture = Enum.Parse<SupportedArchitecture>(result);
return result;
}
}
}
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
Loading

0 comments on commit 651d33b

Please sign in to comment.