in src/AWS.Deploy.CLI/Commands/CommandFactory.cs [145:255]
private Command BuildDeployCommand()
{
var deployCommand = new Command(
"deploy",
"Inspect, build, and deploy the .NET project to AWS using the recommended AWS service.");
lock (s_child_command_lock)
{
deployCommand.Add(_optionProfile);
deployCommand.Add(_optionRegion);
deployCommand.Add(_optionProjectPath);
deployCommand.Add(_optionStackName);
deployCommand.Add(_optionApply);
deployCommand.Add(_optionDiagnosticLogging);
deployCommand.Add(_optionDisableInteractive);
deployCommand.Add(_optionDeploymentProject);
}
deployCommand.Handler = CommandHandler.Create(async (DeployCommandHandlerInput input) =>
{
try
{
_toolInteractiveService.Diagnostics = input.Diagnostics;
_toolInteractiveService.DisableInteractive = input.Silent;
var projectDefinition = await _projectParserUtility.Parse(input.ProjectPath ?? "");
var targetApplicationDirectoryPath = new DirectoryInfo(projectDefinition.ProjectPath).Parent!.FullName;
UserDeploymentSettings? userDeploymentSettings = null;
if (!string.IsNullOrEmpty(input.Apply))
{
var applyPath = Path.GetFullPath(input.Apply, targetApplicationDirectoryPath);
userDeploymentSettings = UserDeploymentSettings.ReadSettings(applyPath);
}
var awsCredentials = await _awsUtilities.ResolveAWSCredentials(input.Profile ?? userDeploymentSettings?.AWSProfile);
var awsRegion = _awsUtilities.ResolveAWSRegion(input.Region ?? userDeploymentSettings?.AWSRegion);
_commandLineWrapper.RegisterAWSContext(awsCredentials, awsRegion);
_awsClientFactory.RegisterAWSContext(awsCredentials, awsRegion);
var callerIdentity = await _awsResourceQueryer.GetCallerIdentity();
var session = new OrchestratorSession(
projectDefinition,
awsCredentials,
awsRegion,
callerIdentity.Account)
{
AWSProfileName = input.Profile ?? userDeploymentSettings?.AWSProfile ?? null
};
var dockerEngine = new DockerEngine.DockerEngine(projectDefinition, _fileManager);
var deploy = new DeployCommand(
_toolInteractiveService,
_orchestratorInteractiveService,
_cdkProjectHandler,
_cdkManager,
_cdkVersionDetector,
_deploymentBundleHandler,
dockerEngine,
_awsResourceQueryer,
_templateMetadataReader,
_deployedApplicationQueryer,
_typeHintCommandFactory,
_displayedResourceHandler,
_cloudApplicationNameGenerator,
_localUserSettingsEngine,
_consoleUtilities,
_customRecipeLocator,
_systemCapabilityEvaluator,
session,
_directoryManager,
_fileManager);
var deploymentProjectPath = input.DeploymentProject ?? string.Empty;
if (!string.IsNullOrEmpty(deploymentProjectPath))
{
deploymentProjectPath = Path.GetFullPath(deploymentProjectPath, targetApplicationDirectoryPath);
}
await deploy.ExecuteAsync(input.StackName ?? "", deploymentProjectPath, userDeploymentSettings);
return CommandReturnCodes.SUCCESS;
}
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
{
if (input.Diagnostics)
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
else
{
_toolInteractiveService.WriteErrorLine(string.Empty);
_toolInteractiveService.WriteErrorLine(e.Message);
}
// bail out with an non-zero return code.
return CommandReturnCodes.USER_ERROR;
}
catch (Exception e)
{
// This is a bug
_toolInteractiveService.WriteErrorLine(
"Unhandled exception. This is a bug. Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
e.PrettyPrint());
return CommandReturnCodes.UNHANDLED_EXCEPTION;
}
});
return deployCommand;
}