Skip to content

Commit

Permalink
Merge pull request #330 from aws/dev
Browse files Browse the repository at this point in the history
chore: release 0.19
  • Loading branch information
philasmar authored Sep 15, 2021
2 parents 7952da9 + f1502dc commit b64e38d
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 189 deletions.
24 changes: 22 additions & 2 deletions src/AWS.Deploy.CLI/ServerMode/Controllers/RecipeController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Linq;
using System.Threading.Tasks;
using AWS.Deploy.CLI.ServerMode.Models;
using AWS.Deploy.Common;
using AWS.Deploy.Common.DeploymentManifest;
using AWS.Deploy.Common.IO;
using AWS.Deploy.Orchestration;
using AWS.Deploy.Orchestration.Utilities;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

Expand All @@ -14,20 +20,34 @@ namespace AWS.Deploy.CLI.ServerMode.Controllers
[Route("api/v1/[controller]")]
public class RecipeController : ControllerBase
{
private readonly ICustomRecipeLocator _customRecipeLocator;
private readonly IProjectDefinitionParser _projectDefinitionParser;

public RecipeController(ICustomRecipeLocator customRecipeLocator, IProjectDefinitionParser projectDefinitionParser)
{
_customRecipeLocator = customRecipeLocator;
_projectDefinitionParser = projectDefinitionParser;
}

/// <summary>
/// Gets a summary of the specified Recipe.
/// </summary>
[HttpGet("{recipeId}")]
[SwaggerOperation(OperationId = "GetRecipe")]
[SwaggerResponse(200, type: typeof(RecipeSummary))]
public IActionResult GetRecipe(string recipeId, [FromQuery] string? projectPath = null)
public async Task<IActionResult> GetRecipe(string recipeId, [FromQuery] string? projectPath = null)
{
if (string.IsNullOrEmpty(recipeId))
{
return BadRequest($"A Recipe ID was not provided.");
}

var recipeDefinitions = RecipeHandler.GetRecipeDefinitions();
ProjectDefinition? projectDefinition = null;
if(!string.IsNullOrEmpty(projectPath))
{
projectDefinition = await _projectDefinitionParser.Parse(projectPath);
}
var recipeDefinitions = await RecipeHandler.GetRecipeDefinitions(_customRecipeLocator, projectDefinition);
var selectedRecipeDefinition = recipeDefinitions.FirstOrDefault(x => x.Id.Equals(recipeId));

if (selectedRecipeDefinition == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void SetValueOverride(object valueOverride)
!AllowedValues.Contains(valueOverride.ToString() ?? ""))
throw new InvalidOverrideValueException($"Invalid value for option setting item '{Name}'");

if (valueOverride is bool || valueOverride is int || valueOverride is long)
if (valueOverride is bool || valueOverride is int || valueOverride is long || valueOverride is double)
{
_valueOverride = valueOverride;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task CleanOrphanStacks(List<string> deployedStacks, string projectN
var localStacks = localUserSettings?.LastDeployedStacks?
.FirstOrDefault(x => x.Exists(awsAccountId, awsRegion, projectName));

if (localUserSettings == null || localStacks == null)
if (localUserSettings == null || localStacks == null || localStacks.Stacks == null)
return;

var validStacks = deployedStacks.Intersect(localStacks.Stacks);
Expand Down
38 changes: 27 additions & 11 deletions src/AWS.Deploy.Orchestration/RecipeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AWS.Deploy.Common;
using AWS.Deploy.Common.Recipes;
using AWS.Deploy.Recipes;
using Newtonsoft.Json;
Expand All @@ -12,24 +15,37 @@ namespace AWS.Deploy.Orchestration
{
public class RecipeHandler
{
public static List<RecipeDefinition> GetRecipeDefinitions()
public static async Task<List<RecipeDefinition>> GetRecipeDefinitions(ICustomRecipeLocator customRecipeLocator, ProjectDefinition? projectDefinition)
{
var recipeDefinitionsPath = RecipeLocator.FindRecipeDefinitionsPath();
IEnumerable<string> recipeDefinitionsPaths = new List<string> { RecipeLocator.FindRecipeDefinitionsPath() };
if(projectDefinition != null)
{
var targetApplicationFullPath = new DirectoryInfo(projectDefinition.ProjectPath).FullName;
var solutionDirectoryPath = !string.IsNullOrEmpty(projectDefinition.ProjectSolutionPath) ?
new DirectoryInfo(projectDefinition.ProjectSolutionPath).Parent.FullName : string.Empty;

var customPaths = await customRecipeLocator.LocateCustomRecipePaths(targetApplicationFullPath, solutionDirectoryPath);
recipeDefinitionsPaths = recipeDefinitionsPaths.Union(customPaths);
}

var recipeDefinitions = new List<RecipeDefinition>();

try
{
foreach (var recipeDefinitionFile in Directory.GetFiles(recipeDefinitionsPath, "*.recipe", SearchOption.TopDirectoryOnly))
foreach(var recipeDefinitionsPath in recipeDefinitionsPaths)
{
try
{
var content = File.ReadAllText(recipeDefinitionFile);
var definition = JsonConvert.DeserializeObject<RecipeDefinition>(content);
recipeDefinitions.Add(definition);
}
catch (Exception e)
foreach (var recipeDefinitionFile in Directory.GetFiles(recipeDefinitionsPath, "*.recipe", SearchOption.TopDirectoryOnly))
{
throw new Exception($"Failed to Deserialize Recipe Definition [{recipeDefinitionFile}]: {e.Message}", e);
try
{
var content = File.ReadAllText(recipeDefinitionFile);
var definition = JsonConvert.DeserializeObject<RecipeDefinition>(content);
recipeDefinitions.Add(definition);
}
catch (Exception e)
{
throw new Exception($"Failed to Deserialize Recipe Definition [{recipeDefinitionFile}]: {e.Message}", e);
}
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions src/AWS.Deploy.Recipes.CDK.Common/CDKRecipeSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,5 @@ public static void RegisterStack<C>(Stack stack, IRecipeProps<C> recipeConfigura
stack.TemplateOptions.Description = $"{Constants.CloudFormationIdentifier.STACK_DESCRIPTION_PREFIX}: {stack.TemplateOptions.Description}";
}
}

/// <summary>
/// TODO remove this function once all recipes have migrated to IRecipeProps
/// </summary>
/// <typeparam name="C"></typeparam>
/// <param name="stack"></param>
/// <param name="recipeConfiguration"></param>
public static void RegisterStack<C>(Stack stack, RecipeConfiguration<C> recipeConfiguration)
{
// Set the AWS .NET deployment tool tag which also identifies the recipe used.
stack.Tags.SetTag(Constants.CloudFormationIdentifier.STACK_TAG, $"{recipeConfiguration.RecipeId}");

// Serializes all AWS .NET deployment tool settings.
var json = JsonSerializer.Serialize(recipeConfiguration.Settings, new JsonSerializerOptions { WriteIndented = false });

Dictionary<string, object> metadata;
if (stack.TemplateOptions.Metadata?.Count > 0)
{
metadata = new Dictionary<string, object>(stack.TemplateOptions.Metadata);
}
else
{
metadata = new Dictionary<string, object>();
}

// Save the settings, recipe id and version as metadata to the CloudFormation template.
metadata[Constants.CloudFormationIdentifier.STACK_METADATA_SETTINGS] = json;
metadata[Constants.CloudFormationIdentifier.STACK_METADATA_RECIPE_ID] = recipeConfiguration.RecipeId;
metadata[Constants.CloudFormationIdentifier.STACK_METADATA_RECIPE_VERSION] = recipeConfiguration.RecipeVersion;

// For the CDK to pick up the changes to the metadata .NET Dictionary you have to reassign the Metadata property.
stack.TemplateOptions.Metadata = metadata;

// CloudFormation tags are propagated to resources created by the stack. In case of Beanstalk deployment a second CloudFormation stack is
// launched which will also have the AWS .NET deployment tool tag. To differentiate these additional stacks a special AWS .NET deployment tool prefix
// is added to the description.
if (string.IsNullOrEmpty(stack.TemplateOptions.Description))
{
stack.TemplateOptions.Description = Constants.CloudFormationIdentifier.STACK_DESCRIPTION_PREFIX;
}
else
{
stack.TemplateOptions.Description = $"{Constants.CloudFormationIdentifier.STACK_DESCRIPTION_PREFIX}: {stack.TemplateOptions.Description}";
}
}
}
}
94 changes: 0 additions & 94 deletions src/AWS.Deploy.Recipes.CDK.Common/RecipeConfiguration.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ namespace AspNetAppAppRunner
{
public class AppStack : Stack
{
private readonly Configuration _configuration;

internal AppStack(Construct scope, IDeployToolStackProps<Configuration> props)
: base(scope, props.StackName, props)
{
_configuration = props.RecipeProps.Settings;

// Setup callback for generated construct to provide access to customize CDK properties before creating constructs.
CDKRecipeCustomizer<Recipe>.CustomizeCDKProps += CustomizeCDKProps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ namespace AspNetAppEcsFargate
{
public class AppStack : Stack
{
private readonly Configuration _configuration;

internal AppStack(Construct scope, IDeployToolStackProps<Configuration> props)
: base(scope, props.StackName, props)
{
_configuration = props.RecipeProps.Settings;

// Setup callback for generated construct to provide access to customize CDK properties before creating constructs.
CDKRecipeCustomizer<Recipe>.CustomizeCDKProps += CustomizeCDKProps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum ScalingTypeEnum { Cpu, Memory, Request }



public int MemoryTypeTargetUtilizationPercent { get; set; } = 70;
public double MemoryTypeTargetUtilizationPercent { get; set; } = 70;

public int MemoryTypeScaleInCooldownSeconds { get; set; } = defaultCooldown;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Collections.Generic;
using Amazon.CDK;
using Amazon.CDK.AWS.ElasticBeanstalk;
using Amazon.CDK.AWS.IAM;
using Amazon.CDK.AWS.S3.Assets;
using AWS.Deploy.Recipes.CDK.Common;

using AspNetAppElasticBeanstalkLinux.Configurations;


namespace AspNetAppElasticBeanstalkLinux
{
public class AppStack : Stack
{
private readonly Configuration _configuration;

internal AppStack(Construct scope, IDeployToolStackProps<Configuration> props)
: base(scope, props.StackName, props)
{
_configuration = props.RecipeProps.Settings;

// Setup callback for generated construct to provide access to customize CDK properties before creating constructs.
CDKRecipeCustomizer<Recipe>.CustomizeCDKProps += CustomizeCDKProps;

Expand All @@ -39,17 +44,13 @@ internal AppStack(Construct scope, IDeployToolStackProps<Configuration> props)
/// <param name="evnt"></param>
private void CustomizeCDKProps(CustomizePropsEventArgs<Recipe> evnt)
{
// Example of how to customize the container image definition to include environment variables to the running applications.
// Example of how to customize the Beanstalk Environment.
//
//if (string.Equals(evnt.ResourceLogicalName, nameof(evnt.Construct.AppContainerDefinition)))
//if (string.Equals(evnt.ResourceLogicalName, nameof(evnt.Construct.BeanstalkEnvironment)))
//{
// if(evnt.Props is ContainerDefinitionOptions props)
// if (evnt.Props is CfnEnvironmentProps props)
// {
// Console.WriteLine("Customizing AppContainerDefinition");
// if (props.Environment == null)
// props.Environment = new Dictionary<string, string>();

// props.Environment["EXAMPLE_ENV1"] = "EXAMPLE_VALUE1";
// Console.WriteLine("Customizing Beanstalk Environment");
// }
//}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ private void ConfigureBeanstalkEnvironment(Configuration settings)
});
}

BeanstalkEnvironment = new CfnEnvironment(this, "Environment", new CfnEnvironmentProps
BeanstalkEnvironment = new CfnEnvironment(this, nameof(BeanstalkEnvironment), InvokeCustomizeCDKPropsEvent(nameof(BeanstalkEnvironment), this, new CfnEnvironmentProps
{
EnvironmentName = settings.EnvironmentName,
ApplicationName = settings.BeanstalkApplication.ApplicationName,
PlatformArn = settings.ElasticBeanstalkPlatformArn,
OptionSettings = optionSettingProperties.ToArray(),
// This line is critical - reference the label created in this same stack
VersionLabel = ApplicationVersion.Ref,
});
}));
}
}
}
Loading

0 comments on commit b64e38d

Please sign in to comment.