public async Task <IImmutableList <PackageResource> > GetPackageResources( Components.ComponentTree components, string version) { if (_tempDir.Exists) { _tempDir.Delete(true); } _tempDir.Create(); var outputDir = new DirectoryInfo(Path.Combine(_tempDir.FullName, "output")); outputDir.Create(); var template = (await _components .FindAll <ICloudformationComponent>(Components.Direction.In) .Select(x => x.component?.GetCloudformationData(x.tree)) .WhenAll()) .Merge(); var serializer = new Serializer(); await File.WriteAllTextAsync( Path.Combine(_tempDir.FullName, "template.yml"), serializer.Serialize(template)); var cliDocker = Docker.TemporaryContainerFromImage("amazon/aws-cli", false) .WithVolume(Path.Combine(User.GetHome(), ".aws"), "/root/.aws") .WithVolume( _projectSettings.GetRootedPath(_path.FullName), $"/usr/src/app/{_projectSettings.GetRelativePath(_path.FullName)}") .EnvironmentVariable("AWS_ACCESS_KEY_ID", Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID")) .EnvironmentVariable("AWS_SECRET_ACCESS_KEY", Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY")) .WorkDir("/usr/src/app"); await Templates.Extract( "deployment-bucket.yml", Path.Combine(_tempDir.FullName, "deployment-bucket.yml"), Templates.TemplateType.Infrastructure); await cliDocker .WithVolume( Path.Combine(_tempDir.FullName, "deployment-bucket.yml"), "/usr/src/app/template.yml") .Run($"cloudformation deploy --template-file ./template.yml --stack-name {_configuration.Settings.DeploymentStackName} --parameter-overrides DeploymentBucketName={_configuration.Settings.DeploymentBucketName} --no-fail-on-empty-changeset --region {_configuration.Settings.AwsRegion}"); await cliDocker .WithVolume(outputDir.FullName, "/usr/src/app/output") .WithVolume(Path.Combine(_tempDir.FullName, "template.yml"), "/usr/src/app/template.yml") .Run($"cloudformation package --template-file ./template.yml --output-template-file ./output/template.yml --s3-bucket {_configuration.Settings.DeploymentBucketName} --s3-prefix {version} --region {_configuration.Settings.AwsRegion}"); var result = new List <PackageResource>(); foreach (var file in outputDir.EnumerateFiles()) { result.Add(new PackageResource( _projectSettings.GetRelativePath(Path.Combine(_path.FullName, file.Name), components.Path.FullName), await File.ReadAllBytesAsync(file.FullName))); } _tempDir.Delete(true); return(result.ToImmutableList()); }