Merge latest build definitions and tests from nightly repo
This commit is contained in:
Родитель
d506a05190
Коммит
d1c363450b
|
@ -1,2 +1,19 @@
|
|||
# test assets
|
||||
.test-assets/
|
||||
# Build output
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# cache for misc downloads
|
||||
artifacts/
|
||||
|
||||
# dotnet install directory
|
||||
.dotnet/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
|
||||
# Visual Studio Code cache/options directory
|
||||
.vscode/
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
|
|
|
@ -8,6 +8,8 @@ param(
|
|||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$(docker version) | % { Write-Host "$_" }
|
||||
|
||||
if ($UseImageCache) {
|
||||
$optionalDockerBuildArgs = ""
|
||||
}
|
||||
|
@ -49,6 +51,6 @@ $manifestRepo.Images |
|
|||
}
|
||||
}
|
||||
|
||||
./test/run-test.ps1 -UseImageCache:$UseImageCache -Filter $Filter -Architecture $Architecture
|
||||
./test/run-test.ps1 -Filter $Filter -Architecture $Architecture
|
||||
|
||||
Write-Host "Tags built and tested:`n$($builtTags | Out-String)"
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
"value": "microsoft/dotnet-buildtools-prereqs:image-builder-jessie-20170817154316"
|
||||
},
|
||||
"image-builder.args": {
|
||||
"value": "build --manifest manifest.json --path $(PB.image-builder.path) --architecture arm --test-var Filter=$(PB.image-builder.path) --test-var Architecture=arm --push --username $(PB.docker.username) --password $(PB.docker.password) $(PB.image-builder.customCommonArgs)",
|
||||
"value": "build --manifest manifest.json --path $(PB.image-builder.path) --architecture arm --skip-test --test-var Filter=$(PB.image-builder.path) --test-var Architecture=arm --push --username $(PB.docker.username) --password $(PB.docker.password) $(PB.image-builder.customCommonArgs)",
|
||||
"allowOverride": true
|
||||
},
|
||||
"PB.docker.password": {
|
||||
|
|
|
@ -16,19 +16,13 @@
|
|||
{
|
||||
"Name": "dotnet-docker-linux-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "1.0"
|
||||
"PB.image-builder.path": "1."
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "dotnet-docker-linux-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "dotnet-docker-linux-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "2.0"
|
||||
"PB.image-builder.path": "2."
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -42,7 +36,7 @@
|
|||
{
|
||||
"Name": "dotnet-docker-linux-arm32v7-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "2.0"
|
||||
"PB.image-builder.path": "2."
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -56,13 +50,7 @@
|
|||
{
|
||||
"Name": "dotnet-docker-windows-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "dotnet-docker-windows-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "1.1"
|
||||
"PB.image-builder.path": "1."
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -70,6 +58,12 @@
|
|||
"Parameters": {
|
||||
"PB.image-builder.path": "2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "dotnet-docker-windows-amd64-images",
|
||||
"Parameters": {
|
||||
"PB.image-builder.path": "2.1"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -4,11 +4,11 @@ def project = GithubProject
|
|||
def branch = GithubBranchName
|
||||
def isPR = true
|
||||
def platformList = ['Ubuntu16.04:Debian', 'Windows_2016:NanoServer']
|
||||
def versionList = ['1.0', '1.1', '2.0']
|
||||
|
||||
platformList.each { platform ->
|
||||
def(hostOS, containerOS) = platform.tokenize(':')
|
||||
def machineLabel = (hostOS == 'Windows_2016') ? 'latest-docker' : 'latest-or-auto-docker'
|
||||
def versionList = (hostOS == 'Windows_2016') ? ['1.', '2.0', '2.1'] : ['1.', '2.']
|
||||
|
||||
versionList.each { version ->
|
||||
def newJobName = Utilities.getFullJobName(project, "${containerOS}_${version}", isPR)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
FROM {image}
|
||||
|
||||
RUN dotnet restore -r debian.8-x64 {optionalRestoreParams}
|
|
@ -12,7 +12,7 @@ RUN apt-get update \
|
|||
libcurl3 \
|
||||
libunwind8 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
RUN curl -o powershell.deb -ssL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.15/powershell_6.0.0-alpha.15-1ubuntu1.16.04.1_amd64.deb \
|
||||
RUN curl -o powershell.deb -ssL https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-beta.6/powershell_6.0.0-beta.6-1ubuntu1.16.04.1_amd64.deb \
|
||||
&& dpkg -i powershell.deb \
|
||||
&& rm -f powershell.deb
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
FROM {image}
|
||||
|
||||
WORKDIR test
|
||||
RUN dotnet new {dotnetNewParam}
|
||||
RUN dotnet restore {optionalRestoreParams}
|
||||
RUN dotnet build
|
|
@ -0,0 +1,102 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Docker.Tests
|
||||
{
|
||||
public class DockerHelper
|
||||
{
|
||||
public static string DockerOS => GetDockerOS();
|
||||
public static string ContainerWorkDir => IsLinuxContainerModeEnabled ? "/sandbox" : "c:\\sandbox";
|
||||
public static bool IsLinuxContainerModeEnabled => string.Equals(DockerOS, "linux", StringComparison.OrdinalIgnoreCase);
|
||||
private ITestOutputHelper Output { get; set; }
|
||||
|
||||
public DockerHelper(ITestOutputHelper output)
|
||||
{
|
||||
Output = output;
|
||||
}
|
||||
|
||||
public void Build(string dockerfile, string tag, string fromImage, params string[] buildArgs)
|
||||
{
|
||||
string buildArgsOption = $"--build-arg base_image={fromImage}";
|
||||
if (buildArgs != null)
|
||||
{
|
||||
foreach (string arg in buildArgs)
|
||||
{
|
||||
buildArgsOption += $" --build-arg {arg}";
|
||||
}
|
||||
}
|
||||
|
||||
Execute($"build -t {tag} {buildArgsOption} -f {dockerfile} .");
|
||||
}
|
||||
|
||||
public void DeleteImage(string name)
|
||||
{
|
||||
if (ResourceExists("image", name))
|
||||
{
|
||||
Execute($"image rm -f {name}");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteVolume(string name)
|
||||
{
|
||||
if (ResourceExists("volume", name))
|
||||
{
|
||||
Execute($"volume rm -f {name}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Execute(string args)
|
||||
{
|
||||
Output.WriteLine($"Executing : docker {args}");
|
||||
ProcessStartInfo info = new ProcessStartInfo("docker", args);
|
||||
info.RedirectStandardOutput = true;
|
||||
info.RedirectStandardError = true;
|
||||
Process process = Process.Start(info);
|
||||
process.WaitForExit();
|
||||
Output.WriteLine(process.StandardOutput.ReadToEnd());
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
string stdErr = process.StandardError.ReadToEnd();
|
||||
string msg = $"Failed to execute {info.FileName} {info.Arguments}{Environment.NewLine}{stdErr}";
|
||||
throw new InvalidOperationException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetDockerOS()
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo("docker", "version -f \"{{ .Server.Os }}\"");
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
Process process = Process.Start(startInfo);
|
||||
process.WaitForExit();
|
||||
return process.StandardOutput.ReadToEnd().Trim();
|
||||
}
|
||||
|
||||
public string GetContainerWorkPath(string relativePath)
|
||||
{
|
||||
string separator = IsLinuxContainerModeEnabled ? "/" : "\\";
|
||||
return $"{ContainerWorkDir}{separator}{relativePath}";
|
||||
}
|
||||
|
||||
private static bool ResourceExists(string type, string id)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo("docker", $"{type} ls -q {id}");
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
Process process = Process.Start(startInfo);
|
||||
process.WaitForExit();
|
||||
return process.ExitCode == 0 && process.StandardOutput.ReadToEnd().Trim() != "";
|
||||
}
|
||||
|
||||
public void Run(string image, string command, string containerName, string volumeName = null)
|
||||
{
|
||||
string volumeArg = volumeName == null ? string.Empty : $" -v {volumeName}:{ContainerWorkDir}";
|
||||
Execute($"run --rm --name {containerName}{volumeArg} {image} {command}");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
ARG base_image
|
||||
FROM $base_image
|
||||
|
||||
ARG netcoreapp_version
|
||||
ARG optional_new_args
|
||||
|
||||
WORKDIR testApp
|
||||
RUN dotnet new console --framework netcoreapp$netcoreapp_version $optional_new_args
|
||||
RUN dotnet restore -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json -s https://api.nuget.org/v3/index.json
|
||||
RUN dotnet build
|
|
@ -0,0 +1,5 @@
|
|||
ARG base_image
|
||||
FROM $base_image
|
||||
|
||||
ARG rid
|
||||
RUN dotnet restore -r $rid -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json -s https://api.nuget.org/v3/index.json
|
|
@ -0,0 +1,10 @@
|
|||
ARG base_image
|
||||
FROM $base_image
|
||||
|
||||
ARG netcoreapp_version
|
||||
ARG optional_new_args
|
||||
|
||||
WORKDIR testApp
|
||||
RUN dotnet new console --framework netcoreapp$env:netcoreapp_version $env:optional_new_args
|
||||
RUN dotnet restore -s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json -s https://api.nuget.org/v3/index.json
|
||||
RUN dotnet build
|
|
@ -0,0 +1,13 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace Microsoft.DotNet.Docker.Tests
|
||||
{
|
||||
public enum DotNetImageType
|
||||
{
|
||||
SDK,
|
||||
Runtime,
|
||||
Runtime_Deps,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.Docker.Tests
|
||||
{
|
||||
public class ImageDescriptor
|
||||
{
|
||||
private string runtimeDepsVersion;
|
||||
private string sdkVersion;
|
||||
private string sdkOsVariant;
|
||||
|
||||
public string Architecture { get; set; } = "amd64";
|
||||
public string DotNetCoreVersion { get; set; }
|
||||
public bool IsArm { get => String.Equals("arm", Architecture, StringComparison.OrdinalIgnoreCase); }
|
||||
public string OsVariant { get; set; }
|
||||
|
||||
public string RuntimeDepsVersion
|
||||
{
|
||||
get { return runtimeDepsVersion ?? DotNetCoreVersion; }
|
||||
set { runtimeDepsVersion = value; }
|
||||
}
|
||||
|
||||
public string SdkVersion
|
||||
{
|
||||
get { return sdkVersion ?? DotNetCoreVersion; }
|
||||
set { sdkVersion = value; }
|
||||
}
|
||||
|
||||
public string SdkOsVariant
|
||||
{
|
||||
get { return sdkOsVariant ?? OsVariant; }
|
||||
set { sdkOsVariant = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,234 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.DotNet.Docker.Tests
|
||||
{
|
||||
public class ImageTests
|
||||
{
|
||||
private static string ArchFilter => Environment.GetEnvironmentVariable("IMAGE_ARCH_FILTER");
|
||||
private static string VersionFilter => Environment.GetEnvironmentVariable("IMAGE_VERSION_FILTER");
|
||||
|
||||
private DockerHelper DockerHelper { get; set; }
|
||||
|
||||
public ImageTests(ITestOutputHelper output)
|
||||
{
|
||||
DockerHelper = new DockerHelper(output);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GetVerifyImagesData()
|
||||
{
|
||||
List<ImageDescriptor> testData = new List<ImageDescriptor>
|
||||
{
|
||||
new ImageDescriptor {DotNetCoreVersion = "1.0", SdkVersion = "1.1"},
|
||||
new ImageDescriptor {DotNetCoreVersion = "1.1", RuntimeDepsVersion = "1.0"},
|
||||
new ImageDescriptor {DotNetCoreVersion = "2.0"},
|
||||
new ImageDescriptor {DotNetCoreVersion = "2.1", RuntimeDepsVersion = "2.0"},
|
||||
};
|
||||
|
||||
if (DockerHelper.IsLinuxContainerModeEnabled)
|
||||
{
|
||||
testData.AddRange(new List<ImageDescriptor>
|
||||
{
|
||||
new ImageDescriptor {DotNetCoreVersion = "2.0", OsVariant = "jessie"},
|
||||
new ImageDescriptor
|
||||
{
|
||||
DotNetCoreVersion = "2.0",
|
||||
OsVariant = "stretch",
|
||||
SdkOsVariant = "",
|
||||
Architecture = "arm"
|
||||
},
|
||||
new ImageDescriptor
|
||||
{
|
||||
DotNetCoreVersion = "2.1",
|
||||
RuntimeDepsVersion = "2.0",
|
||||
OsVariant = "jessie"
|
||||
},
|
||||
new ImageDescriptor
|
||||
{
|
||||
DotNetCoreVersion = "2.1",
|
||||
RuntimeDepsVersion = "2.0",
|
||||
OsVariant = "stretch",
|
||||
SdkOsVariant = "",
|
||||
Architecture ="arm"
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Filter out test data that does not match the active architecture and version filters.
|
||||
return testData
|
||||
.Where(imageDescriptor => ArchFilter == null
|
||||
|| string.Equals(imageDescriptor.Architecture, ArchFilter, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(imageDescriptor => VersionFilter == null
|
||||
|| imageDescriptor.DotNetCoreVersion.StartsWith(VersionFilter))
|
||||
.Select(imageDescriptor => new object[] { imageDescriptor });
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetVerifyImagesData))]
|
||||
public void VerifyImages(ImageDescriptor imageDescriptor)
|
||||
{
|
||||
string appSdkImage = GetIdentifier(imageDescriptor.DotNetCoreVersion, "app-sdk");
|
||||
|
||||
try
|
||||
{
|
||||
CreateTestAppWithSdkImage(imageDescriptor, appSdkImage);
|
||||
|
||||
if (!imageDescriptor.IsArm)
|
||||
{
|
||||
VerifySdkImage_RunApp(imageDescriptor, appSdkImage);
|
||||
}
|
||||
|
||||
VerifyRuntimeImage_FrameworkDependentApp(imageDescriptor, appSdkImage);
|
||||
|
||||
if (DockerHelper.IsLinuxContainerModeEnabled)
|
||||
{
|
||||
VerifyRuntimeDepsImage_SelfContainedApp(imageDescriptor, appSdkImage);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DockerHelper.DeleteImage(appSdkImage);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTestAppWithSdkImage(ImageDescriptor imageDescriptor, string appSdkImage)
|
||||
{
|
||||
// dotnet new, restore, build a new app using the sdk image
|
||||
List<string> buildArgs = new List<string>();
|
||||
buildArgs.Add($"netcoreapp_version={imageDescriptor.DotNetCoreVersion}");
|
||||
if (!imageDescriptor.SdkVersion.StartsWith("1."))
|
||||
{
|
||||
buildArgs.Add($"optional_new_args=--no-restore");
|
||||
}
|
||||
|
||||
string sdkImage = GetDotNetImage(
|
||||
imageDescriptor.DotNetCoreVersion, DotNetImageType.SDK, imageDescriptor.SdkOsVariant);
|
||||
|
||||
DockerHelper.Build(
|
||||
dockerfile: $"Dockerfile.{DockerHelper.DockerOS.ToLower()}.testapp",
|
||||
tag: appSdkImage,
|
||||
fromImage: sdkImage,
|
||||
buildArgs: buildArgs.ToArray());
|
||||
}
|
||||
|
||||
private void VerifySdkImage_RunApp(ImageDescriptor imageDescriptor, string appSdkImage)
|
||||
{
|
||||
// dotnet run the new app using the sdk image
|
||||
DockerHelper.Run(
|
||||
image: appSdkImage,
|
||||
command: "dotnet run",
|
||||
containerName: appSdkImage);
|
||||
}
|
||||
|
||||
private void VerifyRuntimeImage_FrameworkDependentApp(ImageDescriptor imageDescriptor, string appSdkImage)
|
||||
{
|
||||
string frameworkDepAppId = GetIdentifier(imageDescriptor.DotNetCoreVersion, "framework-dependent-app");
|
||||
|
||||
try
|
||||
{
|
||||
// Publish the app to a Docker volume using the app's sdk image
|
||||
DockerHelper.Run(
|
||||
image: appSdkImage,
|
||||
command: $"dotnet publish -o {DockerHelper.ContainerWorkDir}",
|
||||
containerName: frameworkDepAppId,
|
||||
volumeName: frameworkDepAppId);
|
||||
|
||||
// Run the app in the Docker volume to verify the runtime image
|
||||
string runtimeImage = GetDotNetImage(
|
||||
imageDescriptor.DotNetCoreVersion,
|
||||
DotNetImageType.Runtime,
|
||||
imageDescriptor.OsVariant,
|
||||
imageDescriptor.IsArm);
|
||||
string appDllPath = DockerHelper.GetContainerWorkPath("testApp.dll");
|
||||
DockerHelper.Run(
|
||||
image: runtimeImage,
|
||||
command: $"dotnet {appDllPath}",
|
||||
containerName: frameworkDepAppId,
|
||||
volumeName: frameworkDepAppId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DockerHelper.DeleteVolume(frameworkDepAppId);
|
||||
}
|
||||
}
|
||||
|
||||
private void VerifyRuntimeDepsImage_SelfContainedApp(ImageDescriptor imageDescriptor, string appSdkImage)
|
||||
{
|
||||
string selfContainedAppId = GetIdentifier(imageDescriptor.DotNetCoreVersion, "self-contained-app");
|
||||
string rid = imageDescriptor.IsArm ? "linux-arm" : "debian.8-x64";
|
||||
|
||||
try
|
||||
{
|
||||
// Build a self-contained app
|
||||
DockerHelper.Build(
|
||||
dockerfile: "Dockerfile.linux.testapp.selfcontained",
|
||||
tag: selfContainedAppId,
|
||||
fromImage: appSdkImage,
|
||||
buildArgs: $"rid={rid}");
|
||||
|
||||
try
|
||||
{
|
||||
// Publish the self-contained app to a Docker volume using the app's sdk image
|
||||
string optionalPublishArgs = imageDescriptor.DotNetCoreVersion.StartsWith("1.") ? "" : "--no-restore";
|
||||
string dotNetCmd = $"dotnet publish -r {rid} -o {DockerHelper.ContainerWorkDir} {optionalPublishArgs}";
|
||||
DockerHelper.Run(
|
||||
image: selfContainedAppId,
|
||||
command: dotNetCmd,
|
||||
containerName: selfContainedAppId,
|
||||
volumeName: selfContainedAppId);
|
||||
|
||||
// Run the self-contained app in the Docker volume to verify the runtime-deps image
|
||||
string runtimeDepsImage = GetDotNetImage(
|
||||
imageDescriptor.RuntimeDepsVersion,
|
||||
DotNetImageType.Runtime_Deps,
|
||||
imageDescriptor.OsVariant,
|
||||
imageDescriptor.IsArm);
|
||||
string appExePath = DockerHelper.GetContainerWorkPath("testApp");
|
||||
DockerHelper.Run(
|
||||
image: runtimeDepsImage,
|
||||
command: appExePath,
|
||||
containerName: selfContainedAppId,
|
||||
volumeName: selfContainedAppId);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DockerHelper.DeleteVolume(selfContainedAppId);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DockerHelper.DeleteImage(selfContainedAppId);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetDotNetImage(
|
||||
string imageVersion, DotNetImageType imageType, string osVariant, bool isArm = false)
|
||||
{
|
||||
string variantName = Enum.GetName(typeof(DotNetImageType), imageType).ToLowerInvariant().Replace('_', '-');
|
||||
string imageName = $"microsoft/dotnet:{imageVersion}-{variantName}";
|
||||
if (!string.IsNullOrEmpty(osVariant))
|
||||
{
|
||||
imageName += $"-{osVariant}";
|
||||
}
|
||||
|
||||
if (isArm)
|
||||
{
|
||||
imageName += $"-arm32v7";
|
||||
}
|
||||
|
||||
return imageName;
|
||||
}
|
||||
|
||||
private static string GetIdentifier(string version, string type)
|
||||
{
|
||||
return $"{version}-{type}-{DateTime.Now.ToFileTime()}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Dockerfile.*">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26923.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Docker.Tests", "Microsoft.DotNet.Docker.Tests.csproj", "{C645FD53-8170-49F6-9ECB-B9C4B6683284}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C645FD53-8170-49F6-9ECB-B9C4B6683284}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C645FD53-8170-49F6-9ECB-B9C4B6683284}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C645FD53-8170-49F6-9ECB-B9C4B6683284}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C645FD53-8170-49F6-9ECB-B9C4B6683284}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {23A3AC51-ED6C-46EB-B451-EDEF76476E0D}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,6 +1,10 @@
|
|||
#
|
||||
# Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
#
|
||||
|
||||
[cmdletbinding()]
|
||||
param(
|
||||
[switch]$UseImageCache,
|
||||
[string]$Filter,
|
||||
[string]$Architecture
|
||||
)
|
||||
|
@ -8,142 +12,51 @@ param(
|
|||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Exec([scriptblock]$cmd, [string]$errorMessage = "Error executing command: " + $cmd) {
|
||||
& $cmd
|
||||
if ($LastExitCode -ne 0) {
|
||||
throw $errorMessage
|
||||
}
|
||||
$DotnetInstallDir = "$PSScriptRoot/../.dotnet"
|
||||
|
||||
if (!(Test-Path "$DotnetInstallDir")) {
|
||||
mkdir "$DotnetInstallDir" | Out-Null
|
||||
}
|
||||
|
||||
function Get-ActivePlatformImages([PSCustomObject]$manifestRepo, [string]$activeOS) {
|
||||
return $manifestRepo.Images |
|
||||
ForEach-Object { $_.Platforms } |
|
||||
Where-Object { $_.os -eq "$activeOS" } |
|
||||
Where-Object { ( [string]::IsNullOrEmpty($Architecture) -and -not [bool]($_.PSobject.Properties.name -match "architecture"))`
|
||||
-or ( [bool]($_.PSobject.Properties.name -match "architecture") -and $_.architecture -eq "$Architecture" ) }
|
||||
}
|
||||
|
||||
function Get-RuntimeTag([string]$sdkDockerfilePath, [string]$runtimeType, [string]$activeOS, [PSCustomObject]$manifestRepo) {
|
||||
$runtimeDockerfilePath = $sdkDockerfilePath.Replace("sdk", $runtimeType)
|
||||
$platforms = Get-ActivePlatformImages $manifestRepo $activeOS |
|
||||
Where-Object { $_.Dockerfile -eq $runtimeDockerfilePath }
|
||||
return $manifestRepo.Name + ':' + ([array]($_.Tags | ForEach-Object { $_.PSobject.Properties }))[0].Name
|
||||
}
|
||||
|
||||
if ($UseImageCache) {
|
||||
$optionalDockerBuildArgs = ""
|
||||
# Install the .NET Core SDK
|
||||
$IsRunningOnUnix = $PSVersionTable.contains("Platform") -and $PSVersionTable.Platform -eq "Unix"
|
||||
if ($IsRunningOnUnix) {
|
||||
$DotnetInstallScript = "dotnet-install.sh"
|
||||
}
|
||||
else {
|
||||
$optionalDockerBuildArgs = "--no-cache"
|
||||
$DotnetInstallScript = "dotnet-install.ps1"
|
||||
}
|
||||
|
||||
$dirSeparator = [IO.Path]::DirectorySeparatorChar
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$manifestPath = [IO.Path]::combine(${repoRoot}, "manifest.json")
|
||||
$manifestRepo = (Get-Content $manifestPath | ConvertFrom-Json).Repos[0]
|
||||
$testFilesPath = "$PSScriptRoot$dirSeparator"
|
||||
$activeOS = docker version -f "{{ .Server.Os }}"
|
||||
if (!(Test-Path $DotnetInstallScript)) {
|
||||
$DOTNET_INSTALL_SCRIPT_URL = "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0/scripts/obtain/$DotnetInstallScript"
|
||||
Invoke-WebRequest $DOTNET_INSTALL_SCRIPT_URL -OutFile $DotnetInstallDir/$DotnetInstallScript
|
||||
}
|
||||
|
||||
# update as appropriate (e.g. "2.0-sdk") whenever pre-release packages are referenced prior to being available on NuGet.org.
|
||||
$includePrereleasePackageSourceForSdkTag = $null
|
||||
|
||||
if ($activeOS -eq "windows") {
|
||||
$containerRoot = "C:\"
|
||||
$platformDirSeparator = '\'
|
||||
if ($IsRunningOnUnix) {
|
||||
& chmod +x $DotnetInstallDir/$DotnetInstallScript
|
||||
& $DotnetInstallDir/$DotnetInstallScript --channel "release-2.0.0" --version "2.0.0" --architecture x64 --install-dir $DotnetInstallDir
|
||||
}
|
||||
else {
|
||||
$containerRoot = "/"
|
||||
$platformDirSeparator = '/'
|
||||
& $DotnetInstallDir/$DotnetInstallScript -Channel "release-2.0.0" -Version "2.0.0" -Architecture x64 -InstallDir $DotnetInstallDir
|
||||
}
|
||||
|
||||
# Loop through each sdk Dockerfile in the repo and test the sdk and runtime images.
|
||||
Get-ActivePlatformImages $manifestRepo $activeOS |
|
||||
Where-Object { [string]::IsNullOrEmpty($Filter) -or $_.dockerfile -like "$Filter*" } |
|
||||
Where-Object { $_.Dockerfile.Contains('sdk') } |
|
||||
ForEach-Object {
|
||||
$sdkTag = ([array]($_.Tags | ForEach-Object { $_.PSobject.Properties }))[0].Name
|
||||
$fullSdkTag = "$($manifestRepo.Name):${sdkTag}"
|
||||
if ($LASTEXITCODE -ne 0) { throw "Failed to install the .NET Core SDK" }
|
||||
|
||||
$timeStamp = Get-Date -Format FileDateTime
|
||||
$appName = "app$timeStamp".ToLower()
|
||||
$buildImage = "sdk-build-$appName"
|
||||
$dotnetNewParam = "console --framework netcoreapp$($sdkTag.Split('-')[0].Substring(0,3))"
|
||||
Push-Location "$PSScriptRoot\Microsoft.DotNet.Docker.Tests"
|
||||
|
||||
$optionalRestoreParams = ""
|
||||
if ($sdkTag -like $includePrereleasePackageSourceForSdkTag) {
|
||||
$optionalRestoreParams = "-s https://dotnet.myget.org/F/dotnet-core/api/v3/index.json -s https://api.nuget.org/v3/index.json"
|
||||
}
|
||||
|
||||
Write-Host "----- Testing create, restore and build with $fullSdkTag with image $buildImage -----"
|
||||
Try {
|
||||
exec { (Get-Content ${testFilesPath}Dockerfile.test).
|
||||
Replace("{image}", $fullSdkTag).
|
||||
Replace("{dotnetNewParam}", $dotnetNewParam).
|
||||
Replace("{optionalRestoreParams}", $optionalRestoreParams) `
|
||||
| docker build $optionalDockerBuildArgs -t $buildImage -
|
||||
}
|
||||
|
||||
Write-Host "----- Running app built on $fullSdkTag -----"
|
||||
exec { docker run --rm $buildImage dotnet run }
|
||||
|
||||
$framworkDepVol = "framework-dep-publish-$appName"
|
||||
Write-Host "----- Publishing framework-dependant app built on $fullSdkTag to volume $framworkDepVol -----"
|
||||
Try {
|
||||
exec { docker run --rm `
|
||||
-v ${framworkDepVol}:"${containerRoot}volume" `
|
||||
$buildImage `
|
||||
dotnet publish -o ${containerRoot}volume
|
||||
}
|
||||
|
||||
$fullRuntimeTag = Get-RuntimeTag $_.Dockerfile "runtime" $activeOS $manifestRepo
|
||||
Write-Host "----- Testing on $fullRuntimeTag with $sdkTag framework-dependent app -----"
|
||||
exec { docker run --rm `
|
||||
-v ${framworkDepVol}":${containerRoot}volume" `
|
||||
"$fullRuntimeTag" `
|
||||
dotnet "${containerRoot}volume${platformDirSeparator}test.dll"
|
||||
}
|
||||
}
|
||||
Finally {
|
||||
docker volume rm $framworkDepVol
|
||||
}
|
||||
|
||||
if ($activeOS -eq "linux") {
|
||||
$selfContainedImage = "self-contained-build-${buildImage}"
|
||||
Write-Host "----- Creating publish-image for self-contained app built on $fullSdkTag -----"
|
||||
Try {
|
||||
exec { (Get-Content ${testFilesPath}Dockerfile.linux.publish).
|
||||
Replace("{image}", $buildImage).
|
||||
Replace("{optionalRestoreParams}", $optionalRestoreParams) `
|
||||
| docker build $optionalDockerBuildArgs -t $selfContainedImage -
|
||||
}
|
||||
|
||||
$selfContainedVol = "self-contained-publish-$appName"
|
||||
Write-Host "----- Publishing self-contained published app built on $fullSdkTag to volume $selfContainedVol using image $selfContainedImage -----"
|
||||
Try {
|
||||
exec { docker run --rm `
|
||||
-v ${selfContainedVol}":${containerRoot}volume" `
|
||||
$selfContainedImage `
|
||||
dotnet publish -r debian.8-x64 -o ${containerRoot}volume
|
||||
}
|
||||
|
||||
$fullRuntimeDepsTag = Get-RuntimeTag $_.Dockerfile "runtime-deps" $activeOS $manifestRepo
|
||||
Write-Host "----- Testing $fullRuntimeDepsTag with $sdkTag self-contained app -----"
|
||||
exec { docker run -t --rm `
|
||||
-v ${selfContainedVol}":${containerRoot}volume" `
|
||||
$fullRuntimeDepsTag `
|
||||
${containerRoot}volume${platformDirSeparator}test
|
||||
}
|
||||
}
|
||||
Finally {
|
||||
docker volume rm $selfContainedVol
|
||||
}
|
||||
}
|
||||
Finally {
|
||||
docker image rm $selfContainedImage
|
||||
}
|
||||
}
|
||||
}
|
||||
Finally {
|
||||
docker image rm $buildImage
|
||||
}
|
||||
Try {
|
||||
# Run Tests
|
||||
if ([string]::IsNullOrWhiteSpace($Architecture)) {
|
||||
$Architecture = "amd64"
|
||||
}
|
||||
|
||||
$env:IMAGE_ARCH_FILTER = $Architecture
|
||||
$env:IMAGE_VERSION_FILTER = $Filter
|
||||
|
||||
& $DotnetInstallDir/dotnet test -v n
|
||||
|
||||
if ($LASTEXITCODE -ne 0) { throw "Tests Failed" }
|
||||
}
|
||||
Finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче