Skip to content

Commit

Permalink
Merge pull request #840 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 1.21
  • Loading branch information
ashovlin authored Jul 8, 2024
2 parents c512b3c + 5b1c4c2 commit ff86c9c
Show file tree
Hide file tree
Showing 44 changed files with 1,284 additions and 205 deletions.
2 changes: 1 addition & 1 deletion THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
** AWSSDK.ElasticLoadBalancingV2; version 3.7.302.33 -- https://www.nuget.org/packages/AWSSDK.ElasticLoadBalancingV2/
** AWSSDK.Core; version 3.7.303.20 -- https://www.nuget.org/packages/AWSSDK.Core
** AWSSDK.CloudWatchLogs; version 3.7.305.18 -- https://www.nuget.org/packages/AWSSDK.CloudWatchLogs
** Amazon.CDK.Lib; version 2.131.0 -- https://www.nuget.org/packages/Amazon.CDK.Lib/
** Amazon.CDK.Lib; version 2.146.0 -- https://www.nuget.org/packages/Amazon.CDK.Lib/

Apache License
Version 2.0, January 2004
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
* ID: LoadBalancerType
* Description: The type of load balancer for your environment.
* Type: String
* **Load Balancer Scheme**
* ID: LoadBalancerScheme
* Description: Specify "Internal" if your application serves requests only from connected VPCs. "Public" load balancers serve requests from the Internet.
* Type: String
* **Application IAM Role**
* ID: ApplicationIAMRole
* Description: The Identity and Access Management (IAM) role that provides AWS credentials to the application to access AWS services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
* ID: LoadBalancerType
* Description: The type of load balancer for your environment.
* Type: String
* **Load Balancer Scheme**
* ID: LoadBalancerScheme
* Description: Specify "Internal" if your application serves requests only from connected VPCs. "Public" load balancers serve requests from the Internet.
* Type: String
* **Application IAM Role**
* ID: ApplicationIAMRole
* Description: The Identity and Access Management (IAM) role that provides AWS credentials to the application to access AWS services.
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.Deploy.CLI/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void SetExecutionEnvironment(string[] args)
Environment.SetEnvironmentVariable(envName, envValue.ToString());
}

private static string GetToolVersion()
internal static string GetToolVersion()
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var version = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
Expand Down
16 changes: 11 additions & 5 deletions src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Amazon;
using AWS.Deploy.CLI.Commands.TypeHints;
using AWS.Deploy.CLI.Utilities;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Extensions;
using AWS.Deploy.Orchestration;
using AWS.Deploy.Orchestration.CDK;
using AWS.Deploy.Orchestration.Data;
using AWS.Deploy.Orchestration.Utilities;
using AWS.Deploy.CLI.Commands.CommandHandlerInput;
using AWS.Deploy.Common.IO;
Expand All @@ -37,6 +32,7 @@ public interface ICommandFactory

public class CommandFactory : ICommandFactory
{
private static readonly Option<bool> _optionVersion = new(new[] { "-v", "--version" }, "Show version information");
private static readonly Option<string> _optionProfile = new("--profile", "AWS credential profile used to make calls to AWS.");
private static readonly Option<string> _optionRegion = new("--region", "AWS region to deploy the application to. For example, us-west-2.");
private static readonly Option<string> _optionProjectPath = new("--project-path", () => Directory.GetCurrentDirectory(), "Path to the project to deploy.");
Expand Down Expand Up @@ -156,13 +152,23 @@ public Command BuildRootCommand()

lock(s_root_command_lock)
{
rootCommand.AddOption(_optionVersion);
rootCommand.Add(BuildDeployCommand());
rootCommand.Add(BuildListCommand());
rootCommand.Add(BuildDeleteCommand());
rootCommand.Add(BuildDeploymentProjectCommand());
rootCommand.Add(BuildServerModeCommand());
}

rootCommand.Handler = CommandHandler.Create((bool version) =>
{
if (version)
{
var toolVersion = App.GetToolVersion();
_toolInteractiveService.WriteLine($"Version: {toolVersion}");
}
});

return rootCommand;
}

Expand Down
10 changes: 7 additions & 3 deletions src/AWS.Deploy.CLI/Commands/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public async Task ExecuteAsync(string applicationName, string deploymentProjectP
return;
}

// Because we're starting a deployment, clear the cached system capabilities checks
// in case the deployment fails and the user reruns it after modifying Docker or Node
_systemCapabilityEvaluator.ClearCachedCapabilityChecks();

await CreateDeploymentBundle(orchestrator, selectedRecommendation, cloudApplication);

