From 899c11d45df0a82cfe970465e822decba5da8748 Mon Sep 17 00:00:00 2001 From: Phil Asmar Date: Thu, 16 Jun 2022 14:24:47 -0400 Subject: [PATCH] fix: create bootstrap template fails if directory doesn't exist --- src/AWS.Deploy.Constants/CDK.cs | 10 +++++++++- src/AWS.Deploy.Orchestration/CDK/CDKManager.cs | 15 ++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/AWS.Deploy.Constants/CDK.cs b/src/AWS.Deploy.Constants/CDK.cs index 2d8fe7c4d..a2c5c1563 100644 --- a/src/AWS.Deploy.Constants/CDK.cs +++ b/src/AWS.Deploy.Constants/CDK.cs @@ -11,7 +11,15 @@ internal static class CDK /// /// Deployment tool workspace directory to create CDK app during the deployment. /// - public static readonly string DeployToolWorkspaceDirectoryRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aws-dotnet-deploy"); + public static string DeployToolWorkspaceDirectoryRoot { + get + { + var deployToolWorkspace = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aws-dotnet-deploy"); + if (!Directory.Exists(deployToolWorkspace)) + Directory.CreateDirectory(deployToolWorkspace); + return deployToolWorkspace; + } + } /// /// Directory that contains CDK projects diff --git a/src/AWS.Deploy.Orchestration/CDK/CDKManager.cs b/src/AWS.Deploy.Orchestration/CDK/CDKManager.cs index d2ae5d15c..8946acb15 100644 --- a/src/AWS.Deploy.Orchestration/CDK/CDKManager.cs +++ b/src/AWS.Deploy.Orchestration/CDK/CDKManager.cs @@ -45,17 +45,22 @@ public CDKManager(ICDKInstaller cdkInstaller, INPMPackageInitializer npmPackageI _interactiveService = interactiveService; } + private async Task CreateCDKBootstrapTemplate() + { + // The CDK bootstrap template can be generated by running 'cdk bootstrap --show-template'. + // We need to keep the template up to date while making sure that the 'Staging Bucket' retention policies are set to 'Delete'. + var cdkBootstrapTemplate = typeof(CdkProjectHandler).Assembly.ReadEmbeddedFile(TemplateIdentifier); + await using var cdkBootstrapTemplateFile = new StreamWriter(Constants.CDK.CDKBootstrapTemplatePath); + await cdkBootstrapTemplateFile.WriteAsync(cdkBootstrapTemplate); + } + public async Task EnsureCompatibleCDKExists(string workingDirectory, Version cdkVersion) { await s_cdkManagerSemaphoreSlim.WaitAsync(); try { - // The CDK bootstrap template can be generated by running 'cdk bootstrap --show-template'. - // We need to keep the template up to date while making sure that the 'Staging Bucket' retention policies are set to 'Delete'. - var cdkBootstrapTemplate = typeof(CdkProjectHandler).Assembly.ReadEmbeddedFile(TemplateIdentifier); - await using var cdkBootstrapTemplateFile = new StreamWriter(Constants.CDK.CDKBootstrapTemplatePath); - await cdkBootstrapTemplateFile.WriteAsync(cdkBootstrapTemplate); + await CreateCDKBootstrapTemplate(); var installedCdkVersion = await _cdkInstaller.GetVersion(workingDirectory); if (installedCdkVersion.Success && installedCdkVersion.Result?.CompareTo(cdkVersion) >= 0)