public void OryxBuildImage_Contains_VersionAndCommit_Information() { var agentOS = Environment.GetEnvironmentVariable("AGENT_OS"); var gitCommitID = Environment.GetEnvironmentVariable("BUILD_SOURCEVERSION"); var buildNumber = Environment.GetEnvironmentVariable("BUILD_BUILDNUMBER"); var expectedOryxVersion = string.Concat(Settings.OryxVersion, buildNumber); // we cant always rely on gitcommitid as env variable in case build context is not correctly passed // so we should check agent_os environment variable to know if the build is happening in azure devops agent // or locally, locally we need to skip this test Skip.If(string.IsNullOrEmpty(agentOS)); // Act var result = _dockerCli.Run( Settings.BuildImageName, commandToExecuteOnRun: "oryx", commandArguments: new[] { "--version" }); // Assert var actualOutput = result.Output.ReplaceNewLine(); RunAsserts( () => { Assert.True(result.IsSuccess); Assert.DoesNotContain(".unspecified, Commit: unspecified", actualOutput); Assert.Contains(gitCommitID, actualOutput); Assert.Contains(expectedOryxVersion, actualOutput); }, result.GetDebugInfo()); }
private DockerRunCommandResult StartDatabaseContainer() { var runDatabaseContainerResult = _dockerCli.Run( Settings.MySqlDbImageName, environmentVariables: new List <EnvironmentVariable> { new EnvironmentVariable("MYSQL_RANDOM_ROOT_PASSWORD", "yes"), new EnvironmentVariable("MYSQL_DATABASE", Constants.DatabaseName), new EnvironmentVariable("MYSQL_USER", Constants.DatabaseUserName), new EnvironmentVariable("MYSQL_PASSWORD", Constants.DatabaseUserPwd), }, volumes: null, portMapping: null, link: null, runContainerInBackground: true, command: null, commandArguments: null); RunAsserts( () => { Assert.True(runDatabaseContainerResult.IsSuccess); }, runDatabaseContainerResult.GetDebugInfo()); return(runDatabaseContainerResult); }
private DockerRunCommandResult StartDatabaseContainer() { var runDatabaseContainerResult = _dockerCli.Run( Settings.MicrosoftSQLServerImageName, environmentVariables: new List <EnvironmentVariable> { new EnvironmentVariable("ACCEPT_EULA", "Y"), new EnvironmentVariable("SA_PASSWORD", Constants.DatabaseUserPwd), }, volumes: null, portMapping: null, link: null, runContainerInBackground: true, command: null, commandArguments: null); RunAsserts( () => { Assert.True(runDatabaseContainerResult.IsSuccess); }, runDatabaseContainerResult.GetDebugInfo()); return(runDatabaseContainerResult); }
public void DotnetVersionMatchesImageName_NetCoreApp1Versions(string version, string expectedOutput) { // Arrange & Act var result = _dockerCli.Run( "oryxdevms/dotnetcore-" + version + ":latest", commandToExecuteOnRun: "dotnet", commandArguments: new[] { "--version" }); // Assert var actualOutput = result.Output.ReplaceNewLine(); RunAsserts( () => { Assert.Contains(expectedOutput, actualOutput); }, result.GetDebugInfo()); }
public void Builds_NetCore11App_UsingNetCore11_DotnetSdkVersion() { // Arrange var appName = "NetCoreApp11WebApp"; var volume = CreateSampleAppVolume(appName); var appDir = volume.ContainerDir; var appOutputDir = "/tmp/NetCoreApp11WebApp-output"; var script = new ShellScriptBuilder() .AddBuildCommand($"{appDir} -o {appOutputDir}") .AddFileExistsCheck($"{appOutputDir}/{appName}.dll") .ToString(); // Act var result = _dockerCli.Run( Settings.BuildImageName, CreateAppNameEnvVar(appName), volume, commandToExecuteOnRun: "/bin/bash", commandArguments: new[] { "-c", script }); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains(".NET Core Version: " + DotNetCoreVersions.DotNetCore11Version, result.Output); }, result.GetDebugInfo()); }
public void PythonVersionMatchesImageName(string pythonVersion, string expectedOutput) { // Arrange & Act var result = _dockerCli.Run( "oryxdevms/python-" + pythonVersion + ":latest", commandToExecuteOnRun: "python", commandArguments: new[] { "--version" }); // Assert var actualOutput = result.Output.ReplaceNewLine(); RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Equal(expectedOutput, actualOutput); }, result.GetDebugInfo()); }
public void OutOfTheBox_PlatformToolsSupportedByOryx_ShouldBeChosen_InFullBuildImage( string executableName, string expectedPathPrefix) { // Arrange var script = new ShellScriptBuilder() .AddCommand($"which {executableName}") .ToString(); // Act var image = _imageHelper.GetBuildImage(); var result = _dockerCli.Run(image, "/bin/bash", "-c", script); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains(expectedPathPrefix, result.StdOut); }, result.GetDebugInfo()); }
public void DotnetAlias_UsesLtsVersion_ByDefault() { // Arrange var expectedOutput = DotNetCoreVersions.DotNetCore21Version; // Act var result = _dockerCli.Run( Settings.BuildImageName, commandToExecuteOnRun: "dotnet", commandArguments: new[] { "--version" }); // Assert var actualOutput = result.Output.ReplaceNewLine(); RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Equal(expectedOutput, actualOutput); }, result.GetDebugInfo()); }
public void BuildScriptGenIsIncludedInBuildImage() { // Arrange & Act var result = _dockerCli.Run( imageId: Settings.BuildImageName, commandToExecuteOnRun: "oryx", commandArguments: null); // Assert RunAsserts(() => { Assert.True(result.IsSuccess); // Help text must be shown Assert.Contains("Generates and runs build scripts for multiple languages.", result.StdOut); }, result.GetDebugInfo()); }
public void NodeVersionMatchesImageName(string nodeTag, string nodeVersion) { // Arrange & Act var expectedNodeVersion = "v" + nodeVersion; var result = _dockerCli.Run( "oryxdevms/node-" + nodeTag + ":latest", commandToExecuteOnRun: "node", commandArguments: new[] { "--version" }); // Assert var actualOutput = result.Output.ReplaceNewLine(); RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Equal(expectedNodeVersion, actualOutput); }, result.GetDebugInfo()); }
public void PulledBuildImages_Contains_BUILDIMAGE_TYPE_Info(string buildImageName, string expectedBuildImageType) { // Arrange and Act var result = _dockerCli.Run(new DockerRunArguments { ImageId = buildImageName, CommandToExecuteOnRun = "/bin/bash", CommandArguments = new[] { "-c", "cat /opt/oryx/.imagetype" } }); // Assert var actualOutput = result.StdOut.ReplaceNewLine(); RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains(expectedBuildImageType, actualOutput); }, result.GetDebugInfo()); }
public void OutOfTheBox_PlatformToolsSupportedByOryx_ShouldBeChosen(string executableName) { // Arrange var oryxInstalledExecutable = $"/opt/oryx/defaultversions/{executableName}"; var script = new ShellScriptBuilder() .AddCommand($"which {executableName}") .ToString(); // Act var result = _dockerCli.Run(FullBuildImageName, "/bin/bash", "-c", script); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains(oryxInstalledExecutable, result.StdOut); }, result.GetDebugInfo()); }
public override void GeneratesScript_AndBuilds() { // Arrange var volume = CreateSampleAppVolume("flask-app"); var appDir = volume.ContainerDir; var appOutputDir = "/tmp/app-output"; var script = new ShellScriptBuilder() .AddBuildCommand($"{appDir} -o {appOutputDir}") .AddDirectoryExistsCheck($"{appOutputDir}/{PackagesDirectory}") .ToString(); // Act var result = _dockerCli.Run( Settings.BuildImageName, CreateAppNameEnvVar("flask-app"), volume, commandToExecuteOnRun: "/bin/bash", commandArguments: new[] { "-c", script }); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains( $"Python Version: /opt/python/{PythonVersions.Python37Version}/bin/python3", result.Output); }, result.GetDebugInfo()); }
public void GeneratesScript_UsingDefaultOryxPublishOutputDirectory() { // Arrange var appDir = "/app"; var appOutputDir = $"{appDir}/{DotnetCoreConstants.OryxOutputPublishDirectory}"; var expectedStartupCommand = $"dotnet \"webapp.dll\""; var expectedWorkingDir = $"cd \"{appOutputDir}\""; var scriptLocation = "/tmp/run.sh"; var script = new ShellScriptBuilder() .AddCommand($"mkdir -p {appDir}") .AddCommand($"echo '{RegularProjectFileContent}' > {appDir}/webapp.csproj") .AddCommand($"mkdir -p {appOutputDir}") .AddCommand($"echo > {appOutputDir}/webapp.dll") .AddCommand($"oryx -sourcePath {appDir} -output {scriptLocation}") .AddCommand($"cat {scriptLocation}") .ToString(); // Act var result = _dockerCli.Run( DotnetCoreRuntimeImageName, commandToExecuteOnRun: "/bin/sh", commandArguments: new[] { "-c", script }); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); Assert.Contains(expectedWorkingDir, result.Output); Assert.Contains(expectedStartupCommand, result.Output); }, result.GetDebugInfo()); }
public override void GeneratesScript_AndBuilds() { // Arrange var volume = CreateWebFrontEndVolume(); var appDir = volume.ContainerDir; var appOutputDir = "/tmp/webfrontend-output"; var script = new ShellScriptBuilder() .AddBuildCommand($"{appDir} -o {appOutputDir}") .AddDirectoryExistsCheck($"{appOutputDir}/node_modules") .ToString(); // Act var result = _dockerCli.Run( Settings.BuildImageName, volume, commandToExecuteOnRun: "/bin/bash", commandArguments: new[] { "-c", script }); // Assert RunAsserts( () => { Assert.True(result.IsSuccess); }, result.GetDebugInfo()); }