Skip to content

Commit ee68ddd

Browse files
committed
chore: upgrade templating engine to net8
1 parent 346b5c1 commit ee68ddd

File tree

11 files changed

+45
-46
lines changed

11 files changed

+45
-46
lines changed

src/AWS.Deploy.CLI/Commands/GenerateDeploymentProjectCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, GenerateDep
101101
}
102102
}
103103

104-
cdkProjectHandler.CreateCdkProject(selectedRecommendation, session, saveDirectory);
104+
await cdkProjectHandler.CreateCdkProject(selectedRecommendation, session, saveDirectory);
105105
await GenerateDeploymentRecipeSnapShot(selectedRecommendation, saveDirectory, projectDisplayName, targetApplicationFullPath);
106106

107107
var saveCdkDirectoryFullPath = directoryManager.GetDirectoryInfo(saveDirectory).FullName;

src/AWS.Deploy.Orchestration/AWS.Deploy.Orchestration.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
<PackageReference Include="AWSSDK.S3" Version="4.0.0.1" />
2727
<PackageReference Include="AWSSDK.AppRunner" Version="4.0.0.1" />
2828
<PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="4.0.1.1" />
29-
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
30-
<PackageReference Include="Microsoft.TemplateEngine.IDE" Version="5.0.1" />
31-
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="5.0.1" />
29+
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
30+
<PackageReference Include="Microsoft.TemplateEngine.IDE" Version="8.0.408" />
31+
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="8.0.408" />
3232
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3333
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
3434
<PackageReference Include="YamlDotNet" Version="13.4.0" />

src/AWS.Deploy.Orchestration/CdkProjectHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace AWS.Deploy.Orchestration
1616
public interface ICdkProjectHandler
1717
{
1818
Task<string> ConfigureCdkProject(OrchestratorSession session, CloudApplication cloudApplication, Recommendation recommendation);
19-
string CreateCdkProject(Recommendation recommendation, OrchestratorSession session, string? saveDirectoryPath = null);
19+
Task<string> CreateCdkProject(Recommendation recommendation, OrchestratorSession session, string? saveDirectoryPath = null);
2020
Task DeployCdkProject(OrchestratorSession session, CloudApplication cloudApplication, string cdkProjectPath, Recommendation recommendation);
2121
void DeleteTemporaryCdkProject(string cdkProjectPath);
2222
Task<string> PerformCdkDiff(string cdkProjectPath, CloudApplication cloudApplication);
@@ -71,7 +71,7 @@ public async Task<string> ConfigureCdkProject(OrchestratorSession session, Cloud
7171
{
7272
// Create a new temporary CDK project for a new deployment
7373
_interactiveService.LogInfoMessage("Generating AWS Cloud Development Kit (AWS CDK) deployment project");
74-
cdkProjectPath = CreateCdkProject(recommendation, session);
74+
cdkProjectPath = await CreateCdkProject(recommendation, session);
7575
}
7676

7777
// Write required configuration in appsettings.json
@@ -255,7 +255,7 @@ private async Task CheckCdkDeploymentFailure(string stackId, DateTime deployment
255255
}
256256
}
257257

258-
public string CreateCdkProject(Recommendation recommendation, OrchestratorSession session, string? saveCdkDirectoryPath = null)
258+
public async Task<string> CreateCdkProject(Recommendation recommendation, OrchestratorSession session, string? saveCdkDirectoryPath = null)
259259
{
260260
string? assemblyName;
261261
if (string.IsNullOrEmpty(saveCdkDirectoryPath))
@@ -278,7 +278,7 @@ public string CreateCdkProject(Recommendation recommendation, OrchestratorSessio
278278
_directoryManager.CreateDirectory(saveCdkDirectoryPath);
279279

280280
var templateEngine = new TemplateEngine();
281-
templateEngine.GenerateCDKProjectFromTemplate(recommendation, session, saveCdkDirectoryPath, assemblyName);
281+
await templateEngine.GenerateCdkProjectFromTemplateAsync(recommendation, session, saveCdkDirectoryPath, assemblyName);
282282

283283
_interactiveService.LogDebugMessage($"Saving AWS CDK deployment project to: {saveCdkDirectoryPath}");
284284
return saveCdkDirectoryPath;

src/AWS.Deploy.Orchestration/TemplateEngine.cs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
using System;
5-
using System.Collections.Generic;
64
using System.Diagnostics;
7-
using System.Globalization;
8-
using System.IO;
9-
using System.Linq;
10-
using System.Reflection;
11-
using System.Threading.Tasks;
125
using AWS.Deploy.Common;
136
using Microsoft.TemplateEngine.Abstractions;
14-
using Microsoft.TemplateEngine.Edge;
15-
using Microsoft.TemplateEngine.Edge.Template;
7+
using Microsoft.TemplateEngine.Abstractions.Installer;
8+
using Microsoft.TemplateEngine.Edge.Installers.Folder;
169
using Microsoft.TemplateEngine.IDE;
1710
using Microsoft.TemplateEngine.Orchestrator.RunnableProjects;
18-
using Microsoft.TemplateEngine.Utils;
11+
using DefaultTemplateEngineHost = Microsoft.TemplateEngine.Edge.DefaultTemplateEngineHost;
12+
using WellKnownSearchFilters = Microsoft.TemplateEngine.Utils.WellKnownSearchFilters;
1913

2014
namespace AWS.Deploy.Orchestration
2115
{
2216
public class TemplateEngine
2317
{
24-
private const string HostIdentifier = "aws-net-deploy-template-generator";
25-
private const string HostVersion = "v1.0.0";
18+
private const string HOST_IDENTIFIER = "aws-net-deploy-template-generator";
19+
private const string HOST_VERSION = "v2.0.0";
2620
private readonly Bootstrapper _bootstrapper;
27-
private static readonly object s_locker = new();
2821

2922
public TemplateEngine()
3023
{
31-
_bootstrapper = new Bootstrapper(CreateHost(), null, virtualizeConfiguration: true);
24+
_bootstrapper = new Bootstrapper(CreateHost(), true);
3225
}
3326

34-
public void GenerateCDKProjectFromTemplate(Recommendation recommendation, OrchestratorSession session, string outputDirectory, string assemblyName)
27+
public async Task GenerateCdkProjectFromTemplateAsync(Recommendation recommendation, OrchestratorSession session, string outputDirectory, string assemblyName)
3528
{
3629
if (string.IsNullOrEmpty(recommendation.Recipe.CdkProjectTemplate))
3730
{
@@ -49,50 +42,49 @@ public void GenerateCDKProjectFromTemplate(Recommendation recommendation, Orches
4942
recommendation.Recipe.CdkProjectTemplate);
5043

5144
//Installing the base template into the templating engine to make it available for generation
52-
InstallTemplates(cdkProjectTemplateDirectory);
45+
await InstallTemplates(cdkProjectTemplateDirectory);
5346

5447
//Looking up the installed template in the templating engine
55-
var template =
48+
var templates = await
5649
_bootstrapper
57-
.ListTemplates(
58-
true,
59-
WellKnownSearchFilters.NameFilter(recommendation.Recipe.CdkProjectTemplateId))
60-
.FirstOrDefault()
61-
?.Info;
50+
.GetTemplatesAsync(
51+
new[] { WellKnownSearchFilters.NameFilter(recommendation.Recipe.CdkProjectTemplateId) });
52+
var template = templates.FirstOrDefault()?.Info;
6253

6354
//If the template is not found, throw an exception
6455
if (template == null)
6556
throw new Exception($"Failed to find a Template for [{recommendation.Recipe.CdkProjectTemplateId}]");
6657

67-
var templateParameters = new Dictionary<string, string> {
68-
// CDK Template projects can parameterize the version number of the AWS.Deploy.Recipes.CDK.Common package. This avoid
58+
var templateParameters = new Dictionary<string, string?> {
59+
// CDK Template projects can parameterize the version number of the AWS.Deploy.Recipes.CDK.Common package. This avoids
6960
// projects having to be modified every time the package version is bumped.
7061
{ "AWSDeployRecipesCDKCommonVersion", FileVersionInfo.GetVersionInfo(typeof(AWS.Deploy.Recipes.CDK.Common.CDKRecipeSetup).Assembly.Location).ProductVersion
7162
?? throw new InvalidAWSDeployRecipesCDKCommonVersionException(DeployToolErrorCode.InvalidAWSDeployRecipesCDKCommonVersion, "The version number of the AWS.Deploy.Recipes.CDK.Common package is invalid.") }
7263
};
7364

7465
try
7566
{
76-
lock (s_locker)
77-
{
78-
//Generate the CDK project using the installed template into the output directory
79-
_bootstrapper.CreateAsync(template, assemblyName, outputDirectory, templateParameters, false, "").GetAwaiter().GetResult();
80-
}
67+
//Generate the CDK project using the installed template into the output directory
68+
await _bootstrapper.CreateAsync(template, assemblyName, outputDirectory, templateParameters);
8169
}
8270
catch
8371
{
8472
throw new TemplateGenerationFailedException(DeployToolErrorCode.FailedToGenerateCDKProjectFromTemplate, "Failed to generate CDK project from template");
8573
}
8674
}
8775

88-
private void InstallTemplates(string folderLocation)
76+
private async Task InstallTemplates(string folderLocation)
8977
{
9078
try
9179
{
92-
lock (s_locker)
80+
var installRequests = new[]
9381
{
94-
_bootstrapper.Install(folderLocation);
95-
}
82+
new InstallRequest(folderLocation, folderLocation, force: true)
83+
};
84+
85+
var result = await _bootstrapper.InstallTemplatePackagesAsync(installRequests);
86+
if (result.Any(x => x.Success == false))
87+
throw new Exception("Failed to install the default template that is required to the generate the CDK project");
9688
}
9789
catch(Exception e)
9890
{
@@ -107,13 +99,13 @@ private ITemplateEngineHost CreateHost()
10799
{ "prefs:language", "C#" }
108100
};
109101

110-
var builtIns = new AssemblyComponentCatalog(new[]
102+
var builtIns = new List<(Type, IIdentifiedComponent)>
111103
{
112-
typeof(RunnableProjectGenerator).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Orchestrator.RunnableProjects
113-
typeof(AssemblyComponentCatalog).GetTypeInfo().Assembly, // for assembly: Microsoft.TemplateEngine.Edge
114-
});
104+
(typeof(IGenerator), new RunnableProjectGenerator()),
105+
(typeof(IInstallerFactory), new FolderInstallerFactory())
106+
};
115107

116-
ITemplateEngineHost host = new DefaultTemplateEngineHost(HostIdentifier, HostVersion, CultureInfo.CurrentCulture.Name, preferences, builtIns, null);
108+
ITemplateEngineHost host = new DefaultTemplateEngineHost(HOST_IDENTIFIER, HOST_VERSION, preferences, builtIns);
117109

118110
return host;
119111
}

src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppAppRunner/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppEcsFargate/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppElasticBeanstalkLinux/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/AspNetAppElasticBeanstalkWindows/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/BlazorWasm/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateScheduleTask/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

src/AWS.Deploy.Recipes/CdkTemplates/ConsoleAppECSFargateService/.template.config/template.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "http://json.schemastore.org/template",
23
"author": "AWS",
34
"classifications": [
45
"AWS",

0 commit comments

Comments
 (0)