зеркало из https://github.com/microsoft/Oryx.git
Write operation id to build manifest file instead of a separate file (#176)
This commit is contained in:
Родитель
bddf7a9f6f
Коммит
9c7c2fdc7f
|
@ -83,7 +83,7 @@
|
|||
file-name-prefix: __
|
||||
- name: file-paths
|
||||
constants:
|
||||
build-id-file-name: .oryx_build_id
|
||||
build-manifest-file-name: oryx-manifest.toml
|
||||
outputs:
|
||||
- type: csharp
|
||||
directory: src/Common
|
||||
|
|
|
@ -12,6 +12,11 @@ namespace Microsoft.Oryx.BuildScriptGenerator
|
|||
/// </summary>
|
||||
public partial class BuildScriptGeneratorContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the information which is used to correlate log messages.
|
||||
/// </summary>
|
||||
public string OperationId { get; set; }
|
||||
|
||||
public ISourceRepo SourceRepo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Microsoft.Oryx.BuildScriptGenerator
|
|||
{
|
||||
public const string OryxEnvironmentSettingNamePrefix = "ORYX_";
|
||||
public const string BuildEnvironmentFileName = "build.env";
|
||||
public const string ManifestFileName = "oryx-manifest.toml";
|
||||
public const string AppInsightsKey = "APPINSIGHTS_INSTRUMENTATIONKEY";
|
||||
public const string ZipAllOutputBuildPropertyKey = "zip_all_output";
|
||||
public const string ZipAllOutputBuildPropertyKeyDocumentation =
|
||||
|
|
|
@ -334,7 +334,7 @@ namespace Microsoft.Oryx.BuildScriptGenerator
|
|||
PostBuildCommand = postBuildCommand,
|
||||
DirectoriesToExcludeFromCopyToIntermediateDir = directoriesToExcludeFromCopyToIntermediateDir,
|
||||
DirectoriesToExcludeFromCopyToBuildOutputDir = directoriesToExcludeFromCopyToBuildOutputDir,
|
||||
ManifestFileName = Constants.ManifestFileName,
|
||||
ManifestFileName = FilePaths.BuildManifestFileName,
|
||||
BuildProperties = buildProperties
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Oryx.Common;
|
||||
|
||||
namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
||||
{
|
||||
|
@ -52,6 +53,8 @@ namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
|||
public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext context)
|
||||
{
|
||||
var buildProperties = new Dictionary<string, string>();
|
||||
buildProperties[ManifestFilePropertyKeys.OperationId] = context.OperationId;
|
||||
|
||||
(string projectFile, string publishDir) = GetProjectFileAndPublishDir(context.SourceRepo);
|
||||
if (string.IsNullOrEmpty(projectFile) || string.IsNullOrEmpty(publishDir))
|
||||
{
|
||||
|
@ -77,7 +80,7 @@ namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
|||
context),
|
||||
PreBuildCommand = preBuildCommand,
|
||||
PostBuildCommand = postBuildCommand,
|
||||
ManifestFileName = Constants.ManifestFileName,
|
||||
ManifestFileName = FilePaths.BuildManifestFileName,
|
||||
ZipAllOutput = zipAllOutput,
|
||||
Configuration = GetBuildConfiguration()
|
||||
};
|
||||
|
@ -148,6 +151,14 @@ namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
|||
return dirs;
|
||||
}
|
||||
|
||||
private static bool ShouldZipAllOutput(BuildScriptGeneratorContext context)
|
||||
{
|
||||
return BuildPropertiesHelper.IsTrue(
|
||||
Constants.ZipAllOutputBuildPropertyKey,
|
||||
context,
|
||||
valueIsRequired: false);
|
||||
}
|
||||
|
||||
private string GetBuildConfiguration()
|
||||
{
|
||||
var configuration = _options.MSBuildConfiguration;
|
||||
|
@ -159,14 +170,6 @@ namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
|||
return configuration;
|
||||
}
|
||||
|
||||
private static bool ShouldZipAllOutput(BuildScriptGeneratorContext context)
|
||||
{
|
||||
return BuildPropertiesHelper.IsTrue(
|
||||
Constants.ZipAllOutputBuildPropertyKey,
|
||||
context,
|
||||
valueIsRequired: false);
|
||||
}
|
||||
|
||||
private (string projFile, string publishDir) GetProjectFileAndPublishDir(ISourceRepo repo)
|
||||
{
|
||||
var projectFile = _aspNetCoreWebAppProjectFileProvider.GetRelativePathToProjectFile(repo);
|
||||
|
@ -178,18 +181,5 @@ namespace Microsoft.Oryx.BuildScriptGenerator.DotNetCore
|
|||
var publishDir = Path.Combine(repo.RootPath, DotnetCoreConstants.OryxOutputPublishDirectory);
|
||||
return (projectFile, publishDir);
|
||||
}
|
||||
|
||||
private string GetCommandOrScript(string commandOrScript)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(commandOrScript))
|
||||
{
|
||||
if (File.Exists(commandOrScript))
|
||||
{
|
||||
return $"\"{commandOrScript}\"";
|
||||
}
|
||||
}
|
||||
|
||||
return commandOrScript;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,8 @@ namespace Microsoft.Oryx.BuildScriptGenerator
|
|||
{
|
||||
public static class ManifestFilePropertyKeys
|
||||
{
|
||||
public const string ZipAllOutput = "zipAllOutput";
|
||||
public const string ZipAllOutput = nameof(ZipAllOutput);
|
||||
|
||||
public const string OperationId = nameof(OperationId);
|
||||
}
|
||||
}
|
|
@ -61,6 +61,8 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Node
|
|||
public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext context)
|
||||
{
|
||||
var buildProperties = new Dictionary<string, string>();
|
||||
buildProperties[ManifestFilePropertyKeys.OperationId] = context.OperationId;
|
||||
|
||||
var packageJson = GetPackageJsonObject(context.SourceRepo, _logger);
|
||||
string runBuildCommand = null;
|
||||
string runBuildAzureCommand = null;
|
||||
|
|
|
@ -43,6 +43,9 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Php
|
|||
|
||||
public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext ctx)
|
||||
{
|
||||
var buildProperties = new Dictionary<string, string>();
|
||||
buildProperties[ManifestFilePropertyKeys.OperationId] = ctx.OperationId;
|
||||
|
||||
_logger.LogDebug("Selected PHP version: {phpVer}", ctx.PhpVersion);
|
||||
bool composerFileExists = false;
|
||||
|
||||
|
@ -70,7 +73,7 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Php
|
|||
|
||||
var props = new PhpBashBuildSnippetProperties { ComposerFileExists = composerFileExists };
|
||||
string snippet = TemplateHelpers.Render(TemplateHelpers.TemplateResource.PhpBuildSnippet, props, _logger);
|
||||
return new BuildScriptSnippet { BashBuildScriptSnippet = snippet };
|
||||
return new BuildScriptSnippet { BashBuildScriptSnippet = snippet, BuildProperties = buildProperties };
|
||||
}
|
||||
|
||||
public bool IsEnabled(BuildScriptGeneratorContext ctx)
|
||||
|
|
|
@ -6,4 +6,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.Oryx.BuildScriptGenerator.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
[assembly: InternalsVisibleTo("BuildScriptGeneratorCli.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
[assembly: InternalsVisibleTo("BuildScriptGeneratorCli.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
[assembly: InternalsVisibleTo("Oryx.Integration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
[assembly: InternalsVisibleTo("Oryx.BuildImage.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
[assembly: InternalsVisibleTo("Oryx.RuntimeImage.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c96528184668742ee5bc6a1f8b4447fdc42d482d7c339989f050d7858ea7277df2f86c7ad0b8afa733987baaf6adb2858b170995d03ba3ad612bbd0b5a389e1f6392cc5ad158f726d018d9aa75c362e0350da1c6f92b75ca449591be97fc08e68c576d95aff6cfc9e58a4653e4b6e87a1d83e3060f98a6214eacfd62a45cc8bf")]
|
||||
|
|
|
@ -68,6 +68,8 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Python
|
|||
public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext context)
|
||||
{
|
||||
var buildProperties = new Dictionary<string, string>();
|
||||
buildProperties[ManifestFilePropertyKeys.OperationId] = context.OperationId;
|
||||
|
||||
var packageDir = GetPackageDirectory(context);
|
||||
var virtualEnvName = GetVirtualEnvironmentName(context);
|
||||
if (string.IsNullOrEmpty(packageDir))
|
||||
|
@ -105,13 +107,11 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Python
|
|||
|
||||
bool enableCollectStatic = IsCollectStaticEnabled();
|
||||
|
||||
string compressVirtualEnvCommand = null;
|
||||
string compressedVirtualEnvFileName = null;
|
||||
GetVirtualEnvPackOptions(
|
||||
context,
|
||||
virtualEnvName,
|
||||
out compressVirtualEnvCommand,
|
||||
out compressedVirtualEnvFileName);
|
||||
out var compressVirtualEnvCommand,
|
||||
out var compressedVirtualEnvFileName);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(compressedVirtualEnvFileName))
|
||||
{
|
||||
|
|
|
@ -20,25 +20,30 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
private readonly IConsole _console;
|
||||
private readonly List<ICheckerMessage> _checkerMessageSink;
|
||||
private readonly ILogger<BuildScriptGenerator> _logger;
|
||||
private readonly string _operationId;
|
||||
|
||||
public BuildScriptGenerator(
|
||||
IServiceProvider serviceProvider,
|
||||
IConsole console,
|
||||
List<ICheckerMessage> checkerMessageSink)
|
||||
List<ICheckerMessage> checkerMessageSink,
|
||||
string operationId)
|
||||
{
|
||||
_console = console;
|
||||
_serviceProvider = serviceProvider;
|
||||
_checkerMessageSink = checkerMessageSink;
|
||||
_logger = _serviceProvider.GetRequiredService<ILogger<BuildScriptGenerator>>();
|
||||
_operationId = operationId;
|
||||
}
|
||||
|
||||
public static BuildScriptGeneratorContext CreateContext(
|
||||
BuildScriptGeneratorOptions options,
|
||||
CliEnvironmentSettings envSettings,
|
||||
ISourceRepo sourceRepo)
|
||||
ISourceRepo sourceRepo,
|
||||
string operationId)
|
||||
{
|
||||
return new BuildScriptGeneratorContext
|
||||
{
|
||||
OperationId = operationId,
|
||||
SourceRepo = sourceRepo,
|
||||
Language = options.Language,
|
||||
LanguageVersion = options.LanguageVersion,
|
||||
|
@ -63,7 +68,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
var sourceRepoProvider = _serviceProvider.GetRequiredService<ISourceRepoProvider>();
|
||||
var environment = _serviceProvider.GetRequiredService<CliEnvironmentSettings>();
|
||||
var sourceRepo = sourceRepoProvider.GetSourceRepo();
|
||||
var scriptGenCtx = CreateContext(options, environment, sourceRepo);
|
||||
var scriptGenCtx = CreateContext(options, environment, sourceRepo, _operationId);
|
||||
|
||||
scriptGen.GenerateBashScript(scriptGenCtx, out generatedScript, _checkerMessageSink);
|
||||
return true;
|
||||
|
|
|
@ -7,7 +7,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
|
@ -96,7 +95,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
DataReceivedEventHandler stdErrHandler)
|
||||
{
|
||||
var logger = serviceProvider.GetRequiredService<ILogger<BuildCommand>>();
|
||||
var buildOpId = logger.StartOperation(
|
||||
var buildOperationId = logger.StartOperation(
|
||||
BuildOperationName(serviceProvider.GetRequiredService<IEnvironment>()));
|
||||
|
||||
var options = serviceProvider.GetRequiredService<IOptions<BuildScriptGeneratorOptions>>().Value;
|
||||
|
@ -107,7 +106,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
|
||||
var buildInfo = new DefinitionListFormatter();
|
||||
buildInfo.AddDefinition("Oryx Version", $"{Program.GetVersion()}, Commit: {Program.GetCommit()}");
|
||||
buildInfo.AddDefinition("Build Operation ID", buildOpId);
|
||||
buildInfo.AddDefinition("Build Operation ID", buildOperationId);
|
||||
|
||||
var sourceRepo = serviceProvider.GetRequiredService<ISourceRepoProvider>().GetSourceRepo();
|
||||
var commitId = GetSourceRepoCommitId(
|
||||
|
@ -121,21 +120,6 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
|
||||
console.WriteLine(buildInfo.ToString());
|
||||
|
||||
// Try writing the ID to a file in the source directory
|
||||
try
|
||||
{
|
||||
using (logger.LogTimedEvent("WriteBuildIdFile"))
|
||||
using (var idFileWriter = new StreamWriter(
|
||||
Path.Combine(sourceRepo.RootPath, Common.FilePaths.BuildIdFileName)))
|
||||
{
|
||||
idFileWriter.Write(buildOpId);
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.LogError(exc, "Exception caught while trying to write build ID file");
|
||||
}
|
||||
|
||||
var environmentSettingsProvider = serviceProvider.GetRequiredService<IEnvironmentSettingsProvider>();
|
||||
if (!environmentSettingsProvider.TryGetAndLoadSettings(out var environmentSettings))
|
||||
{
|
||||
|
@ -147,7 +131,8 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
using (var stopwatch = logger.LogTimedEvent("GenerateBuildScript"))
|
||||
{
|
||||
var checkerMessages = new List<ICheckerMessage>();
|
||||
var scriptGenerator = new BuildScriptGenerator(serviceProvider, console, checkerMessages);
|
||||
var scriptGenerator = new BuildScriptGenerator(
|
||||
serviceProvider, console, checkerMessages, buildOperationId);
|
||||
|
||||
var generated = scriptGenerator.TryGenerateScript(out scriptContent);
|
||||
stopwatch.AddProperty("generateSucceeded", generated.ToString());
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
// --------------------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using McMaster.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -40,7 +39,11 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
|
||||
internal override int Execute(IServiceProvider serviceProvider, IConsole console)
|
||||
{
|
||||
var scriptGenerator = new BuildScriptGenerator(serviceProvider, console, checkerMessageSink: null);
|
||||
var scriptGenerator = new BuildScriptGenerator(
|
||||
serviceProvider,
|
||||
console,
|
||||
checkerMessageSink: null,
|
||||
operationId: null);
|
||||
|
||||
if (!scriptGenerator.TryGenerateScript(out var generatedScript))
|
||||
{
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
|
|||
var env = serviceProvider.GetRequiredService<CliEnvironmentSettings>();
|
||||
var repo = serviceProvider.GetRequiredService<ISourceRepoProvider>().GetSourceRepo();
|
||||
|
||||
var ctx = BuildScriptGenerator.CreateContext(options, env, repo);
|
||||
var ctx = BuildScriptGenerator.CreateContext(options, env, repo, operationId: null);
|
||||
var compatPlats = generator.GetCompatiblePlatforms(ctx);
|
||||
|
||||
if (compatPlats != null && compatPlats.Any())
|
||||
|
|
|
@ -4,6 +4,6 @@ namespace Microsoft.Oryx.Common
|
|||
{
|
||||
public static class FilePaths
|
||||
{
|
||||
public const string BuildIdFileName = ".oryx_build_id";
|
||||
public const string BuildManifestFileName = "oryx-manifest.toml";
|
||||
}
|
||||
}
|
|
@ -6,17 +6,20 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"startupscriptgenerator/common/consts"
|
||||
"github.com/BurntSushi/toml"
|
||||
"log"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type BuildManifest struct {
|
||||
StartupFileName string
|
||||
ZipAllOutput string
|
||||
StartupFileName string
|
||||
ZipAllOutput string
|
||||
OperationId string
|
||||
}
|
||||
|
||||
const ManifestFileName = "oryx-manifest.toml"
|
||||
var _buildManifest = BuildManifest{}
|
||||
var _readManifest = false
|
||||
|
||||
func DeserializeBuildManifest(manifestFile string) BuildManifest {
|
||||
var manifest BuildManifest
|
||||
|
@ -27,11 +30,15 @@ func DeserializeBuildManifest(manifestFile string) BuildManifest {
|
|||
}
|
||||
|
||||
func GetBuildManifest(appPath string) BuildManifest {
|
||||
buildManifest := BuildManifest{}
|
||||
|
||||
tomlFile := filepath.Join(appPath, ManifestFileName)
|
||||
if FileExists(tomlFile) {
|
||||
buildManifest = DeserializeBuildManifest(tomlFile)
|
||||
if _readManifest {
|
||||
return _buildManifest
|
||||
}
|
||||
return buildManifest
|
||||
|
||||
tomlFile := filepath.Join(appPath, consts.BuildManifestFileName)
|
||||
if FileExists(tomlFile) {
|
||||
_buildManifest = DeserializeBuildManifest(tomlFile)
|
||||
_readManifest = true
|
||||
}
|
||||
|
||||
return _buildManifest
|
||||
}
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
package consts
|
||||
|
||||
const BuildIdFileName string = ".oryx_build_id"
|
||||
const BuildManifestFileName string = "oryx-manifest.toml"
|
||||
|
|
|
@ -7,9 +7,7 @@ package common
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"startupscriptgenerator/common/consts"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -32,12 +30,12 @@ type Logger struct {
|
|||
var buildOpId string
|
||||
|
||||
func SetGlobalOperationId(appRootPath string) {
|
||||
if buildOpId == "" {
|
||||
rawId, err := ioutil.ReadFile(path.Join(appRootPath, consts.BuildIdFileName))
|
||||
if err == nil { // Silently ignore errors
|
||||
buildOpId = strings.TrimSpace(string(rawId))
|
||||
}
|
||||
buildManifest := GetBuildManifest(appRootPath)
|
||||
|
||||
if buildManifest.OperationId != "" {
|
||||
buildOpId = strings.TrimSpace(buildManifest.OperationId)
|
||||
}
|
||||
fmt.Println("Build Operation ID: " + buildOpId)
|
||||
}
|
||||
|
||||
func GetLogger(name string) *Logger {
|
||||
|
|
|
@ -48,14 +48,13 @@ func (gen *NodeStartupScriptGenerator) GenerateEntrypointScript() string {
|
|||
|
||||
logger.LogInformation("Generating script for source at '%s'", gen.SourcePath)
|
||||
|
||||
const oryxManifestFile string = "oryx-manifest.toml"
|
||||
scriptBuilder := strings.Builder{}
|
||||
scriptBuilder.WriteString("#!/bin/sh\n")
|
||||
scriptBuilder.WriteString("\n# Enter the source directory to make sure the script runs where the user expects\n")
|
||||
scriptBuilder.WriteString("cd " + gen.SourcePath + "\n\n")
|
||||
scriptBuilder.WriteString("if [ -f ./" + oryxManifestFile + " ]; then\n")
|
||||
scriptBuilder.WriteString(" echo \"Found '" + oryxManifestFile + "'\"\n")
|
||||
scriptBuilder.WriteString(" . ./" + oryxManifestFile + "\n")
|
||||
scriptBuilder.WriteString("if [ -f ./" + consts.BuildManifestFileName + " ]; then\n")
|
||||
scriptBuilder.WriteString(" echo \"Found '" + consts.BuildManifestFileName + "'\"\n")
|
||||
scriptBuilder.WriteString(" . ./" + consts.BuildManifestFileName + "\n")
|
||||
scriptBuilder.WriteString("fi\n\n")
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"startupscriptgenerator/common"
|
||||
"startupscriptgenerator/common/consts"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -92,13 +93,12 @@ func logReadDirError(logger *common.Logger, path string, err error) {
|
|||
// Builds the commands to setup the Python packages, using virtual env or a package folder.
|
||||
func (gen *PythonStartupScriptGenerator) getPackageSetupCommand() string {
|
||||
scriptBuilder := strings.Builder{}
|
||||
const buildManifestFile string = "oryx-manifest.toml"
|
||||
manifesFilePath := filepath.Join(gen.SourcePath, buildManifestFile)
|
||||
manifesFilePath := filepath.Join(gen.SourcePath, consts.BuildManifestFileName)
|
||||
// If a manifest file is present, it takes precedence.
|
||||
if common.FileExists(manifesFilePath) {
|
||||
virtualEnvVarPath := filepath.Join(gen.SourcePath, "$virtualEnvName")
|
||||
scriptBuilder.WriteString("echo \"Using '" + buildManifestFile + "'.\"\n")
|
||||
scriptBuilder.WriteString(". ./" + buildManifestFile + "\n")
|
||||
scriptBuilder.WriteString("echo \"Using '" + consts.BuildManifestFileName + "'.\"\n")
|
||||
scriptBuilder.WriteString(". ./" + consts.BuildManifestFileName + "\n")
|
||||
|
||||
if !gen.SkipVirtualEnvExtraction {
|
||||
scriptBuilder.WriteString("echo \"Checking if virtual environment was compressed...\"\n")
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
var script = new ShellScriptBuilder()
|
||||
.AddBuildCommand($"{appDir} -o {appOutputDir}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/app.dll")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -76,7 +76,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
var script = new ShellScriptBuilder()
|
||||
.AddBuildCommand($"{appDir} -o {appOutputDir}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{appName}.dll")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -147,7 +147,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
var script = new ShellScriptBuilder()
|
||||
.AddBuildCommand($"{appDir} -o {appOutputDir}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/app.dll")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
|
|
@ -7,6 +7,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Oryx.BuildScriptGenerator.Node;
|
||||
using Microsoft.Oryx.Common;
|
||||
using Microsoft.Oryx.Tests.Common;
|
||||
using Xunit;
|
||||
|
@ -141,12 +142,13 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
var appDir = volume.ContainerDir;
|
||||
var nestedOutputDir = "/tmp/output";
|
||||
var script = new ShellScriptBuilder()
|
||||
.AddCommand("printenv")
|
||||
.AddCommand($"oryx build {appDir} -o {nestedOutputDir} --log-file {appDir}/1.log")
|
||||
.AddCommand($"oryx build {appDir} -o {nestedOutputDir}")
|
||||
.AddDirectoryExistsCheck($"{nestedOutputDir}/node_modules")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/oryx-appinsightsloader.js")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddStringExistsInFileCheck("injectedAppInsights=\"True\"", $"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddStringExistsInFileCheck(
|
||||
$"{NodeConstants.InjectedAppInsights}=\"True\"",
|
||||
$"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -233,7 +235,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
.CreateFile($"{appDir}/1.log", "hello1")
|
||||
.CreateFile($"{appDir}/app2/2.log", "hello2")
|
||||
.CreateFile($"{appDir}/app2/app3/3.log", "hello3")
|
||||
.CreateFile($"{appDir}/idea.js", nodeCode)
|
||||
.CreateFile($"{appDir}/idea.js", $"\"{nodeCode}\"")
|
||||
.AddBuildCommand($"{appDir} -o {appOutputDir} --log-file {logFile}");
|
||||
|
||||
return script;
|
||||
|
@ -639,7 +641,7 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
.AddDirectoryDoesNotExistCheck($"{appOutputDir}/node_modules")
|
||||
.AddStringExistsInFileCheck(
|
||||
"compressedNodeModulesFile=\"node_modules.zip\"",
|
||||
$"{appOutputDir}/oryx-manifest.toml")
|
||||
$"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -713,8 +715,10 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
$"oryx build {appDir} -o {nestedOutputDir} {spcifyNodeVersionCommand} --log-file {appDir}/1.log")
|
||||
.AddDirectoryExistsCheck($"{nestedOutputDir}/node_modules")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/oryx-appinsightsloader.js")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddStringExistsInFileCheck("injectedAppInsights=\"True\"", $"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddFileExistsCheck($"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddStringExistsInFileCheck(
|
||||
$"{NodeConstants.InjectedAppInsights}=\"True\"",
|
||||
$"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -762,7 +766,9 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
$"oryx build {appDir} -o {nestedOutputDir} {spcifyNodeVersionCommand} --log-file {appDir}/1.log")
|
||||
.AddDirectoryExistsCheck($"{nestedOutputDir}/node_modules")
|
||||
.AddFileDoesNotExistCheck($"{nestedOutputDir}/oryx-appinsightsloader.js")
|
||||
.AddFileDoesNotExistCheck($"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddStringDoesNotExistInFileCheck(
|
||||
NodeConstants.InjectedAppInsights,
|
||||
$"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
@ -810,7 +816,8 @@ namespace Microsoft.Oryx.BuildImage.Tests
|
|||
$"oryx build {appDir} -o {nestedOutputDir} {spcifyNodeVersionCommand} --log-file {appDir}/1.log")
|
||||
.AddDirectoryExistsCheck($"{nestedOutputDir}/node_modules")
|
||||
.AddFileDoesNotExistCheck($"{nestedOutputDir}/oryx-appinsightsloader.js")
|
||||
.AddFileDoesNotExistCheck($"{nestedOutputDir}/oryx-manifest.toml")
|
||||
.AddStringDoesNotExistInFileCheck(
|
||||
NodeConstants.InjectedAppInsights, $"{nestedOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
// Act
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AssemblyOriginatorKeyFile>..\..\build\TestAssembliesKey.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -20,6 +23,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\BuildScriptGenerator\BuildScriptGenerator.csproj" />
|
||||
<ProjectReference Include="..\BuildScriptGeneratorCli.Tests\BuildScriptGeneratorCli.Tests.csproj" />
|
||||
<ProjectReference Include="..\Oryx.Tests.Common\Oryx.Tests.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.IO;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.Oryx.BuildScriptGenerator;
|
||||
using Microsoft.Oryx.BuildScriptGenerator.DotNetCore;
|
||||
using Microsoft.Oryx.Common;
|
||||
using Microsoft.Oryx.Tests.Common;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
@ -303,10 +304,10 @@ namespace Microsoft.Oryx.Integration.Tests
|
|||
var appOutputDir = $"{appDir}/myoutputdir";
|
||||
var buildImageScript = new ShellScriptBuilder()
|
||||
.AddCommand($"oryx build {appDir} -o {appOutputDir} -l dotnet --language-version {dotnetcoreVersion}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
// NOTE: Delete the manifest file explicitly
|
||||
.AddCommand($"rm -f {appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileDoesNotExistCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddCommand($"rm -f {appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddFileDoesNotExistCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
var runtimeImageScript = new ShellScriptBuilder()
|
||||
.AddCommand(
|
||||
|
@ -350,10 +351,10 @@ namespace Microsoft.Oryx.Integration.Tests
|
|||
var appOutputDir = $"{appDir}/myoutputdir";
|
||||
var buildImageScript = new ShellScriptBuilder()
|
||||
.AddCommand($"oryx build {appDir} -o {appOutputDir} -l dotnet --language-version {dotnetcoreVersion}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileExistsCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
// NOTE: Delete the manifest file explicitly
|
||||
.AddCommand($"rm -f {appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddFileDoesNotExistCheck($"{appOutputDir}/{ScriptGenerator.Constants.ManifestFileName}")
|
||||
.AddCommand($"rm -f {appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddFileDoesNotExistCheck($"{appOutputDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
var runtimeImageScript = new ShellScriptBuilder()
|
||||
.AddCommand(
|
||||
|
|
|
@ -7,6 +7,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Oryx.BuildScriptGenerator.Node;
|
||||
using Microsoft.Oryx.Common;
|
||||
using Microsoft.Oryx.Tests.Common;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
@ -258,7 +260,7 @@ namespace Microsoft.Oryx.Integration.Tests
|
|||
var appName = "webfrontend";
|
||||
var appVolume = CreateAppVolume(appName);
|
||||
// Allows `pack` to use the host's Docker engine
|
||||
var dockerPort = DockerVolume.Create("/var/run/docker.sock", "/var/run/docker.sock");
|
||||
var dockerPort = DockerVolume.DockerDaemonSocket;
|
||||
var appImageName = "testnodeapp";
|
||||
|
||||
// Act
|
||||
|
@ -836,8 +838,9 @@ namespace Microsoft.Oryx.Integration.Tests
|
|||
.AddCommand($"oryx build {appDir} -o {appDir} {spcifyNodeVersionCommand} --log-file {appDir}/1.log")
|
||||
.AddDirectoryExistsCheck($"{appDir}/node_modules")
|
||||
.AddFileExistsCheck($"{appDir}/oryx-appinsightsloader.js")
|
||||
.AddFileExistsCheck($"{appDir}/oryx-manifest.toml")
|
||||
.AddStringExistsInFileCheck("injectedAppInsights=\"True\"", $"{appDir}/oryx-manifest.toml")
|
||||
.AddFileExistsCheck($"{appDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddStringExistsInFileCheck(
|
||||
$"{NodeConstants.InjectedAppInsights}=\"True\"", $"{appDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
var runScript = new ShellScriptBuilder()
|
||||
|
@ -846,8 +849,10 @@ namespace Microsoft.Oryx.Integration.Tests
|
|||
.AddCommand($"oryx -appPath {appDir} -bindPort {ContainerPort}")
|
||||
.AddCommand(DefaultStartupFilePath)
|
||||
.AddFileExistsCheck($"{appDir}/oryx-appinsightsloader.js")
|
||||
.AddFileExistsCheck($"{appDir}/oryx-manifest.toml")
|
||||
.AddStringExistsInFileCheck("injectedAppInsights=\"True\"", $"{appDir}/oryx-manifest.toml")
|
||||
.AddFileExistsCheck($"{appDir}/{FilePaths.BuildManifestFileName}")
|
||||
.AddStringExistsInFileCheck(
|
||||
$"{NodeConstants.InjectedAppInsights}=\"True\"",
|
||||
$"{appDir}/{FilePaths.BuildManifestFileName}")
|
||||
.ToString();
|
||||
|
||||
await EndToEndTestHelper.BuildRunAndAssertAppAsync(
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<LangVersion>7.3</LangVersion>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AssemblyOriginatorKeyFile>..\..\build\TestAssembliesKey.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -17,6 +20,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\BuildScriptGenerator\BuildScriptGenerator.csproj" />
|
||||
<ProjectReference Include="..\Oryx.Tests.Common\Oryx.Tests.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Oryx.BuildScriptGenerator.Node;
|
||||
using Microsoft.Oryx.Common;
|
||||
using Microsoft.Oryx.Tests.Common;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
@ -147,13 +149,13 @@ namespace Microsoft.Oryx.RuntimeImage.Tests
|
|||
console.error(e);
|
||||
}
|
||||
}";
|
||||
var manifestFileContent = "injectedAppInsight=\"True\"";
|
||||
var manifestFileContent = $"'{NodeConstants.InjectedAppInsights}=\"True\"'";
|
||||
|
||||
var script = new ShellScriptBuilder()
|
||||
.CreateDirectory(appPath)
|
||||
.CreateFile(appPath + "/entry.sh", $"exit {exitCodeSentinel}")
|
||||
.CreateFile(appPath + "/oryx-manifest.toml", manifestFileContent)
|
||||
.CreateFile(appPath + "/oryx-appinsightsloader.js", aiNodesdkLoaderContent)
|
||||
.CreateFile($"{appPath}/entry.sh", $"exit {exitCodeSentinel}")
|
||||
.CreateFile($"{appPath}/{FilePaths.BuildManifestFileName}", manifestFileContent)
|
||||
.CreateFile($"{appPath}/oryx-appinsightsloader.js", $"\"{aiNodesdkLoaderContent}\"")
|
||||
.AddCommand("oryx -userStartupCommand entry.sh -appPath " + appPath)
|
||||
.AddCommand(". ./run.sh") // Source the default output path
|
||||
.AddStringExistsInFileCheck("export NODE_OPTIONS='--require ./oryx-appinsightsloader.js'", "./run.sh")
|
||||
|
@ -234,11 +236,12 @@ namespace Microsoft.Oryx.RuntimeImage.Tests
|
|||
// and additionally print the exception message
|
||||
|
||||
// Arrange
|
||||
var imageName = string.Concat("oryxdevms/node-", nodeVersion);
|
||||
var hostSamplesDir = Path.Combine(Directory.GetCurrentDirectory(), "SampleApps");
|
||||
var volume = DockerVolume.CreateMirror(Path.Combine(hostSamplesDir, "nodejs", "linxnodeexpress"));
|
||||
var appName = "linxnodeexpress";
|
||||
var hostDir = Path.Combine(_hostSamplesDir, "nodejs", appName);
|
||||
var volume = DockerVolume.CreateMirror(hostDir);
|
||||
var appDir = volume.ContainerDir;
|
||||
var manifestFileContent = "injectedAppInsight=\"True\"";
|
||||
var imageName = string.Concat("oryxdevms/node-", nodeVersion);
|
||||
var manifestFileContent = $"'{NodeConstants.InjectedAppInsights}=\"True\"'";
|
||||
var aiNodesdkLoaderContent = @"try {
|
||||
var appInsights = require('applicationinsights');
|
||||
if (process.env.APPINSIGHTS_INSTRUMENTATIONKEY)
|
||||
|
@ -252,8 +255,8 @@ namespace Microsoft.Oryx.RuntimeImage.Tests
|
|||
int containerDebugPort = 8080;
|
||||
|
||||
var script = new ShellScriptBuilder()
|
||||
.CreateFile(appDir + "/oryx-manifest.toml", manifestFileContent)
|
||||
.CreateFile(appDir + "/oryx-appinsightsloader.js", aiNodesdkLoaderContent)
|
||||
.CreateFile($"{appDir}/{FilePaths.BuildManifestFileName}", manifestFileContent)
|
||||
.CreateFile($"{appDir}/oryx-appinsightsloader.js", $"\"{aiNodesdkLoaderContent}\"")
|
||||
.AddCommand($"cd {appDir}")
|
||||
.AddCommand("npm install")
|
||||
.AddCommand($"oryx -appPath {appDir}")
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<LangVersion>7.3</LangVersion>
|
||||
<IsPackable>false</IsPackable>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AssemblyOriginatorKeyFile>..\..\build\TestAssembliesKey.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -20,6 +23,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\BuildScriptGenerator\BuildScriptGenerator.csproj" />
|
||||
<ProjectReference Include="..\Oryx.Tests.Common\Oryx.Tests.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -7,13 +7,18 @@ using System;
|
|||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Oryx.Common;
|
||||
|
||||
namespace Microsoft.Oryx.Tests.Common
|
||||
{
|
||||
public class DockerVolume
|
||||
{
|
||||
private const string DockerSocket = "/var/run/docker.sock";
|
||||
public static readonly DockerVolume DockerDaemonSocket = new DockerVolume(
|
||||
originalHostDir: null,
|
||||
mountedHostDir: DockerSocket,
|
||||
containerDir: DockerSocket);
|
||||
|
||||
// VSTS variable used to identify if the tests are running in VSTS or not (for example, on dev machines)
|
||||
public const string VstsAgentNameEnivronmentVariable = "AGENT_NAME";
|
||||
|
||||
|
@ -42,30 +47,25 @@ namespace Microsoft.Oryx.Tests.Common
|
|||
/// </summary>
|
||||
public string ContainerDir { get; }
|
||||
|
||||
public static DockerVolume Create([NotNull] string hostPath, [NotNull] string containerPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hostPath) && !Directory.Exists(hostPath) && !File.Exists(hostPath))
|
||||
{
|
||||
throw new ArgumentException($"'{nameof(hostPath)}' must point to an existing directory or file.");
|
||||
}
|
||||
|
||||
return new DockerVolume(null, hostPath, containerPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of a local directory, and returns a DockerVolume instance for mounting that copy in a
|
||||
/// container.
|
||||
/// </summary>
|
||||
/// <param name="originalDir">local directory to be used in a container</param>
|
||||
/// <param name="hostDir">local directory to be used in a container</param>
|
||||
/// <returns>DockerVolume instance that can be used to mount the new copy of `originalDir`.</returns>
|
||||
public static DockerVolume CreateMirror(string originalDir)
|
||||
public static DockerVolume CreateMirror(string hostDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(originalDir))
|
||||
if (string.IsNullOrEmpty(hostDir))
|
||||
{
|
||||
throw new ArgumentException($"'{nameof(originalDir)}' cannot be null or empty.");
|
||||
throw new ArgumentException($"'{nameof(hostDir)}' cannot be null or empty.");
|
||||
}
|
||||
|
||||
var dirInfo = new DirectoryInfo(originalDir);
|
||||
if (!Directory.Exists(hostDir))
|
||||
{
|
||||
throw new ArgumentException($"'{nameof(hostDir)}' must point to an existing directory.");
|
||||
}
|
||||
|
||||
var dirInfo = new DirectoryInfo(hostDir);
|
||||
|
||||
// Copy the host directory to a different location and mount that one as it's always possible that a
|
||||
// single sample app could be tested by different tests and we do not want to modify its original state
|
||||
|
@ -94,7 +94,7 @@ namespace Microsoft.Oryx.Tests.Common
|
|||
tempDirRoot,
|
||||
Guid.NewGuid().ToString("N"),
|
||||
dirInfo.Name);
|
||||
CopyDirectories(originalDir, writableHostDir, copySubDirs: true);
|
||||
CopyDirectories(hostDir, writableHostDir, copySubDirs: true);
|
||||
|
||||
// Grant permissions to the folder we just copied on the host machine. The permisions here allow the
|
||||
// user(a non-root user) in the container to read/write/execute files.
|
||||
|
@ -113,7 +113,7 @@ namespace Microsoft.Oryx.Tests.Common
|
|||
// Note: Path.Combine is the ideal solution here but this would fail when we run the
|
||||
// tests on a windows machine (which most of us use).
|
||||
var containerDir = $"{ContainerDirRoot}/{containerDirName}";
|
||||
return new DockerVolume(originalDir, writableHostDir, containerDir);
|
||||
return new DockerVolume(hostDir, writableHostDir, containerDir);
|
||||
}
|
||||
|
||||
private static void CopyDirectories(string sourceDirName, string destDirName, bool copySubDirs)
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
<LangVersion>7.3</LangVersion>
|
||||
<RootNamespace>Microsoft.Oryx.Tests.Common</RootNamespace>
|
||||
<AssemblyName>Microsoft.Oryx.Tests.Common</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>..\..\build\TestAssembliesKey.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Microsoft.Oryx.Tests.Common
|
|||
|
||||
public ShellScriptBuilder CreateFile(string file, string content)
|
||||
{
|
||||
return Append($"echo \"{content}\" > \"{file}\"");
|
||||
return Append($"echo {content} > \"{file}\"");
|
||||
}
|
||||
|
||||
public ShellScriptBuilder SetExecutePermissionOnFile(string file)
|
||||
|
@ -104,16 +104,16 @@ namespace Microsoft.Oryx.Tests.Common
|
|||
public ShellScriptBuilder AddStringExistsInFileCheck(string searchString, string file)
|
||||
{
|
||||
return Append(
|
||||
$"grep '{searchString}' '{file}' && if [ $? -eq 1 ]; then " +
|
||||
$"echo '{searchString}' not found 1>&2 && " +
|
||||
$"if ! grep -q '{searchString}' '{file}'; then " +
|
||||
$"echo '{searchString}' not found 1>&2; " +
|
||||
"exit 1; fi");
|
||||
}
|
||||
|
||||
public ShellScriptBuilder AddStringDoesNotExistInFileCheck(string searchString, string file)
|
||||
{
|
||||
return Append(
|
||||
$"grep '{searchString}' '{file}' && if [ $? -eq 0 ]; then " +
|
||||
$"echo '{searchString}' found 1>&2 && " +
|
||||
$"if grep -q '{searchString}' '{file}'; then " +
|
||||
$"echo '{searchString}' still found 1>&2; " +
|
||||
"exit 1; fi");
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче