public async Task TestServerlessPackage() { var logger = new TestToolLogger(); var assembly = this.GetType().GetTypeInfo().Assembly; var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestServerlessWebApp"); var command = new PackageCICommand(logger, fullPath, new string[0]); command.Region = "us-west-2"; command.Configuration = "Release"; command.TargetFramework = "netcoreapp2.1"; command.CloudFormationTemplate = "serverless.template"; command.CloudFormationOutputTemplate = Path.Combine(Path.GetTempPath(), "output-serverless.template"); command.S3Bucket = "serverless-package-test-" + DateTime.Now.Ticks; command.DisableInteractive = true; if (File.Exists(command.CloudFormationOutputTemplate)) { File.Delete(command.CloudFormationOutputTemplate); } await command.S3Client.PutBucketAsync(command.S3Bucket); try { Assert.True(await command.ExecuteAsync()); Assert.True(File.Exists(command.CloudFormationOutputTemplate)); } finally { await AmazonS3Util.DeleteS3BucketWithObjectsAsync(command.S3Client, command.S3Bucket); } }
public async Task TestMissingImageTagServerlessMetadata() { var assembly = this.GetType().GetTypeInfo().Assembly; var toolLogger = new TestToolLogger(_testOutputHelper); var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/ServerlessTemplateExamples"); var command = new PackageCICommand(toolLogger, fullPath, new string[0]); command.Region = TEST_REGION; command.DisableInteractive = true; command.S3Bucket = this._testFixture.Bucket; command.CloudFormationTemplate = "serverless-function-missing-image-tag.template"; command.CloudFormationOutputTemplate = Path.GetTempFileName(); var created = await command.ExecuteAsync(); Assert.True(created); var outputRoot = JsonConvert.DeserializeObject(File.ReadAllText(command.CloudFormationOutputTemplate)) as JObject; { var useDefaultDockerFunction = outputRoot["Resources"]["UseDockerMetadataFunction"]["Properties"] as JObject; Assert.Contains("dkr.ecr", useDefaultDockerFunction["ImageUri"]?.ToString()); Assert.Contains("usedockermetadata:usedockermetadatafunction", useDefaultDockerFunction["ImageUri"]?.ToString()); Assert.EndsWith("latest", useDefaultDockerFunction["ImageUri"]?.ToString()); } }
public async Task TestServerlessPackage() { var logger = new TestToolLogger(); var assembly = this.GetType().GetTypeInfo().Assembly; var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestServerlessWebApp"); var command = new PackageCICommand(logger, fullPath, new string[0]); command.Region = "us-west-2"; command.Configuration = "Release"; command.CloudFormationTemplate = "serverless-arm.template"; command.CloudFormationOutputTemplate = Path.Combine(Path.GetTempPath(), "output-serverless-arm.template"); command.S3Bucket = "serverless-package-test-" + DateTime.Now.Ticks; command.DisableInteractive = true; if (File.Exists(command.CloudFormationOutputTemplate)) { File.Delete(command.CloudFormationOutputTemplate); } await command.S3Client.PutBucketAsync(command.S3Bucket); try { Assert.True(await command.ExecuteAsync()); Assert.True(File.Exists(command.CloudFormationOutputTemplate)); var templateJson = File.ReadAllText(command.CloudFormationOutputTemplate); var templateRoot = JsonConvert.DeserializeObject(templateJson) as JObject; var codeUri = templateRoot["Resources"]["DefaultFunction"]["Properties"]["CodeUri"].ToString(); Assert.False(string.IsNullOrEmpty(codeUri)); var s3Key = codeUri.Split('/').Last(); var transfer = new TransferUtility(command.S3Client); var functionZipPath = Path.GetTempFileName(); await transfer.DownloadAsync(functionZipPath, command.S3Bucket, s3Key); Assert.Equal("linux-arm64", GetRuntimeFromBundle(functionZipPath)); File.Delete(functionZipPath); } finally { await AmazonS3Util.DeleteS3BucketWithObjectsAsync(command.S3Client, command.S3Bucket); } }
public async Task TestMissingDockerFileServerlessMetadata() { var assembly = this.GetType().GetTypeInfo().Assembly; var toolLogger = new TestToolLogger(_testOutputHelper); var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/ServerlessTemplateExamples"); var command = new PackageCICommand(toolLogger, fullPath, new string[0]); command.Region = TEST_REGION; command.DisableInteractive = true; command.S3Bucket = this._testFixture.Bucket; command.CloudFormationTemplate = "serverless-function-missing-dockerfile.template"; command.CloudFormationOutputTemplate = Path.GetTempFileName(); var created = await command.ExecuteAsync(); Assert.False(created); Assert.Contains("Error failed to find file ", toolLogger.Buffer); }
public static void Main(string[] args) { try { PrintToolTitle(); if (args.Length == 0) { PrintUsage(); Environment.Exit(-1); } ICommand command = null; switch (args[0]) { case DeployFunctionCommand.COMMAND_DEPLOY_NAME: command = new DeployFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case InvokeFunctionCommand.COMMAND_NAME: command = new InvokeFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case ListFunctionCommand.COMMAND_NAME: command = new ListFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case DeleteFunctionCommand.COMMAND_NAME: command = new DeleteFunctionCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case GetFunctionConfigCommand.COMMAND_NAME: command = new GetFunctionConfigCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case UpdateFunctionConfigCommand.COMMAND_NAME: command = new UpdateFunctionConfigCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case DeployServerlessCommand.COMMAND_NAME: command = new DeployServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case ListServerlessCommand.COMMAND_NAME: command = new ListServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case DeleteServerlessCommand.COMMAND_NAME: command = new DeleteServerlessCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case PackageCommand.COMMAND_NAME: command = new PackageCommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case PackageCICommand.COMMAND_NAME: command = new PackageCICommand(new ConsoleToolLogger(), Directory.GetCurrentDirectory(), args.Skip(1).ToArray()); break; case "--help": case "--h": case "help": if (args.Length > 1) { PrintUsage(args[1]); } else { PrintUsage(); } break; default: Console.Error.WriteLine($"Unknown command {args[0]}"); PrintUsage(); Environment.Exit(-1); break; } if (command != null) { var success = command.ExecuteAsync().Result; if (!success) { Environment.Exit(-1); } } } catch (LambdaToolsException e) { Console.Error.WriteLine(e.Message); Environment.Exit(-1); } catch (Exception e) { Console.Error.WriteLine($"Unknown error: {e.Message}"); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }