Merged PR 165398: Multi-language builds should be off by default

We've decided to roll out more conservatively and have multi-language builds off by default.

Related work items: #796284
This commit is contained in:
Gabriel Pedro de Castro 2019-02-22 00:35:32 +00:00
Родитель 3332783b48
Коммит eab931d273
6 изменённых файлов: 125 добавлений и 17 удалений

Просмотреть файл

@ -14,7 +14,7 @@ PROJECT | repo-relative path to directory with `.csproj
DISABLE\_DOTNETCORE\_BUILD | if `true`, the system won't attempt to detect or build any .NET Core code in the repo. |
DISABLE\_PYTHON\_BUILD | if `true`, the system won't attempt to detect or build any Python code in the repo. |
DISABLE\_NODEJS\_BUILD | if `true`, the system won't attempt to detect or build any NodeJS code in the repo. |
DISABLE\_MULTIPLATFORM\_BUILD | if `true`, only the selected platform is used, e.g. in AppService language selection or `oryx build` command; no automatic detection or build for other platforms will be performed. |
ENABLE\_MULTIPLATFORM\_BUILD | if `true`, the system will automatically detect the platforms used in the repo and build them. If needed, each platform can be individually disabled using its own flag described above. |
# Azure Web Apps configuration

Просмотреть файл

@ -77,22 +77,23 @@ namespace Microsoft.Oryx.BuildScriptGenerator
}
bool usePlatform = false;
var currPlatformMatch = !string.IsNullOrEmpty(context.Language) &&
var currPlatformMatchesProvided = !string.IsNullOrEmpty(context.Language) &&
string.Equals(context.Language, platform.Name, StringComparison.OrdinalIgnoreCase);
string targetVersionSpec = null;
if (currPlatformMatch)
if (currPlatformMatchesProvided)
{
providedLanguageFound = true;
targetVersionSpec = context.LanguageVersion;
usePlatform = true;
}
else if (context.DisableMultiPlatformBuild)
else if (context.DisableMultiPlatformBuild && !string.IsNullOrEmpty(context.Language))
{
_logger.LogDebug("Multi platform build is disabled and platform was specified. Skipping language {skippedLang}", platform.Name);
continue;
}
if (!currPlatformMatch || string.IsNullOrEmpty(targetVersionSpec))
if (!currPlatformMatchesProvided || string.IsNullOrEmpty(targetVersionSpec))
{
_logger.LogDebug("Detecting platform using {langPlat}", platform.Name);
var detectionResult = platform.Detect(context.SourceRepo);

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.Oryx.BuildScriptGenerator
/// the detection and build of all other platforms. If set to <c>true</c>, all other languages
/// are disabled even if they are enabled by their specific flags.
/// </summary>
public bool DisableMultiPlatformBuild { get; set; } = false;
public bool DisableMultiPlatformBuild { get; set; } = true;
/// <summary>
/// Gets or sets specific properties for the build script.

Просмотреть файл

@ -12,7 +12,7 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
private const string DisableDotNetCoreEnvVarName = "DISABLE_DOTNETCORE_BUILD";
private const string DisablePythonEnvVarName = "DISABLE_PYTHON_BUILD";
private const string DisableNodeJsEnvVarName = "DISABLE_NODEJS_BUILD";
private const string DisableMultiPlatformBuildEnvVarName = "DISABLE_MULTIPLATFORM_BUILD";
private const string EnableMultiPlatformBuildEnvVarName = "ENABLE_MULTIPLATFORM_BUILD";
private IEnvironment _environment;
@ -21,20 +21,25 @@ namespace Microsoft.Oryx.BuildScriptGeneratorCli
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
}
public bool DisableDotNetCore => IsDisableVariableSet(DisableDotNetCoreEnvVarName);
public bool DisableDotNetCore => IsEnvVariableTrue(DisableDotNetCoreEnvVarName);
public bool DisableNodeJs => IsDisableVariableSet(DisableNodeJsEnvVarName);
public bool DisableNodeJs => IsEnvVariableTrue(DisableNodeJsEnvVarName);
public bool DisablePython => IsDisableVariableSet(DisablePythonEnvVarName);
public bool DisablePython => IsEnvVariableTrue(DisablePythonEnvVarName);
public bool DisableMultiPlatformBuild => IsDisableVariableSet(DisableMultiPlatformBuildEnvVarName);
/// <summary>
/// Gets a value indicating whether multi-platform builds must be disabled.
/// They are disabled by default, so the user must opt-in setting environment
/// variable <c>ENABLE_MULTIPLATFORM_BUILD</c> to <c>true</c>.
/// </summary>
public bool DisableMultiPlatformBuild => !IsEnvVariableTrue(EnableMultiPlatformBuildEnvVarName);
private bool IsDisableVariableSet(string disableEnvVarName)
private bool IsEnvVariableTrue(string disableEnvVarName)
{
var isDisabledVar = _environment.GetBoolEnvironmentVariable(disableEnvVarName);
if (isDisabledVar == true)
{
// The user has set the variable _and_ its value is true, so the feature is disabled.
// The user has set the variable _and_ its value is true.
return true;
}
else

Просмотреть файл

@ -119,7 +119,8 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Tests
var generator = CreateDefaultScriptGenerator(platform);
var context = CreateScriptGeneratorContext(
suppliedLanguageName: null,
suppliedLanguageVersion: null);
suppliedLanguageVersion: null,
enableMultiPlatformBuild: true);
// Act & Assert
var exception = Assert.Throws<UnsupportedLanguageException>(
@ -217,7 +218,7 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Tests
Assert.Equal(
"'unsupported' platform is not supported. Supported platforms are: test",
exception.Message);
Assert.True(detector.DetectInvoked);
Assert.False(detector.DetectInvoked);
}
[Fact]
@ -272,6 +273,105 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Tests
Assert.True(detector.DetectInvoked);
}
[Fact]
public void TryGenerateScript_CallsDetector_IfMultiPlatformIsOff_AndNoLangProvided()
{
// Arrange
var detector = new TestLanguageDetectorUsingLangName(
detectedLanguageName: "test",
detectedLanguageVersion: "1.0.0");
var platform = new TestProgrammingPlatform(
"test",
new[] { "1.0.0" },
canGenerateScript: true,
scriptContent: "script-content",
detector);
var generator = CreateDefaultScriptGenerator(platform);
var context = CreateScriptGeneratorContext(
suppliedLanguageName: null,
suppliedLanguageVersion: null,
enableMultiPlatformBuild: false);
// Act & Assert
var generateOutput = generator.TryGenerateBashScript(context, out var generatedScript);
Assert.True(generateOutput);
Assert.True(detector.DetectInvoked);
}
[Fact]
public void TryGenerateScript_DoesntCallDetector_IfMultiPlatformIsOff_AndLangProvided()
{
// Arrange
var detector = new TestLanguageDetectorUsingLangName(
detectedLanguageName: "test",
detectedLanguageVersion: "1.0.0");
var platform = new TestProgrammingPlatform(
"test",
new[] { "1.0.0" },
canGenerateScript: true,
scriptContent: "script-content",
detector);
var detector2 = new TestLanguageDetectorUsingLangName(
detectedLanguageName: "test2",
detectedLanguageVersion: "1.0.0");
var platform2 = new TestProgrammingPlatform(
"test2",
new[] { "1.0.0" },
canGenerateScript: true,
scriptContent: "script-content",
detector2);
var generator = CreateDefaultScriptGenerator(new[] { platform, platform2 });
var context = CreateScriptGeneratorContext(
suppliedLanguageName: "test",
suppliedLanguageVersion: "1.0.0",
enableMultiPlatformBuild: false);
// Act & Assert
var generateOutput = generator.TryGenerateBashScript(context, out var generatedScript);
Assert.True(generateOutput);
Assert.False(detector.DetectInvoked);
Assert.False(detector2.DetectInvoked);
}
[Fact]
public void TryGenerateScript_CallsDetector_IfMultiPlatformIsOn_AndLangProvided()
{
// Arrange
var detector = new TestLanguageDetectorUsingLangName(
detectedLanguageName: "test",
detectedLanguageVersion: "1.0.0");
var platform = new TestProgrammingPlatform(
"test",
new[] { "1.0.0" },
canGenerateScript: true,
scriptContent: "script-content",
detector);
var detector2 = new TestLanguageDetectorUsingLangName(
detectedLanguageName: "test2",
detectedLanguageVersion: "1.0.0");
var platform2 = new TestProgrammingPlatform(
"test2",
new[] { "1.0.0" },
canGenerateScript: true,
scriptContent: "script-content",
detector2);
var generator = CreateDefaultScriptGenerator(new[] { platform, platform2 });
var context = CreateScriptGeneratorContext(
suppliedLanguageName: "test",
suppliedLanguageVersion: "1.0.0",
enableMultiPlatformBuild: true);
// Act & Assert
var generateOutput = generator.TryGenerateBashScript(context, out var generatedScript);
Assert.True(generateOutput);
Assert.False(detector.DetectInvoked);
Assert.True(detector2.DetectInvoked);
}
[Fact]
public void UsesMaxSatisfyingVersion_WhenOnlyMajorVersion_OfLanguageIsSpecified()
{
@ -456,13 +556,15 @@ namespace Microsoft.Oryx.BuildScriptGenerator.Tests
private static ScriptGeneratorContext CreateScriptGeneratorContext(
string suppliedLanguageName = null,
string suppliedLanguageVersion = null)
string suppliedLanguageVersion = null,
bool enableMultiPlatformBuild = false)
{
return new ScriptGeneratorContext
{
Language = suppliedLanguageName,
LanguageVersion = suppliedLanguageVersion,
SourceRepo = new TestSourceRepo(),
DisableMultiPlatformBuild = !enableMultiPlatformBuild
};
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace BuildScriptGeneratorCli.Tests
yield return new object[] { "DISABLE_DOTNETCORE_BUILD", (Func<CliEnvironmentSettings, bool>)(s => s.DisableDotNetCore) };
yield return new object[] { "DISABLE_PYTHON_BUILD", (Func<CliEnvironmentSettings, bool>)(s => s.DisablePython) };
yield return new object[] { "DISABLE_NODEJS_BUILD", (Func<CliEnvironmentSettings, bool>)(s => s.DisableNodeJs) };
yield return new object[] { "DISABLE_MULTIPLATFORM_BUILD", (Func<CliEnvironmentSettings, bool>)(s => s.DisableMultiPlatformBuild) };
yield return new object[] { "ENABLE_MULTIPLATFORM_BUILD", (Func<CliEnvironmentSettings, bool>)(s => !s.DisableMultiPlatformBuild) };
}
}