Skip to content

Commit

Permalink
feat: add support for deploying ARM console apps to ECS Fargate
Browse files Browse the repository at this point in the history
  • Loading branch information
philasmar committed Oct 13, 2024
1 parent 6adaba2 commit 628fb39
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .autover/changes/a2dd7cca-b2c5-47e1-8bce-34eb5239a047.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "AWS.Deploy.CLI",
"Type": "Minor",
"ChangelogMessages": [
"Add support for deploying ARM console apps to ECS Fargate"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ private void ConfigureTaskDefinition(IRecipeProps<Configuration> props)
{
TaskRole = AppIAMTaskRole,
Cpu = settings.TaskCpu,
MemoryLimitMiB = settings.TaskMemory
MemoryLimitMiB = settings.TaskMemory,
RuntimePlatform = new RuntimePlatform
{
CpuArchitecture = CpuArchitecture.Of(props.EnvironmentArchitecture ?? string.Empty)
}
}));

AppLogging = new AwsLogDriver(InvokeCustomizeCDKPropsEvent(nameof(AppLogging), this, new AwsLogDriverProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ private void ConfigureTaskDefinition(IRecipeProps<Configuration> props)
{
TaskRole = AppIAMTaskRole,
Cpu = settings.TaskCpu,
MemoryLimitMiB = settings.TaskMemory
MemoryLimitMiB = settings.TaskMemory,
RuntimePlatform = new RuntimePlatform
{
CpuArchitecture = CpuArchitecture.Of(props.EnvironmentArchitecture ?? string.Empty)
}
}));

AppLogging = new AwsLogDriver(InvokeCustomizeCDKPropsEvent(nameof(AppLogging), this, new AwsLogDriverProps
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.3",
"Version": "1.1.0",
"Name": "Scheduled Task on Amazon Elastic Container Service (ECS) using AWS Fargate",
"DeploymentType": "CdkProject",
"DeploymentBundle": "Container",
Expand All @@ -11,7 +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" ],
"SupportedArchitectures": [ "x86_64", "arm64" ],

"DisplayedResources": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./aws-deploy-recipe-schema.json",
"Id": "ConsoleAppEcsFargateService",
"Version": "1.0.3",
"Version": "1.1.0",
"Name": "Service on Amazon Elastic Container Service (ECS) using AWS Fargate",
"DeploymentType": "CdkProject",
"DeploymentBundle": "Container",
Expand All @@ -11,7 +11,7 @@
"ShortDescription": "Deploys a service 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" ],
"SupportedArchitectures": [ "x86_64", "arm64" ],

"DisplayedResources": [
{
Expand Down
64 changes: 64 additions & 0 deletions test/AWS.Deploy.CLI.IntegrationTests/ConsoleAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,70 @@ public async Task DefaultConfigurations(params string[] components)
Assert.True(await _cloudFormationHelper.IsStackDeleted(_stackName), $"{_stackName} still exists.");
}

[Theory]
[InlineData("testapps", "ConsoleAppService", "ConsoleAppService.csproj")]
[InlineData("testapps", "ConsoleAppTask", "ConsoleAppTask.csproj")]
public async Task FargateArmDeployment(params string[] components)
{
_stackName = $"{components[1]}Arm{Guid.NewGuid().ToString().Split('-').Last()}";

// Arrange input for deploy
await _interactiveService.StdInWriter.WriteAsync(Environment.NewLine); // Select default recommendation
await _interactiveService.StdInWriter.WriteLineAsync("8"); // Select "Environment Architecture"
await _interactiveService.StdInWriter.WriteLineAsync("2"); // Select "Arm64"
await _interactiveService.StdInWriter.WriteAsync(Environment.NewLine); // Confirm selection and deploy
await _interactiveService.StdInWriter.FlushAsync();

// Deploy
var deployArgs = new[] { "deploy", "--project-path", _testAppManager.GetProjectPath(Path.Combine(components)), "--application-name", _stackName, "--diagnostics" };
Assert.Equal(CommandReturnCodes.SUCCESS, await _app.Run(deployArgs));

// Verify application is deployed and running
Assert.Equal(StackStatus.CREATE_COMPLETE, await _cloudFormationHelper.GetStackStatus(_stackName));

var cluster = await _ecsHelper.GetCluster(_stackName);
Assert.Equal("ACTIVE", cluster.Status);

// Verify CloudWatch logs
var logGroup = await _ecsHelper.GetLogGroup(_stackName);
var logMessages = await _cloudWatchLogsHelper.GetLogMessages(logGroup);
Assert.Contains("Hello World!", logMessages);

var deployStdOut = _interactiveService.StdOutReader.ReadAllLines();

var tempCdkProjectLine = deployStdOut.First(line => line.StartsWith("Saving AWS CDK deployment project to: "));
var tempCdkProject = tempCdkProjectLine.Split(": ")[1].Trim();
Assert.False(Directory.Exists(tempCdkProject), $"{tempCdkProject} must not exist.");

// list
var listArgs = new[] { "list-deployments", "--diagnostics" };
Assert.Equal(CommandReturnCodes.SUCCESS, await _app.Run(listArgs));;

// Verify stack exists in list of deployments
var listStdOut = _interactiveService.StdOutReader.ReadAllLines().Select(x => x.Split()[0]).ToList();
Assert.Contains(listStdOut, (deployment) => _stackName.Equals(deployment));

// Arrange input for re-deployment
await _interactiveService.StdInWriter.WriteAsync(Environment.NewLine); // Select default option settings
await _interactiveService.StdInWriter.FlushAsync();

// Perform re-deployment
deployArgs = new[] { "deploy", "--project-path", _testAppManager.GetProjectPath(Path.Combine(components)), "--application-name", _stackName, "--diagnostics" };
Assert.Equal(CommandReturnCodes.SUCCESS, await _app.Run(deployArgs));
Assert.Equal(StackStatus.UPDATE_COMPLETE, await _cloudFormationHelper.GetStackStatus(_stackName));

// Arrange input for delete
await _interactiveService.StdInWriter.WriteAsync("y"); // Confirm delete
await _interactiveService.StdInWriter.FlushAsync();
var deleteArgs = new[] { "delete-deployment", _stackName, "--diagnostics" };

// Delete
Assert.Equal(CommandReturnCodes.SUCCESS, await _app.Run(deleteArgs));;

// Verify application is deleted
Assert.True(await _cloudFormationHelper.IsStackDeleted(_stackName), $"{_stackName} still exists.");
}

public void Dispose()
{
Dispose(true);
Expand Down

0 comments on commit 628fb39

Please sign in to comment.