Skip to content

Commit

Permalink
Merge pull request #619 from aws/dev
Browse files Browse the repository at this point in the history
fix: create bootstrap template fails if directory doesn't exist
  • Loading branch information
philasmar authored Jun 16, 2022
2 parents 6ef0d03 + 899c11d commit c9a4a57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/AWS.Deploy.Constants/CDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ internal static class CDK
/// <summary>
/// Deployment tool workspace directory to create CDK app during the deployment.
/// </summary>
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;
}
}

/// <summary>
/// Directory that contains CDK projects
Expand Down
15 changes: 10 additions & 5 deletions src/AWS.Deploy.Orchestration/CDK/CDKManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c9a4a57

Please sign in to comment.