Skip to content

Commit

Permalink
Merge pull request #362 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 0.23
  • Loading branch information
philasmar authored Oct 12, 2021
2 parents 2ae77eb + 39e09aa commit 6281946
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/AWS.Deploy.CLI/Commands/ServerModeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ServerModeCommand(IToolInteractiveService interactiveService, int port, i

public async Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
_interactiveService.WriteLine("Server mode is an experimental feature being developed to allow communication between this CLI and the AWS Toolkit for Visual Studio. Expect behavior changes and API changes as server mode is being developed.");
_interactiveService.WriteLine("Server mode allows communication between this CLI and the AWS Toolkit for Visual Studio.");

IEncryptionProvider encryptionProvider = CreateEncryptionProvider();

Expand All @@ -54,15 +54,15 @@ public ServerModeCommand(IToolInteractiveService interactiveService, int port, i

var host = builder.Build();

if (_parentPid == null)
if (_parentPid.HasValue && _parentPid.Value != 0)
{
await host.RunAsync(cancellationToken);
}
else
{
try
{
var process = Process.GetProcessById((int)_parentPid);
var process = Process.GetProcessById(_parentPid.GetValueOrDefault());
process.EnableRaisingEvents = true;
process.Exited += async (sender, args) => { await ShutDownHost(host, cancellationToken); };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ private async Task CreateDeploymentBundle()
{
if (_selectedRecommendation.Recipe.DeploymentBundle == DeploymentBundleTypes.Container)
{
await _orchestrator.CreateContainerDeploymentBundle(_cloudApplication, _selectedRecommendation);
var dockerBuildDeploymentBundleResult = await _orchestrator.CreateContainerDeploymentBundle(_cloudApplication, _selectedRecommendation);
if (!dockerBuildDeploymentBundleResult)
throw new FailedToCreateDeploymentBundleException("Failed to create a deployment bundle");
}
else if (_selectedRecommendation.Recipe.DeploymentBundle == DeploymentBundleTypes.DotnetPublishZipFile)
{
Expand Down
50 changes: 34 additions & 16 deletions src/AWS.Deploy.Orchestration/CDK/CDKManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using AWS.Deploy.Orchestration.Utilities;

namespace AWS.Deploy.Orchestration.CDK
{
Expand All @@ -25,37 +28,52 @@ public interface ICDKManager

public class CDKManager : ICDKManager
{
private static readonly SemaphoreSlim s_cdkManagerSemaphoreSlim = new(1,1);

private readonly ICDKInstaller _cdkInstaller;
private readonly INPMPackageInitializer _npmPackageInitializer;
private readonly IOrchestratorInteractiveService _interactiveService;

public CDKManager(ICDKInstaller cdkInstaller, INPMPackageInitializer npmPackageInitializer)
public CDKManager(ICDKInstaller cdkInstaller, INPMPackageInitializer npmPackageInitializer, IOrchestratorInteractiveService interactiveService)
{
_cdkInstaller = cdkInstaller;
_npmPackageInitializer = npmPackageInitializer;
_interactiveService = interactiveService;
}

public async Task EnsureCompatibleCDKExists(string workingDirectory, Version cdkVersion)
{
var globalCDKVersionResult = await _cdkInstaller.GetGlobalVersion();
if (globalCDKVersionResult.Success && globalCDKVersionResult.Result?.CompareTo(cdkVersion) >= 0)
{
return;
}
await s_cdkManagerSemaphoreSlim.WaitAsync();

var isNPMPackageInitialized = _npmPackageInitializer.IsInitialized(workingDirectory);
if (!isNPMPackageInitialized)
try
{
await _npmPackageInitializer.Initialize(workingDirectory, cdkVersion);
return; // There is no need to install CDK CLI explicitly, npm install takes care of first time bootstrap.
}
var globalCdkVerion = await _cdkInstaller.GetGlobalVersion();
if (globalCdkVerion.Success && globalCdkVerion.Result?.CompareTo(cdkVersion) >= 0)
{
_interactiveService.LogDebugLine($"CDK version {globalCdkVerion.Result} found in global node_modules.");
return;
}

var localCDKVersionResult = await _cdkInstaller.GetLocalVersion(workingDirectory);
if (localCDKVersionResult.Success && localCDKVersionResult.Result?.CompareTo(cdkVersion) >= 0)
var isNPMPackageInitialized = _npmPackageInitializer.IsInitialized(workingDirectory);
if (!isNPMPackageInitialized)
{
await _npmPackageInitializer.Initialize(workingDirectory, cdkVersion);
return; // There is no need to install CDK CLI explicitly, npm install takes care of first time bootstrap.
}

var localCdkVersion = await _cdkInstaller.GetLocalVersion(workingDirectory);
if (localCdkVersion.Success && localCdkVersion.Result?.CompareTo(cdkVersion) >= 0)
{
_interactiveService.LogDebugLine($"CDK version {localCdkVersion.Result} found in local node_modules at {workingDirectory}.");
return;
}

await _cdkInstaller.Install(workingDirectory, cdkVersion);
}
finally
{
return;
s_cdkManagerSemaphoreSlim.Release();
}

await _cdkInstaller.Install(workingDirectory, cdkVersion);
}
}
}
9 changes: 8 additions & 1 deletion src/AWS.Deploy.Orchestration/CDK/NPMPackageInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ public class NPMPackageInitializer : INPMPackageInitializer
private readonly IPackageJsonGenerator _packageJsonGenerator;
private readonly IFileManager _fileManager;
private readonly IDirectoryManager _directoryManager;
private readonly IOrchestratorInteractiveService _interactiveService;
private const string _packageJsonFileName = "package.json";

public NPMPackageInitializer(ICommandLineWrapper commandLineWrapper, IPackageJsonGenerator packageJsonGenerator, IFileManager fileManager, IDirectoryManager directoryManager)
public NPMPackageInitializer(ICommandLineWrapper commandLineWrapper,
IPackageJsonGenerator packageJsonGenerator,
IFileManager fileManager,
IDirectoryManager directoryManager,
IOrchestratorInteractiveService interactiveService)
{
_commandLineWrapper = commandLineWrapper;
_packageJsonGenerator = packageJsonGenerator;
_fileManager = fileManager;
_directoryManager = directoryManager;
_interactiveService = interactiveService;
}

public bool IsInitialized(string workingDirectory)
Expand All @@ -64,6 +70,7 @@ public bool IsInitialized(string workingDirectory)

public async Task Initialize(string workingDirectory, Version cdkVersion)
{
_interactiveService.LogDebugLine($"Creating package.json at {workingDirectory}.");
var packageJsonFileContent = _packageJsonGenerator.Generate(cdkVersion);
var packageJsonFilePath = Path.Combine(workingDirectory, _packageJsonFileName);

Expand Down
27 changes: 16 additions & 11 deletions src/AWS.Deploy.Orchestration/CustomRecipeLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<HashSet<string>> LocateCustomRecipePaths(string targetApplicat
customRecipePaths.Add(recipePath);
}

foreach (var recipePath in await LocateAlternateRecipePaths(targetApplicationFullPath, solutionDirectoryPath))
foreach (var recipePath in LocateAlternateRecipePaths(targetApplicationFullPath, solutionDirectoryPath))
{
if (ContainsRecipeFile(recipePath))
customRecipePaths.Add(recipePath);
Expand Down Expand Up @@ -95,14 +95,14 @@ private async Task<List<string>> LocateRecipePathsFromManifestFile(string target
/// <param name="targetApplicationFullPath">The absolute path to the target application csproj or fsproj file</param>
/// <param name="solutionDirectoryPath">The absolute path of the directory which contains the solution file for the target application</param>
/// <returns>A list of recipe definition paths.</returns>
private async Task<List<string>> LocateAlternateRecipePaths(string targetApplicationFullPath, string solutionDirectoryPath )
private List<string> LocateAlternateRecipePaths(string targetApplicationFullPath, string solutionDirectoryPath )
{
var targetApplicationDirectoryPath = _directoryManager.GetDirectoryInfo(targetApplicationFullPath).Parent.FullName;
string? rootDirectoryPath;

if (await IsDirectoryUnderSourceControl(targetApplicationDirectoryPath))
if (IsDirectoryUnderSourceControl(targetApplicationDirectoryPath))
{
rootDirectoryPath = await GetSourceControlRootDirectory(targetApplicationDirectoryPath);
rootDirectoryPath = GetSourceControlRootDirectory(targetApplicationDirectoryPath);
}
else
{
Expand Down Expand Up @@ -138,10 +138,10 @@ private List<string> GetRecipePathsFromRootDirectory(string? rootDirectoryPath)
/// </summary>
/// <param name="currentDirectoryPath">The absolute path of the current directory</param>
/// <returns>The source control root directory absolute path.</returns>
private async Task<string?> GetSourceControlRootDirectory(string currentDirectoryPath)
private string? GetSourceControlRootDirectory(string currentDirectoryPath)
{
var possibleRootDirectoryPath = currentDirectoryPath;
while (await IsDirectoryUnderSourceControl(currentDirectoryPath))
while (IsDirectoryUnderSourceControl(currentDirectoryPath))
{
possibleRootDirectoryPath = currentDirectoryPath;
var currentDirectoryInfo = _directoryManager.GetDirectoryInfo(currentDirectoryPath);
Expand All @@ -159,14 +159,19 @@ private List<string> GetRecipePathsFromRootDirectory(string? rootDirectoryPath)
/// </summary>
/// <param name="directoryPath">An absolute directory path.</param>
/// <returns></returns>
private async Task<bool> IsDirectoryUnderSourceControl(string? directoryPath)
private bool IsDirectoryUnderSourceControl(string? directoryPath)
{
if (!string.IsNullOrEmpty(directoryPath))
var currentDir = directoryPath;
while(currentDir != null)
{
var gitStatusResult = await _commandLineWrapper.TryRunWithResult(GIT_STATUS_COMMAND, directoryPath);
var svnStatusResult = await _commandLineWrapper.TryRunWithResult(SVN_STATUS_COMMAND, directoryPath);
return gitStatusResult.Success || svnStatusResult.Success;
if(_directoryManager.GetDirectories(currentDir, ".git").Any())
{
return true;
}

currentDir = _directoryManager.GetDirectoryInfo(currentDir).Parent?.FullName;
}

return false;
}

Expand Down
15 changes: 1 addition & 14 deletions src/AWS.Deploy.Orchestration/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AWS.Deploy.Common;
using AWS.Deploy.Common.IO;
Expand All @@ -14,8 +13,6 @@
using AWS.Deploy.Orchestration.CDK;
using AWS.Deploy.Orchestration.Data;
using AWS.Deploy.Orchestration.LocalUserSettings;
using AWS.Deploy.Recipes;
using Newtonsoft.Json;

namespace AWS.Deploy.Orchestration
{
Expand All @@ -26,7 +23,6 @@ namespace AWS.Deploy.Orchestration
/// </summary>
public class Orchestrator
{
private static readonly SemaphoreSlim s_cdkManagerSemaphoreSlim = new(1,1);
private const string REPLACE_TOKEN_LATEST_DOTNET_BEANSTALK_PLATFORM_ARN = "{LatestDotnetBeanstalkPlatformArn}";

private readonly ICdkProjectHandler? _cdkProjectHandler;
Expand Down Expand Up @@ -166,16 +162,7 @@ public async Task DeployRecommendation(CloudApplication cloudApplication, Recomm
var projFiles = _directoryManager.GetProjFiles(cdkProject);
var cdkVersion = _cdkVersionDetector.Detect(projFiles);

await s_cdkManagerSemaphoreSlim.WaitAsync();

try
{
await _cdkManager.EnsureCompatibleCDKExists(Constants.CDK.DeployToolWorkspaceDirectoryRoot, cdkVersion);
}
finally
{
s_cdkManagerSemaphoreSlim.Release();
}
await _cdkManager.EnsureCompatibleCDKExists(Constants.CDK.DeployToolWorkspaceDirectoryRoot, cdkVersion);

try
{
Expand Down
7 changes: 5 additions & 2 deletions src/AWS.Deploy.ServerMode.Client/RestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,8 +1518,11 @@ public partial class OptionSettingItemSummary
[Newtonsoft.Json.JsonProperty("advanced", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool Advanced { get; set; }

[Newtonsoft.Json.JsonProperty("updatable", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool Updatable { get; set; }
[Newtonsoft.Json.JsonProperty("readOnly", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool ReadOnly { get; set; }

[Newtonsoft.Json.JsonProperty("visible", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public bool Visible { get; set; }

[Newtonsoft.Json.JsonProperty("allowedValues", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public System.Collections.Generic.ICollection<string> AllowedValues { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ public class CDKManagerTests
{
private readonly Mock<ICDKInstaller> _mockCdkManager;
private readonly Mock<INPMPackageInitializer> _mockNodeInitializer;
private readonly Mock<IOrchestratorInteractiveService> _mockInteractiveService;
private readonly CDKManager _cdkManager;
private const string _workingDirectory = @"c:\fake\path";

public CDKManagerTests()
{
_mockCdkManager = new Mock<ICDKInstaller>();
_mockNodeInitializer = new Mock<INPMPackageInitializer>();
_cdkManager = new CDKManager(_mockCdkManager.Object, _mockNodeInitializer.Object);
_mockInteractiveService = new Mock<IOrchestratorInteractiveService>();
_cdkManager = new CDKManager(_mockCdkManager.Object, _mockNodeInitializer.Object, _mockInteractiveService.Object);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System;
using System.IO;
using System.Threading.Tasks;
using AWS.Deploy.CLI;
using AWS.Deploy.CLI.Common.UnitTests.IO;
using AWS.Deploy.Orchestration.CDK;
using Moq;
using Xunit;

namespace AWS.Deploy.Orchestration.UnitTests.CDK
Expand All @@ -16,6 +18,7 @@ public class NPMPackageInitializerTests
private readonly INPMPackageInitializer _npmPackageInitializer;
private readonly TestFileManager _fileManager;
private readonly TestDirectoryManager _directoryManager;
private readonly Mock<IOrchestratorInteractiveService> _mockInteractiveService;
private const string _workingDirectory = @"c:\fake\path";

private const string _packageJsonContent =
Expand Down Expand Up @@ -44,11 +47,12 @@ public class NPMPackageInitializerTests

public NPMPackageInitializerTests()
{
_mockInteractiveService = new Mock<IOrchestratorInteractiveService>();
_fileManager = new TestFileManager();
_directoryManager = new TestDirectoryManager();
_testCommandLineWrapper = new TestCommandLineWrapper();
var packageJsonGenerator = new PackageJsonGenerator(_packageJsonTemplate);
_npmPackageInitializer = new NPMPackageInitializer(_testCommandLineWrapper, packageJsonGenerator, _fileManager, _directoryManager);
_npmPackageInitializer = new NPMPackageInitializer(_testCommandLineWrapper, packageJsonGenerator, _fileManager, _directoryManager, _mockInteractiveService.Object);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.22",
"version": "0.23",
"publicReleaseRefSpec": [
".*"
],
Expand Down

0 comments on commit 6281946

Please sign in to comment.