public async Task NativeDependencyExample() { var fullPath = GetTestProjectPath("NativeDependencyExample"); var command = new PackageCommand(new ConsoleToolLogger(), fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp1.0"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); try { Assert.True(created); using (var archive = ZipFile.OpenRead(command.OutputPackageFileName)) { Assert.True(archive.GetEntry("System.Diagnostics.TraceSource.dll") != null, "Failed to find System.Diagnostics.TraceSource.dll"); Assert.True(archive.GetEntry("libuv.so") != null, "Failed to find libuv.so"); ValidateNoRuntimeFolder(archive); MakeSureCorrectAssemblyWasPicked(archive, fullPath, "System.Diagnostics.TraceSource.dll", "runtimes/unix/lib/netstandard1.3"); MakeSureCorrectAssemblyWasPicked(archive, fullPath, "libuv.so", "runtimes/rhel-x64/native"); } } finally { if (File.Exists(command.OutputPackageFileName)) { File.Delete(command.OutputPackageFileName); } } }
public async Task ExpandEnvironmentVariable() { const string envName = "EB_OUTPUT_PACKAGE"; var outputPackage = Path.GetTempFileName(); Environment.SetEnvironmentVariable(envName, outputPackage); try { var packageCommand = new PackageCommand(new ConsoleToolLogger(), TestUtilities.TestBeanstalkWebAppPath, new string[] { "--config-file", "env-eb-config.json" }); await packageCommand.ExecuteAsync(); var manifest = ReadManifestFromPackage(outputPackage); var appInManifest = manifest["deployments"]["aspNetCoreWeb"][0]; Assert.NotNull(appInManifest); var appInManifestParameters = appInManifest["parameters"]; Assert.Equal(".", appInManifestParameters["appBundle"].ToString()); Assert.Equal("/", appInManifestParameters["iisPath"].ToString()); Assert.Equal("Default Web Site", appInManifestParameters["iisWebSite"].ToString()); } finally { Environment.SetEnvironmentVariable(envName, null); } }
public async Task NpgsqlTest() { var fullPath = GetTestProjectPath("NpgsqlExample"); var command = new PackageCommand(new ConsoleToolLogger(), fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp1.0"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); try { Assert.True(created); using (var archive = ZipFile.OpenRead(command.OutputPackageFileName)) { Assert.True(archive.GetEntry("Npgsql.dll") != null, "Failed to find Npgsql.dll"); Assert.True(archive.GetEntry("System.Net.NetworkInformation.dll") != null, "Failed to find System.Net.NetworkInformation.dll"); Assert.True(archive.GetEntry("runtimes/linux/lib/netstandard1.3/System.Net.NetworkInformation.dll") == null, "runtimes/linux/lib/netstandard1.3/System.Net.NetworkInformation.dll should not be zip file."); ValidateNoRuntimeFolder(archive); } } finally { if (File.Exists(command.OutputPackageFileName)) { File.Delete(command.OutputPackageFileName); } } }
public void Execute(ScriptType type) { PackageCommand command = null; switch (type) { case ScriptType.BEFORE_INSTALL: command = BeforeInstall; break; case ScriptType.AFTER_INSTALL: command = AfterInstall; break; default: break; } Utils.CrossPlatformAction( // Windows-based systems () => { Utils.RunShellCommand(command.WindowsCommand); }, // Unix-based systems () => { Utils.RunShellCommand(command.UnixCommand); }); }
public async Task NativeDependency2Example() { var fullPath = GetTestProjectPath("NativeDependencyExample2"); var command = new PackageCommand(new ConsoleToolLogger(), fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp2.1"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); try { Assert.True(created); using (var archive = ZipFile.OpenRead(command.OutputPackageFileName)) { Assert.True(archive.GetEntry("libgit2-b0d9952.so") != null, "Failed to find libgit2-b0d9952.so"); ValidateNoRuntimeFolder(archive); MakeSureCorrectAssemblyWasPicked(archive, "libgit2sharp.nativebinaries", "1.0.226", "libgit2-b0d9952.so", "runtimes/rhel-x64/native/"); } } finally { if (File.Exists(command.OutputPackageFileName)) { File.Delete(command.OutputPackageFileName); } } }
public async Task DeployWithPackage() { var assembly = this.GetType().GetTypeInfo().Assembly; string packageZip = Path.GetTempFileName() + ".zip"; var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestFunction"); var packageCommand = new PackageCommand(new ConsoleToolLogger(), fullPath, new string[0]); packageCommand.OutputPackageFileName = packageZip; packageCommand.Configuration = "Release"; packageCommand.TargetFramework = "netcoreapp1.0"; await packageCommand.ExecuteAsync(); var deployCommand = new DeployFunctionCommand(new ConsoleToolLogger(), Path.GetTempPath(), new string[0]); deployCommand.FunctionName = "test-function-" + DateTime.Now.Ticks; deployCommand.Handler = "TestFunction::TestFunction.Function::ToUpper"; deployCommand.Timeout = 10; deployCommand.MemorySize = 512; deployCommand.Role = this._roleArn; deployCommand.Package = packageZip; deployCommand.Runtime = "dotnetcore1.0"; deployCommand.Region = "us-east-1"; deployCommand.DisableInteractive = true; var created = await deployCommand.ExecuteAsync(); try { Assert.True(created); var invokeRequest = new InvokeRequest { FunctionName = deployCommand.FunctionName, LogType = LogType.Tail, Payload = "\"hello world\"" }; var response = await deployCommand.LambdaClient.InvokeAsync(invokeRequest); var payload = new StreamReader(response.Payload).ReadToEnd(); Assert.Equal("\"HELLO WORLD\"", payload); } finally { if (File.Exists(packageZip)) { File.Delete(packageZip); } if (created) { await deployCommand.LambdaClient.DeleteFunctionAsync(deployCommand.FunctionName); } } }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); ConfigureCommand.Initialize(this); ValidateCommand.Initialize(this); PackageCommand.Initialize(this); TestCommand.Initialize(this); PushCommand.Initialize(this); }
public async Task CreateArmPackage() { var assembly = this.GetType().GetTypeInfo().Assembly; var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/TestFunction"); var command = new PackageCommand(new TestToolLogger(_testOutputHelper), fullPath, new string[0]); command.DisableInteractive = true; command.Architecture = LambdaConstants.ARCHITECTURE_ARM64; command.OutputPackageFileName = Path.GetTempFileName(); var created = await command.ExecuteAsync(); Assert.True(created); Assert.Equal("linux-arm64", GetRuntimeFromBundle(command.OutputPackageFileName)); File.Delete(command.OutputPackageFileName); }
public async Task UseNewtonsoft10() { var fullPath = GetTestProjectPath("UseNewtonsoft10"); var logger = new TestToolLogger(); var command = new PackageCommand(logger, fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp1.0"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); Assert.False(created); Assert.True(logger.Buffer.ToLower().Contains("error: netstandard.library 1.6.1 is used for target framework netcoreapp1.1")); Assert.True(logger.Buffer.ToLower().Contains("error: newtonsoft.json : 10.0.2")); }
public async Task ExplicitIISSettings() { var outputPackage = Path.GetTempFileName(); var packageCommand = new PackageCommand(new ConsoleToolLogger(), TestUtilities.TestBeanstalkWebAppPath, new string[] { "--output-package", outputPackage, "--iis-website", "The WebSite", "--app-path", "/child" }); packageCommand.DisableInteractive = true; await packageCommand.ExecuteAsync(); var manifest = ReadManifestFromPackage(outputPackage); var appInManifest = manifest["deployments"]["aspNetCoreWeb"][0]; Assert.NotNull(appInManifest); var appInManifestParameters = appInManifest["parameters"]; Assert.Equal(".", appInManifestParameters["appBundle"].ToString()); Assert.Equal("/child", appInManifestParameters["iisPath"].ToString()); Assert.Equal("The WebSite", appInManifestParameters["iisWebSite"].ToString()); }
public async Task Use11ASPNetCoreDependencies() { var fullPath = GetTestProjectPath("Use11ASPNetCoreDependencies"); var logger = new TestToolLogger(); var command = new PackageCommand(logger, fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp1.0"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); Assert.False(created); Assert.True(logger.Buffer.ToLower().Contains("error: netstandard.library 1.6.1 is used for target framework netcoreapp1.1")); Assert.True(logger.Buffer.ToLower().Contains("error: microsoft.aspnetcore.diagnostics : 1.1.1")); Assert.True(logger.Buffer.ToLower().Contains("error: microsoft.extensions.fileproviders.embedded : 1.1.0")); }
public async Task SqlClientTest() { var fullPath = GetTestProjectPath("SQLServerClientExample"); var command = new PackageCommand(new ConsoleToolLogger(), fullPath, new string[0]); command.DisableInteractive = true; command.Configuration = "Release"; command.TargetFramework = "netcoreapp1.0"; command.OutputPackageFileName = Path.GetTempFileName() + ".zip"; var created = await command.ExecuteAsync(); try { Assert.True(created); using (var archive = ZipFile.OpenRead(command.OutputPackageFileName)) { Assert.True(archive.GetEntry("System.Data.SqlClient.dll") != null, "Failed to find System.Data.SqlClient.dll"); Assert.True(archive.GetEntry("System.IO.Pipes.dll") != null, "Failed to find System.IO.Pipes.dll"); Assert.True(archive.GetEntry("runtimes/linux/lib/netstandard1.3/System.Data.SqlClient.dll") == null, "runtimes/linux/lib/netstandard1.3/System.Data.SqlClient.dll should not be zip file."); ValidateNoRuntimeFolder(archive); MakeSureCorrectAssemblyWasPicked(archive, fullPath, "System.Data.SqlClient.dll", "runtimes/unix/lib/netstandard1.3"); MakeSureCorrectAssemblyWasPicked(archive, fullPath, "System.IO.Pipes.dll", "runtimes/unix/lib/netstandard1.3"); } } finally { if (File.Exists(command.OutputPackageFileName)) { File.Delete(command.OutputPackageFileName); } } }
protected CommandBase(PackageCommand id) { Command = new OleMenuCommand((s, e) => Execute(), new CommandID(GuidList.guidRebracerCmdSet, (int)id)); }
public static void Main(string[] args) { try { 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 "--help": case "--h": case "help": PrintUsageHeader(); 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) { command.EnableInteractive = true; 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); } }
public async Task CreateEnvironmentWithPackageTest() { var application = "TestApp"; var environment = "TestEnv"; var solutionStack = "TestWindowsStack"; var iamProfile = "arn:aws:fake-profile"; var mockS3Client = new Mock <IAmazonS3>(); var calls = new Dictionary <string, int>(); Action <string> addCall = x => { if (calls.ContainsKey(x)) { calls[x] = calls[x] + 1; } else { calls[x] = 1; } }; var mockEbClient = new Mock <IAmazonElasticBeanstalk>(); mockEbClient.Setup(client => client.DescribeApplicationsAsync(It.IsAny <DescribeApplicationsRequest>(), It.IsAny <CancellationToken>())) .Callback <DescribeApplicationsRequest, CancellationToken>((request, token) => { Assert.Equal(application, request.ApplicationNames[0]); }) .Returns((DescribeApplicationsRequest r, CancellationToken token) => { addCall("DescribeApplicationsAsync"); return(Task.FromResult(new DescribeApplicationsResponse())); }); mockEbClient.Setup(client => client.CreateStorageLocationAsync(It.IsAny <CancellationToken>())) .Returns((CancellationToken token) => { addCall("CreateStorageLocationAsync"); return(Task.FromResult(new CreateStorageLocationResponse { S3Bucket = "TestBucket" })); }); mockEbClient.Setup(client => client.DescribeEventsAsync(It.IsAny <DescribeEventsRequest>(), It.IsAny <CancellationToken>())) .Callback <DescribeEventsRequest, CancellationToken>((request, token) => { Assert.Equal(application, request.ApplicationName); Assert.Equal(environment, request.EnvironmentName); }) .Returns((DescribeEventsRequest r, CancellationToken token) => { addCall("DescribeEventsAsync"); var response = new DescribeEventsResponse { Events = new List <EventDescription> { new EventDescription { ApplicationName = application, EnvironmentName = environment, Message = "Dummy Message", EventDate = DateTime.Now } } }; return(Task.FromResult(response)); }); mockEbClient.Setup(client => client.CreateApplicationAsync(It.IsAny <CreateApplicationRequest>(), It.IsAny <CancellationToken>())) .Callback <CreateApplicationRequest, CancellationToken>((request, token) => { Assert.Equal(application, request.ApplicationName); }) .Returns((CreateApplicationRequest r, CancellationToken token) => { addCall("CreateApplicationAsync"); return(Task.FromResult(new CreateApplicationResponse())); }); mockEbClient.Setup(client => client.CreateEnvironmentAsync(It.IsAny <CreateEnvironmentRequest>(), It.IsAny <CancellationToken>())) .Callback <CreateEnvironmentRequest, CancellationToken>((request, token) => { Assert.Equal(application, request.ApplicationName); Assert.Equal(environment, request.EnvironmentName); Assert.Equal(solutionStack, request.SolutionStackName); var iamSetting = request.OptionSettings.FirstOrDefault(x => string.Equals(x.OptionName, "IamInstanceProfile") && string.Equals(x.Namespace, "aws:autoscaling:launchconfiguration")); Assert.Equal(iamSetting.Value, iamProfile); var xraySetting = request.OptionSettings.FirstOrDefault(x => string.Equals(x.OptionName, "XRayEnabled") && string.Equals(x.Namespace, "aws:elasticbeanstalk:xray")); Assert.Equal(xraySetting.Value.ToLower(), "true"); }) .Returns((CreateEnvironmentRequest r, CancellationToken token) => { addCall("CreateEnvironmentAsync"); return(Task.FromResult(new CreateEnvironmentResponse())); }); mockEbClient.Setup(client => client.DescribeEnvironmentsAsync(It.IsAny <DescribeEnvironmentsRequest>(), It.IsAny <CancellationToken>())) .Returns((DescribeEnvironmentsRequest r, CancellationToken token) => { addCall("DescribeEnvironmentsAsync"); return(Task.FromResult(new DescribeEnvironmentsResponse { Environments = new List <EnvironmentDescription> { new EnvironmentDescription { ApplicationName = application, EnvironmentName = environment, DateCreated = DateTime.Now.AddMinutes(-1), DateUpdated = DateTime.Now, Status = EnvironmentStatus.Ready } } })); }); var outputPackage = Path.GetTempFileName().Replace(".tmp", ".zip"); var packageCommand = new PackageCommand(new ConsoleToolLogger(), TestUtilities.TestBeanstalkWebAppPath, new string[] { "--output-package", outputPackage, "--iis-website", "The WebSite", "--app-path", "/child" }); packageCommand.DisableInteractive = true; await packageCommand.ExecuteAsync(); var deployCommand = new DeployEnvironmentCommand(new ConsoleToolLogger(), Path.GetTempPath(), new string[] { "-app", application, "-env", environment, "--solution-stack", solutionStack, "--instance-profile", iamProfile, "--region", "us-moq-1", "--enable-xray", "true", "--package", outputPackage }); deployCommand.DisableInteractive = true; deployCommand.EBClient = mockEbClient.Object; deployCommand.S3Client = mockS3Client.Object; await deployCommand.ExecuteAsync(); Assert.Null(deployCommand.LastToolsException); Assert.True(calls.ContainsKey("CreateApplicationAsync")); Assert.True(calls.ContainsKey("CreateEnvironmentAsync")); }
public async Task PackageFunctionAsLocalImageThenDeployWithDifferentECRTag() { var assembly = this.GetType().GetTypeInfo().Assembly; var toolLogger = new TestToolLogger(_testOutputHelper); var fullPath = Path.GetFullPath(Path.GetDirectoryName(assembly.Location) + "../../../../../../testapps/ImageBasedProjects/TestSimpleImageProject"); var packageCommand = new PackageCommand(toolLogger, fullPath, new string[0]); packageCommand.Region = TEST_REGION; packageCommand.DockerImageTag = $"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags1"; packageCommand.DisableInteractive = true; packageCommand.PackageType = "image"; var packageSuccess = await packageCommand.ExecuteAsync(); Assert.True(packageSuccess); Assert.Contains($"Packaged project as image: \"{packageCommand.DockerImageTag}\"", toolLogger.Buffer); Assert.DoesNotContain("Pushing image to ECR repository", toolLogger.Buffer); var functionName = "test-package-then-deploy-differenttags-" + DateTime.Now.Ticks; toolLogger.ClearBuffer(); var deployCommand = new DeployFunctionCommand(toolLogger, fullPath, new string[0]); deployCommand.FunctionName = functionName; deployCommand.Region = TEST_REGION; deployCommand.Role = await TestHelper.GetTestRoleArnAsync(); deployCommand.LocalDockerImage = packageCommand.DockerImageTag; deployCommand.DockerImageTag = $"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags2"; deployCommand.DisableInteractive = true; var deploySuccess = await deployCommand.ExecuteAsync(); try { Assert.True(deploySuccess); Assert.DoesNotContain("docker build", toolLogger.Buffer); Assert.Contains($"{TEST_ECR_REPOSITORY}:packageanddeploywithdifferenttags2 Push Complete.", toolLogger.Buffer); toolLogger.ClearBuffer(); var invokeCommand = new InvokeFunctionCommand(toolLogger, fullPath, new string[0]); invokeCommand.FunctionName = deployCommand.FunctionName; invokeCommand.Payload = "hello world"; invokeCommand.Region = TEST_REGION; await invokeCommand.ExecuteAsync(); // Make sure waiting works. Assert.Contains("... Waiting", toolLogger.Buffer); Assert.Contains("HELLO WORLD", toolLogger.Buffer); } finally { if (deploySuccess) { await deployCommand.LambdaClient.DeleteFunctionAsync(deployCommand.FunctionName); } } }