From bd9769d03207ce56e868d2c347ef277b63909564 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Wed, 5 Jun 2019 13:00:35 -0700 Subject: [PATCH] Code clean-up in tests (#195) --- .../DotNetCoreEndToEndTests.cs | 6 - .../NodeEndToEndTests.cs | 185 ++++++++++------- .../PhpEndToEndTests.cs | 22 +- .../PythonEndToEndTests.cs | 196 ++++++++++++------ 4 files changed, 254 insertions(+), 155 deletions(-) diff --git a/tests/Oryx.Integration.Tests/DotNetCoreEndToEndTests.cs b/tests/Oryx.Integration.Tests/DotNetCoreEndToEndTests.cs index a7afdfe7a5..1788071d7c 100644 --- a/tests/Oryx.Integration.Tests/DotNetCoreEndToEndTests.cs +++ b/tests/Oryx.Integration.Tests/DotNetCoreEndToEndTests.cs @@ -39,7 +39,6 @@ public DotNetCoreEndToEndTestsBase(ITestOutputHelper output, TestTempDirTestFixt } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion10Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion10Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) @@ -92,7 +91,6 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion11Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion11Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) @@ -189,7 +187,6 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion20Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion20Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) @@ -242,7 +239,6 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion21Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion21Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) @@ -710,7 +706,6 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion22Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion22Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) @@ -994,7 +989,6 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( } [Trait("category", "dotnetcore")] - [Trait("platform", "dotnet")] public class DotNetCoreRuntimeVersion30Tests : DotNetCoreEndToEndTestsBase { public DotNetCoreRuntimeVersion30Tests(ITestOutputHelper output, TestTempDirTestFixture testTempDirTestFixture) diff --git a/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs b/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs index 22552234c2..73acc664cf 100644 --- a/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs +++ b/tests/Oryx.Integration.Tests/NodeEndToEndTests.cs @@ -68,7 +68,6 @@ public async Task CanBuildAndRunNodeApp_UsingZippedNodeModules_WithoutExtracting .AddCommand(DefaultStartupFilePath) .AddDirectoryDoesNotExistCheck("/node_modules") .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand( $"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs " + @@ -120,12 +119,10 @@ public async Task CanBuildAndRunNodeApp_OnSecondBuild_AfterZippingNodeModules_In var appName = "webfrontend"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand( $"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs " + @@ -150,7 +147,7 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( new[] { "-c", - script + runScript }, async (hostPort) => { @@ -178,12 +175,10 @@ public async Task CanBuildAndRunNodeApp_OnSecondBuild_AfterNotZippingNodeModules var appName = "webfrontend"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand($"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs --language-version {nodeVersion}") .AddCommand( @@ -208,7 +203,7 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( new[] { "-c", - script + runScript }, async (hostPort) => { @@ -226,8 +221,10 @@ public async Task CanBuildAndRun_NodeApp(string nodeVersion) var appName = "webfrontend"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -236,15 +233,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -298,8 +299,10 @@ public async Task NodeStartupScript_UsesPortEnvironmentVariableValue() var appName = "webfrontend"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"export PORT={ContainerPort}") .AddCommand($"oryx -appPath {appDir}") .AddCommand(DefaultStartupFilePath) @@ -309,15 +312,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -334,8 +341,10 @@ public async Task NodeStartupScript_UsesSuppliedBindingPort_EvenIfPortEnvironmen var appName = "webfrontend"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"export PORT=9095") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) @@ -345,15 +354,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -371,8 +384,10 @@ public async Task CanBuildAndRunNodeApp_UsingYarnForBuild_AndExplicitOutputFile( var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; var startupFilePath = "/tmp/startup.sh"; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -output {startupFilePath} -bindPort {ContainerPort}") .AddCommand(startupFilePath) .ToString(); @@ -381,10 +396,10 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", new[] { "-c", buildScript }, $"oryxdevms/node-{nodeVersion}", ContainerPort, - "/bin/sh", new[] { "-c", script }, + "/bin/sh", new[] { "-c", runScript }, async (hostPort) => { var data = await _httpClient.GetStringAsync($"http://localhost:{hostPort}/"); @@ -401,8 +416,10 @@ public async Task CanBuildNodeAppUsingScriptsNodeInPackageJson() var nodeVersion = "10.14"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -411,15 +428,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -436,8 +457,10 @@ public async Task Node_Lab2AppServiceApp() var nodeVersion = "10.14"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -446,15 +469,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -471,8 +498,10 @@ public async Task Node_SoundCloudNgrxApp() var nodeVersion = "8.11"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand($"npm rebuild node-sass") //remove this once workitem 762584 is done .AddCommand(DefaultStartupFilePath) @@ -482,15 +511,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -509,8 +542,10 @@ public async Task Node_CreateReactAppSample() var nodeVersion = "10.14"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -519,15 +554,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -554,11 +593,9 @@ public async Task Node_CreateReactAppSample_zippedNodeModules(string nodeVersion var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; var runAppScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand( $"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs " + @@ -591,8 +628,10 @@ public async Task Node_CreateReactAppSample_singleImage() var nodeVersion = "10"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand( $"oryx run-script --appPath {appDir} --platform nodejs " + $"--platform-version {nodeVersion} --bindPort {ContainerPort}") @@ -603,8 +642,8 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName: appName, output: _output, volume: volume, - buildCmd: "oryx", - buildArgs: new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + buildCmd: "/bin/sh", + buildArgs: new[] { "-c", buildScript }, runtimeImageName: $"oryxdevms/build", ContainerPort, runCmd: "/bin/sh", @@ -634,9 +673,10 @@ public async Task CanBuildAndRun_NodeExpressApp_UsingSingleImage_AndCustomScript File.WriteAllText(Path.Join(volume.MountedHostDir, customStartupScriptName), "#!/bin/bash\n" + $"PORT={ContainerPort} node server.js\n"); - + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"chmod -x ./{customStartupScriptName}") .AddCommand( $"oryx run-script --appPath {appDir} --platform nodejs " + @@ -648,8 +688,8 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName: appName, output: _output, volume: volume, - buildCmd: "oryx", - buildArgs: new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + buildCmd: "/bin/sh", + buildArgs: new[] { "-c", buildScript }, runtimeImageName: $"oryxdevms/build", ContainerPort, runCmd: "/bin/sh", @@ -676,9 +716,10 @@ public async Task CanBuildAndRun_NodeExpressApp_UsingSingleImage_AndCustomStartu // Create a custom startup command const string customStartupScriptCommand = "'npm start'"; - + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand( $"oryx run-script --appPath {appDir} --platform nodejs " + $"--platform-version {nodeVersion} --userStartupCommand {customStartupScriptCommand} --debug") @@ -689,8 +730,8 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName: appName, output: _output, volume: volume, - buildCmd: "oryx", - buildArgs: new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + buildCmd: "/bin/sh", + buildArgs: new[] { "-c", buildScript }, runtimeImageName: $"oryxdevms/build", ContainerPort, runCmd: "/bin/sh", @@ -723,8 +764,10 @@ public async Task Test_NodeSassExample(string nodeVersion) var appName = "node-sass-example"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l nodejs --language-version {nodeVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -733,15 +776,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "nodejs", "--language-version", nodeVersion }, + "/bin/sh", + new[] + { + "-c", + buildScript + }, $"oryxdevms/node-{nodeVersion}", ContainerPort, "/bin/sh", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -779,11 +826,9 @@ public async Task CanBuildAndRunNodeApp_UsingZippedNodeModules(string compressFo var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; var runAppScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand( $"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs " + @@ -844,10 +889,8 @@ public async Task CanBuildAndRun_NodeApp_WithAppInsights_Configured(string nodeV .AddStringExistsInFileCheck( $"{NodeConstants.InjectedAppInsights}=\"True\"", $"{appDir}/{FilePaths.BuildManifestFileName}") .ToString(); - var runScript = new ShellScriptBuilder() .AddCommand($"export {aIKey}=asdas") - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .AddFileExistsCheck($"{appDir}/oryx-appinsightsloader.js") @@ -908,11 +951,9 @@ public async Task CanBuildAndRunNodeApp_WithDebugger(string nodeVersion) var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; var runAppScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appOutputDir} -remoteDebug -debugPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); - var buildScript = new ShellScriptBuilder() .AddCommand( $"oryx build {appDir} -i /tmp/int -o /tmp/out -l nodejs " + diff --git a/tests/Oryx.Integration.Tests/PhpEndToEndTests.cs b/tests/Oryx.Integration.Tests/PhpEndToEndTests.cs index 6663bf4fff..1a770abab0 100644 --- a/tests/Oryx.Integration.Tests/PhpEndToEndTests.cs +++ b/tests/Oryx.Integration.Tests/PhpEndToEndTests.cs @@ -52,8 +52,10 @@ public async Task TwigExample(string phpVersion) var hostDir = Path.Combine(_hostSamplesDir, "php", appName); var volume = DockerVolume.CreateMirror(hostDir); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l php --language-version {phpVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -output {RunScriptPath}") .AddCommand(RunScriptPath) .ToString(); @@ -61,10 +63,10 @@ public async Task TwigExample(string phpVersion) // Act & Assert await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", new[] { "build", appDir, "-l", "php", "--language-version", phpVersion }, + "/bin/sh", new[] { "-c", buildScript }, $"oryxdevms/php-{phpVersion}", ContainerPort, - "/bin/sh", new[] { "-c", script }, + "/bin/sh", new[] { "-c", runScript }, async (hostPort) => { var data = await _httpClient.GetStringAsync($"http://localhost:{hostPort}/"); @@ -104,8 +106,10 @@ public async Task WordPress51(string phpVersion) var appName = "wordpress"; var volume = DockerVolume.CreateMirror(hostDir); var appDir = volume.ContainerDir; + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l php --language-version {phpVersion}") + .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -output {RunScriptPath}") .AddCommand(RunScriptPath) .ToString(); @@ -113,7 +117,7 @@ public async Task WordPress51(string phpVersion) // Act & Assert await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", new[] { "build", appDir, "-l", "php", "--language-version", phpVersion }, + "/bin/sh", new[] { "-c", buildScript }, $"oryxdevms/php-{phpVersion}", ContainerPort, "/bin/sh", new[] { "-c", runScript }, @@ -145,8 +149,10 @@ public async Task ImagickExample(string phpVersion) var hostDir = Path.Combine(_hostSamplesDir, "php", appName); var volume = DockerVolume.CreateMirror(hostDir); var appDir = volume.ContainerDir; + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l php --language-version {phpVersion}") + .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -output {RunScriptPath}") .AddCommand(RunScriptPath) .ToString(); @@ -154,7 +160,7 @@ public async Task ImagickExample(string phpVersion) // Act & Assert await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", new[] { "build", appDir, "-l", "php", "--language-version", phpVersion }, + "/bin/sh", new[] { "-c", buildScript }, $"oryxdevms/php-{phpVersion}", ContainerPort, "/bin/sh", new[] { "-c", runScript }, diff --git a/tests/Oryx.Integration.Tests/PythonEndToEndTests.cs b/tests/Oryx.Integration.Tests/PythonEndToEndTests.cs index e0b2041e8d..6db60048f2 100644 --- a/tests/Oryx.Integration.Tests/PythonEndToEndTests.cs +++ b/tests/Oryx.Integration.Tests/PythonEndToEndTests.cs @@ -3,13 +3,13 @@ // Licensed under the MIT license. // -------------------------------------------------------------------------------------------- -using Microsoft.Oryx.BuildScriptGenerator.Python; -using Microsoft.Oryx.Common; -using Microsoft.Oryx.Tests.Common; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Microsoft.Oryx.BuildScriptGenerator.Python; +using Microsoft.Oryx.Common; +using Microsoft.Oryx.Tests.Common; using Xunit; using Xunit.Abstractions; @@ -61,8 +61,6 @@ public async Task CanRunPythonApp_UsingEarlierBuiltPackagesDirectory() .AddFileDoesNotExistCheck($"{appDir}/{FilePaths.BuildManifestFileName}") .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") - .AddCommand($"oryx -appPath {appDir} -virtualEnvName {virtualEnvName} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -106,7 +104,6 @@ public async Task CanRunPythonApp_WithoutBuildManifestFile() .AddFileDoesNotExistCheck($"{appDir}/{FilePaths.BuildManifestFileName}") .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -virtualEnvName {virtualEnvName} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -149,8 +146,10 @@ public async Task CanBuildAndRunPythonApp_UsingPython27_AndExplicitOutputStartup var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; var startupFile = "/tmp/startup.sh"; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l python --language-version 2.7") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -output {startupFile} -bindPort {ContainerPort}") .AddCommand(startupFile) .ToString(); @@ -159,15 +158,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "python", "--language-version", "2.7" }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-2.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -191,7 +194,6 @@ public async Task CanBuildAndRun_Python27App_UsingVirtualEnv() // Mimic the commands ran by app service in their derived image. .AddCommand("pip install gunicorn") .AddCommand("pip install flask") - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -237,8 +239,10 @@ public async Task CanBuildAndRunPythonApp_UsingPython37() var appName = "flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l python --language-version 3.7") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -247,15 +251,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -272,8 +280,10 @@ public async Task CanBuildAndRunPythonApp_UsingPython37_AndVirtualEnv() var virtualEnvName = "antenv"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -p virtualenv_name={virtualEnvName}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -282,15 +292,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-p", $"virtualenv_name={virtualEnvName}" }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -325,7 +339,6 @@ public async Task CanBuildAndRunPythonApp_UsingPython37_AndCompressedVirtualEnv( .AddCommand($"cp -rf {tempOutputDir}/* {appOutputDir}") .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -362,7 +375,10 @@ public async Task CanBuildAndRun_DjangoApp_DoingCollectStaticByDefault() var appName = "django-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) @@ -372,15 +388,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -418,8 +438,7 @@ public async Task CanBuildAndRun_DjangoPython37App_UsingVirtualEnv() .AddCommand($"cp -rf /tmp/out/* {appOutputDir}") .ToString(); - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appOutputDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -440,7 +459,7 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( new[] { "-c", - script + runScript }, async (hostPort) => { @@ -474,8 +493,10 @@ public async Task CanBuildAndRunPythonApp_UsingPython36() var appName = "flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l python --language-version 3.6") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -484,15 +505,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "python", "--language-version", "3.6" }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.6", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -508,8 +533,10 @@ public async Task CanBuildAndRun_Tweeter3App() var appName = "tweeter3"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -518,15 +545,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -555,7 +586,6 @@ public async Task BuildWithVirtualEnv_RemovesOryxPackagesDir_FromOlderBuild(stri .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddDirectoryDoesNotExistCheck("__oryx_packages__") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort} -virtualEnvName={virtualEnvName}") .AddCommand(DefaultStartupFilePath) @@ -608,7 +638,6 @@ public async Task CanBuildAndRun_DjangoPython36App_UsingVirtualEnv() .AddBuildCommand($"{appDir} -l python --language-version 3.6 -p virtualenv_name={virtualEnvName}") .ToString(); var runScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -654,8 +683,10 @@ public async Task CanBuildAndRun_DjangoApp_UsingPython36() var appName = "django-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l python --language-version 3.6") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -664,15 +695,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "python", "--language-version", "3.6" }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.6", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -701,12 +736,10 @@ public async Task CanBuildAndRun_MultiPlatformApp_HavingReactAndDjango() var buildScript = new ShellScriptBuilder() .AddCommand("export ENABLE_MULTIPLATFORM_BUILD=true") - .AddCommand($"cd {appDir}") .AddBuildCommand($"{appDir} -l python --language-version 3.7") .ToString(); var runAppScript = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") // User would do this through app settings .AddCommand("export ENABLE_MULTIPLATFORM_BUILD=true") .AddCommand("export DJANGO_SETTINGS_MODULE=\"reactdjango.settings.local_base\"") @@ -771,8 +804,10 @@ public async Task CanBuildAndRun_ShapelyFlaskApp_UsingVirtualEnv(string pythonVe var appName = "shapely-flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir} -l python --language-version {pythonVersion}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -782,15 +817,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "python", "--language-version", pythonVersion }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, imageVersion, ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -808,8 +847,11 @@ public async Task CanBuildAndRun_ShapelyFlaskApp_PackageDir(string pythonVersion var appName = "shapely-flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand( + $"oryx build {appDir} -l python --language-version {pythonVersion} -p packagedir={packageDir}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) .ToString(); @@ -819,15 +861,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir, "-l", "python", "--language-version", pythonVersion, "-p", $"packagedir={packageDir}" }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, imageVersion, ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -852,8 +898,10 @@ public async Task PythonStartupScript_UsesPortEnvironmentVariableValue() var appName = "flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"export PORT={ContainerPort}") .AddCommand($"oryx -appPath {appDir}") .AddCommand(DefaultStartupFilePath) @@ -863,15 +911,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => { @@ -887,8 +939,10 @@ public async Task PythonStartupScript_UsesSuppliedBindingPort_EvenIfPortEnvironm var appName = "flask-app"; var volume = CreateAppVolume(appName); var appDir = volume.ContainerDir; - var script = new ShellScriptBuilder() - .AddCommand($"cd {appDir}") + var buildScript = new ShellScriptBuilder() + .AddCommand($"oryx build {appDir}") + .ToString(); + var runScript = new ShellScriptBuilder() .AddCommand($"export PORT=9095") .AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}") .AddCommand(DefaultStartupFilePath) @@ -898,15 +952,19 @@ await EndToEndTestHelper.BuildRunAndAssertAppAsync( appName, _output, volume, - "oryx", - new[] { "build", appDir }, + "/bin/bash", + new[] + { + "-c", + buildScript + }, "oryxdevms/python-3.7", ContainerPort, "/bin/bash", new[] { "-c", - script + runScript }, async (hostPort) => {