in src/AWS.Deploy.CLI/Commands/CommandFactory.cs [176:300]
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(_optionApplicationName);
deployCommand.Add(_optionApply);
deployCommand.Add(_optionDiagnosticLogging);
deployCommand.Add(_optionDisableInteractive);
deployCommand.Add(_optionDeploymentProject);
deployCommand.Add(_optionSaveSettings);
deployCommand.Add(_optionSaveAllSettings);
}
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;
DeploymentSettings? deploymentSettings = null;
if (!string.IsNullOrEmpty(input.Apply))
{
var applyPath = Path.GetFullPath(input.Apply, targetApplicationDirectoryPath);
deploymentSettings = await _deploymentSettingsHandler.ReadSettings(applyPath);
}
var (awsCredentials, regionFromProfile) = await _awsUtilities.ResolveAWSCredentials(input.Profile ?? deploymentSettings?.AWSProfile);
var awsRegion = _awsUtilities.ResolveAWSRegion(input.Region ?? deploymentSettings?.AWSRegion ?? regionFromProfile);
_commandLineWrapper.RegisterAWSContext(awsCredentials, awsRegion);
_awsClientFactory.RegisterAWSContext(awsCredentials, awsRegion);
var callerIdentity = await _awsResourceQueryer.GetCallerIdentity(awsRegion);
var session = new OrchestratorSession(
projectDefinition,
awsCredentials,
awsRegion,
callerIdentity.Account)
{
AWSProfileName = input.Profile ?? deploymentSettings?.AWSProfile ?? null
};
var dockerEngine = new DockerEngine(projectDefinition, _fileManager, _directoryManager);
var deploy = new DeployCommand(
_serviceProvider,
_toolInteractiveService,
_orchestratorInteractiveService,
_cdkProjectHandler,
_cdkManager,
_cdkVersionDetector,
_deploymentBundleHandler,
dockerEngine,
_awsResourceQueryer,
_cloudFormationTemplateReader,
_deployedApplicationQueryer,
_typeHintCommandFactory,
_displayedResourceHandler,
_cloudApplicationNameGenerator,
_localUserSettingsEngine,
_consoleUtilities,
_systemCapabilityEvaluator,
session,
_directoryManager,
_fileManager,
_awsServiceHandler,
_optionSettingHandler,
_validatorFactory,
_recipeHandler,
_deployToolWorkspaceMetadata,
_deploymentSettingsHandler);
var deploymentProjectPath = input.DeploymentProject ?? string.Empty;
if (!string.IsNullOrEmpty(deploymentProjectPath))
{
deploymentProjectPath = Path.GetFullPath(deploymentProjectPath, targetApplicationDirectoryPath);
}
var saveSettingsConfig = Helpers.GetSaveSettingsConfiguration(input.SaveSettings, input.SaveAllSettings, targetApplicationDirectoryPath, _fileManager);
await deploy.ExecuteAsync(input.ApplicationName ?? string.Empty, deploymentProjectPath, saveSettingsConfig, deploymentSettings);
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);
}
_toolInteractiveService.WriteErrorLine(string.Empty);
_toolInteractiveService.WriteErrorLine("For more information, please visit our troubleshooting guide https://aws.github.io/aws-dotnet-deploy/troubleshooting-guide/.");
_toolInteractiveService.WriteErrorLine("If you are still unable to solve this issue and believe this is an issue with the tooling, please cut a ticket https://github.com/aws/aws-dotnet-deploy/issues/new/choose.");
// 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;
}