if (saveSettingsConfig.SettingsType != SaveSettingsType.None)
Expand Down Expand Up @@ -282,14 +286,14 @@ private void DisplayOutputResources(List<DisplayedResourceItem> displayedResourc
/// <param name="selectedRecommendation">The selected recommendation settings used for deployment.<see cref="Recommendation"/></param>
public async Task EvaluateSystemCapabilities(Recommendation selectedRecommendation)
{
var systemCapabilities = await _systemCapabilityEvaluator.EvaluateSystemCapabilities(selectedRecommendation);
var missingSystemCapabilities = await _systemCapabilityEvaluator.EvaluateSystemCapabilities(selectedRecommendation);
var missingCapabilitiesMessage = "";
foreach (var capability in systemCapabilities)
foreach (var capability in missingSystemCapabilities)
{
missingCapabilitiesMessage = $"{missingCapabilitiesMessage}{Environment.NewLine}{capability.GetMessage()}{Environment.NewLine}";
}

if (systemCapabilities.Any())
if (missingSystemCapabilities.Any())
throw new MissingSystemCapabilityException(DeployToolErrorCode.MissingSystemCapabilities, missingCapabilitiesMessage);
}

Expand Down
48 changes: 36 additions & 12 deletions src/AWS.Deploy.CLI/ServerMode/Controllers/DeploymentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ public async Task<IActionResult> StartDeploymentSession(StartDeploymentSessionIn
Guid.NewGuid().ToString()
);

var serviceProvider = CreateSessionServiceProvider(output.SessionId, input.AWSRegion);
var awsResourceQueryer = serviceProvider.GetRequiredService<IAWSResourceQueryer>();

var state = new SessionState(
output.SessionId,
input.ProjectPath,
input.AWSRegion,
(await awsResourceQueryer.GetCallerIdentity(input.AWSRegion)).Account,
await _projectParserUtility.Parse(input.ProjectPath)
);

var serviceProvider = CreateSessionServiceProvider(state);
var awsResourceQueryer = serviceProvider.GetRequiredService<IAWSResourceQueryer>();

state.AWSAccountId = (await awsResourceQueryer.GetCallerIdentity(input.AWSRegion)).Account;

_stateServer.Save(output.SessionId, state);

var deployedApplicationQueryer = serviceProvider.GetRequiredService<IDeployedApplicationQueryer>();
Expand Down Expand Up @@ -581,6 +582,10 @@ public async Task<IActionResult> StartDeployment(string sessionId)
if (capabilities.Any())
return Problem($"Unable to start deployment due to missing system capabilities.{Environment.NewLine}{missingCapabilitiesMessage}", statusCode: Microsoft.AspNetCore.Http.StatusCodes.Status424FailedDependency);

// Because we're starting a deployment, clear the cached system capabilities checks
// in case the deployment fails and the user reruns it after modifying Docker or Node
systemCapabilityEvaluator.ClearCachedCapabilityChecks();

var task = new DeployRecommendationTask(orchestratorSession, orchestrator, state.ApplicationDetails, state.SelectedRecommendation);
state.DeploymentTask = task.Execute();

Expand Down Expand Up @@ -668,28 +673,41 @@ public async Task<IActionResult> GetDeploymentDetails(string sessionId)
}

private IServiceProvider CreateSessionServiceProvider(SessionState state)
{
return CreateSessionServiceProvider(state.SessionId, state.AWSRegion);
}

private IServiceProvider CreateSessionServiceProvider(string sessionId, string awsRegion)
{
var awsCredentials = HttpContext.User.ToAWSCredentials();
if(awsCredentials == null)
{
throw new FailedToRetrieveAWSCredentialsException("AWS credentials are missing for the current session.");
}

var interactiveServices = new SessionOrchestratorInteractiveService(sessionId, _hubContext);
var interactiveServices = new SessionOrchestratorInteractiveService(state.SessionId, _hubContext);
var services = new ServiceCollection();
services.AddSingleton<IOrchestratorInteractiveService>(interactiveServices);
services.AddSingleton<ICommandLineWrapper>(services =>
{
var wrapper = new CommandLineWrapper(interactiveServices, true);
wrapper.RegisterAWSContext(awsCredentials, awsRegion);
wrapper.RegisterAWSContext(awsCredentials, state.AWSRegion);
return wrapper;
});

if (state.AWSResourceQueryService == null)
{
services.AddSingleton<IAWSResourceQueryer, SessionAWSResourceQuery>();
}
else
{
services.AddSingleton<IAWSResourceQueryer>(state.AWSResourceQueryService);
}

if (state.SystemCapabilityEvaluator == null)
{
services.AddSingleton<ISystemCapabilityEvaluator, SystemCapabilityEvaluator>();
}
else
{
services.AddSingleton<ISystemCapabilityEvaluator>(state.SystemCapabilityEvaluator);
}

services.AddCustomServices();
var serviceProvider = services.BuildServiceProvider();

Expand All @@ -698,9 +716,15 @@ private IServiceProvider CreateSessionServiceProvider(string sessionId, string a
awsClientFactory.ConfigureAWSOptions(awsOptions =>
{
awsOptions.Credentials = awsCredentials;
awsOptions.Region = RegionEndpoint.GetBySystemName(awsRegion);
awsOptions.Region = RegionEndpoint.GetBySystemName(state.AWSRegion);
});

// Cache the SessionAWSResourceQuery and SystemCapabilityEvaluator with the session state
// so they can be reused in future ServerMode API calls with the same session id. This avoids reloading
// existing resources from AWS and running the Docker/Node checks when they're not expected to change.
state.AWSResourceQueryService = serviceProvider.GetRequiredService<IAWSResourceQueryer>() as SessionAWSResourceQuery;
state.SystemCapabilityEvaluator = serviceProvider.GetRequiredService<ISystemCapabilityEvaluator>() as SystemCapabilityEvaluator;

return serviceProvider;
}

Expand Down
Loading

0 comments on commit ff86c9c

Please sign in to comment.