Skip to content

Commit

Permalink
fix: last deployed stack local file is overwritten when different app…
Browse files Browse the repository at this point in the history
…s are used
  • Loading branch information
philasmar authored and normj committed Oct 19, 2021
1 parent c375c3c commit 10be2be
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository contains the AWS .NET deployment tool for .NET CLI - the opinion

The tool assumes minimal knowledge of AWS. It is designed to guide you through the deployment process and provides suggested defaults. The tool will show you all compute service options available to deploy your application, and will recommend a default with information about why it was chosen. The other compute service options will be shown with an explanation of their differences. If the selected compute option does not match your needs, you can select a different compute service.

The goal of the deployment tool is to deploy cloud-native .NET applications that are built with .NET Core 2.1 and above. A cloud-native .NET application is written in .NET with the intent to deploy to Linux. It is not tied to any Windows specific technology such as Windows registry, IIS or MSMQ, and can be deployed on virtualized compute. The tool **cannot** be used to deploy .NET Framework, Desktop, Xamarin, or other applications that do not fit the "cloud-native" criteria.
The goal of the deployment tool is to deploy cloud-native .NET applications that are built with .NET Core 3.1 and above. A cloud-native .NET application is written in .NET with the intent to deploy to Linux. It is not tied to any Windows specific technology such as Windows registry, IIS or MSMQ, and can be deployed on virtualized compute. The tool **cannot** be used to deploy .NET Framework, Desktop, Xamarin, or other applications that do not fit the "cloud-native" criteria.

## Project Status
The tool is currently in **developer preview**. It currently has limited support for deployment targets and the settings for those targets. We are looking for feedback on the type of applications users want to deploy to AWS and what features are important to them. Please provide your feedback by opening an [issue in this repository](https://github.com/aws/aws-dotnet-deploy/issues).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace AWS.Deploy.Orchestration.LocalUserSettings
{
public class LocalUserSettings
{
public List<LastDeployedStack>? LastDeployedStacks { get; set; }

public LocalUserSettings(List<LastDeployedStack> lastDeployedStacks)
{
LastDeployedStacks = lastDeployedStacks;
}
public List<LastDeployedStack> LastDeployedStacks = new List<LastDeployedStack>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ public async Task UpdateLastDeployedStack(string stackName, string projectName,
}
else
{
localUserSettings.LastDeployedStacks = new List<LastDeployedStack>() {
new LastDeployedStack(
awsAccountId,
awsRegion,
projectName,
new List<string>() { stackName })};
var currentStack = new LastDeployedStack(
awsAccountId,
awsRegion,
projectName,
new List<string>()
{
stackName
});

if (localUserSettings.LastDeployedStacks == null)
{
localUserSettings.LastDeployedStacks = new List<LastDeployedStack>() { currentStack };
}
else
{
localUserSettings.LastDeployedStacks.Add(currentStack);
}
}
}
else
Expand All @@ -84,7 +95,10 @@ public async Task UpdateLastDeployedStack(string stackName, string projectName,
awsRegion,
projectName,
new List<string>() { stackName }) };
localUserSettings = new LocalUserSettings(lastDeployedStacks);
localUserSettings = new LocalUserSettings
{
LastDeployedStacks = lastDeployedStacks
};
}

await WriteLocalUserSettingsFile(localUserSettings);
Expand Down Expand Up @@ -167,8 +181,7 @@ private async Task<string> WriteLocalUserSettingsFile(LocalUserSettings deployme
var settingsFilejsonString = JsonConvert.SerializeObject(deploymentManifestModel, new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new SerializeModelContractResolver()
NullValueHandling = NullValueHandling.Ignore
});

await _fileManager.WriteAllTextAsync(localUserSettingsFilePath, settingsFilejsonString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ public async Task UpdateLastDeployedStackTest()
Assert.Equal(stackName, userSettings.LastDeployedStacks[0].Stacks[0]);
}

[Fact]
public async Task UpdateLastDeployedStackTest_ExistingStacks()
{
var stackName = "WebAppWithDockerFile";
var awsAccountId = "1234567890";
var awsRegion = "us-west-2";
var settingsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aws-dotnet-deploy", "local-user-settings.json");
await _fileManager.WriteAllTextAsync(settingsFilePath, "{\"LastDeployedStacks\": [{\"AWSAccountId\": \"1234567890\",\"AWSRegion\": \"us-west-2\",\"ProjectName\": \"WebApp1\",\"Stacks\": [\"WebApp1\"]}]}");

await _localUserSettingsEngine.UpdateLastDeployedStack(stackName, stackName, awsAccountId, awsRegion);
var userSettings = await _localUserSettingsEngine.GetLocalUserSettings();

Assert.True(_fileManager.Exists(settingsFilePath));
Assert.NotNull(userSettings);
Assert.NotNull(userSettings.LastDeployedStacks);
Assert.Equal(2, userSettings.LastDeployedStacks.Count);
Assert.Equal(awsAccountId, userSettings.LastDeployedStacks[1].AWSAccountId);
Assert.Equal(awsRegion, userSettings.LastDeployedStacks[1].AWSRegion);
Assert.Single(userSettings.LastDeployedStacks[1].Stacks);
Assert.Equal(stackName, userSettings.LastDeployedStacks[1].Stacks[0]);
}

[Fact]
public async Task DeleteLastDeployedStackTest()
{
Expand All @@ -65,7 +87,6 @@ public async Task DeleteLastDeployedStackTest()
Assert.Single(userSettings.LastDeployedStacks);
Assert.Equal(awsAccountId, userSettings.LastDeployedStacks[0].AWSAccountId);
Assert.Equal(awsRegion, userSettings.LastDeployedStacks[0].AWSRegion);
Assert.Null(userSettings.LastDeployedStacks[0].Stacks);
}

[Fact]
Expand All @@ -86,9 +107,8 @@ public async Task CleanOrphanStacksTest()
Assert.Single(userSettings.LastDeployedStacks);
Assert.Equal(awsAccountId, userSettings.LastDeployedStacks[0].AWSAccountId);
Assert.Equal(awsRegion, userSettings.LastDeployedStacks[0].AWSRegion);
Assert.Null(userSettings.LastDeployedStacks[0].Stacks);

// Attempt to clean orphans again. This is to make sure if the underlying stacks array collection is null we don't throw an exception.
// Attempt to clean orphans again. This is to make sure if the underlying stacks array collection is null we don't throw an exception.
await _localUserSettingsEngine.CleanOrphanStacks(new List<string> { "WebAppWithDockerFile1" }, stackName, awsAccountId, awsRegion);
userSettings = await _localUserSettingsEngine.GetLocalUserSettings();

Expand All @@ -98,7 +118,6 @@ public async Task CleanOrphanStacksTest()
Assert.Single(userSettings.LastDeployedStacks);
Assert.Equal(awsAccountId, userSettings.LastDeployedStacks[0].AWSAccountId);
Assert.Equal(awsRegion, userSettings.LastDeployedStacks[0].AWSRegion);
Assert.Null(userSettings.LastDeployedStacks[0].Stacks);
}
}
}

0 comments on commit 10be2be

Please sign in to comment.