private async Task <bool> Deploy( Settings settings, DryRunLevel?dryRun, string outputFilename, bool allowDataLoos, bool protectStack ) { var stopwatch = Stopwatch.StartNew(); // read input file Console.WriteLine(); Console.WriteLine($"Processing module: {settings.ModuleFileName}"); var source = await File.ReadAllTextAsync(settings.ModuleFileName); // preprocess file var tokenStream = new ModelPreprocessor(settings).Preprocess(source); if (ErrorCount > 0) { return(false); } // parse yaml module file var module = new ModelParser(settings).Parse(tokenStream, skipCompile: dryRun == DryRunLevel.CloudFormation); if (ErrorCount > 0) { return(false); } // generate cloudformation template var stack = new ModelGenerator().Generate(module); if (ErrorCount > 0) { return(false); } // serialize stack to disk var result = true; var outputPath = Path.Combine(settings.WorkingDirectory, outputFilename); var template = new JsonStackSerializer().Serialize(stack); File.WriteAllText(outputPath, template); if (dryRun == null) { result = await new StackUpdater().Deploy(module, template, allowDataLoos, protectStack); try { File.Delete(outputPath); } catch { } } Console.WriteLine($"Done (duration: {stopwatch.Elapsed:c})"); return(result); }
public static void Main() { Stack stack = BuildStack(); var serializer = new JsonStackSerializer(); var template = serializer.Serialize(stack); File.WriteAllText("cloudformation.template", template); FnExamples(); }
private string GenerateCloudFormationTemplateChecksum() { // convert stack to string using the Humidifier serializer var json = new JsonStackSerializer().Serialize(_stack); // parse json into a generic object var value = JObject.Parse(json); // convert value to json, but sort the properties to achieve a stable hash return(OrderFields(value).ToString(Formatting.None).ToMD5Hash()); }
private async Task <bool> Deploy( Settings settings, DryRunLevel?dryRun, string outputCloudFormationFilePath, bool allowDataLoos, bool protectStack, bool skipAssemblyValidation ) { var stopwatch = Stopwatch.StartNew(); // read input file Console.WriteLine(); Console.WriteLine($"Processing module: {settings.ModuleSource}"); var source = await File.ReadAllTextAsync(settings.ModuleSource); // preprocess file var tokenStream = new ModelPreprocessor(settings).Preprocess(source); if (HasErrors) { return(false); } // parse yaml module file var module = new ModelParser().Parse(tokenStream); if (HasErrors) { return(false); } // reset settings when the 'LambdaSharp` module is being deployed if (module.Name == "LambdaSharp") { settings.Reset(); } else { await PopulateEnvironmentSettingsAsync(settings); if (settings.EnvironmentVersion == null) { // check that LambdaSharp Environment & Tool versions match AddError("could not determine the LambdaSharp Environment version", new LambdaSharpDeploymentTierSetupException(settings.Tier)); } else { if (settings.EnvironmentVersion != settings.ToolVersion) { AddError($"LambdaSharp Tool (v{settings.ToolVersion}) and Environment (v{settings.EnvironmentVersion}) versions do not match", new LambdaSharpDeploymentTierSetupException(settings.Tier)); } } } // validate module new ModelValidation(settings).Process(module); if (HasErrors) { return(false); } // resolve all imported parameters new ModelImportProcessor(settings).Process(module); // package all functions new ModelFunctionPackager(settings).Process( module, settings.ToolVersion, skipCompile: dryRun == DryRunLevel.CloudFormation, skipAssemblyValidation: skipAssemblyValidation ); // package all files new ModelFilesPackager(settings).Process(module); // compile module file var compiledModule = new ModelConverter(settings).Process(module); if (HasErrors) { return(false); } // generate cloudformation template var stack = new ModelGenerator(settings).Generate(compiledModule); // upload assets if (HasErrors) { return(false); } await new ModelUploader(settings).ProcessAsync(compiledModule, skipUpload: dryRun != null); // serialize stack to disk var result = true; var template = new JsonStackSerializer().Serialize(stack); var outputCloudFormationDirectory = Path.GetDirectoryName(outputCloudFormationFilePath); if (outputCloudFormationDirectory != "") { Directory.CreateDirectory(outputCloudFormationDirectory); } File.WriteAllText(outputCloudFormationFilePath, template); if (dryRun == null) { result = await new ModelUpdater(settings).Deploy(compiledModule, outputCloudFormationFilePath, allowDataLoos, protectStack); if (settings.OutputDirectory == settings.WorkingDirectory) { try { File.Delete(outputCloudFormationFilePath); } catch { } } } Console.WriteLine($"Done (duration: {stopwatch.Elapsed:c})"); return(result); }