Skip to content

Commit 9ddf6f7

Browse files
authoredJun 24, 2020
Add test script for Image Builder (#567)
1 parent f200f99 commit 9ddf6f7

File tree

15 files changed

+93
-21
lines changed

15 files changed

+93
-21
lines changed
 

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
# ImageBuilder directory
1515
.Microsoft.DotNet.ImageBuilder
16+
17+
# dotnet install directory
18+
.dotnet/
19+
20+
# Test files
21+
*.trx

‎eng/common/Install-DotNetSdk.ps1

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env pwsh
2+
#
3+
# Copyright (c) .NET Foundation and contributors. All rights reserved.
4+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
#
6+
7+
<#
8+
.SYNOPSIS
9+
Install the .NET Core SDK at the specified path.
10+
11+
.PARAMETER InstallPath
12+
The path where the .NET Core SDK is to be installed.
13+
14+
#>
15+
[cmdletbinding()]
16+
param(
17+
[string]
18+
$InstallPath
19+
)
20+
21+
Set-StrictMode -Version Latest
22+
$ErrorActionPreference = 'Stop'
23+
24+
if (!(Test-Path "$InstallPath")) {
25+
mkdir "$InstallPath" | Out-Null
26+
}
27+
28+
$IsRunningOnUnix = $PSVersionTable.contains("Platform") -and $PSVersionTable.Platform -eq "Unix"
29+
if ($IsRunningOnUnix) {
30+
$DotnetInstallScript = "dotnet-install.sh"
31+
}
32+
else {
33+
$DotnetInstallScript = "dotnet-install.ps1"
34+
}
35+
36+
if (!(Test-Path $DotnetInstallScript)) {
37+
Invoke-WebRequest "https://dot.net/v1/$DotnetInstallScript" -OutFile $InstallPath/$DotnetInstallScript
38+
}
39+
40+
if ($IsRunningOnUnix) {
41+
& chmod +x $InstallPath/$DotnetInstallScript
42+
& $InstallPath/$DotnetInstallScript --channel "3.1" --version "latest" --install-dir $InstallPath
43+
}
44+
else {
45+
& $InstallPath/$DotnetInstallScript -Channel "3.1" -Version "latest" -InstallDir $InstallPath
46+
}
47+
48+
if ($LASTEXITCODE -ne 0) { throw "Failed to install the .NET Core SDK" }

‎eng/common/templates/steps/test-images-windows-client.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ steps:
3939
continueOnError: true
4040
inputs:
4141
testRunner: vSTest
42-
testResultsFiles: 'tests/**/*.trx'
42+
testResultsFiles: '$(testResultsDirectory)/**/*.trx'
4343
mergeTestResults: true
4444
publishRunAttachments: true
4545
testRunTitle: $(dotnetVersion) $(osVariant) amd64

‎eng/pipelines/dotnet-docker-tools-eng-validation.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ trigger:
1818
variables:
1919
- template: ../common/templates/variables/common.yml
2020
- name: manifest
21-
value: test/pipeline-validation/test-manifest.json
21+
value: eng/tests/pipeline-validation/test-manifest.json
2222
- name: testScriptPath
23-
value: ./test/pipeline-validation/run-tests.ps1
23+
value: ./eng/tests/pipeline-validation/run-tests.ps1
2424
- name: testResultsDirectory
25-
value: test/pipeline-validation/TestResults/
25+
value: eng/tests/pipeline-validation/TestResults/
2626
- name: publicGitRepoUri
2727
value: https://github.com/dotnet/dotnet-docker-test
2828
- name: publishRepoPrefix

‎eng/pipelines/templates/variables/image-builder.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ variables:
88
value: --var UniqueId=$(sourceBuildId)
99
- name: imageInfoVariant
1010
value: "-imagebuilder"
11+
- name: testScriptPath
12+
value: ./src/Microsoft.DotNet.ImageBuilder/run-tests.ps1
13+
- name: testResultsDirectory
14+
value: src/Microsoft.DotNet.ImageBuilder/tests/TestResults/

‎src/Microsoft.DotNet.ImageBuilder/Dockerfile.linux

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ ARG RID_ARCH=x64
1212
WORKDIR /image-builder
1313

1414
# restore packages before copying entire source - provides optimizations when rebuilding
15-
COPY Microsoft.DotNet.ImageBuilder.sln ./
1615
COPY NuGet.config ./
1716
COPY src/Microsoft.DotNet.ImageBuilder.csproj ./src/
18-
COPY tests/Microsoft.DotNet.ImageBuilder.Tests.csproj ./tests/
19-
RUN dotnet restore Microsoft.DotNet.ImageBuilder.sln
17+
RUN dotnet restore ./src/Microsoft.DotNet.ImageBuilder.csproj
2018

21-
# copy everything else and build
19+
# copy everything else and publish
2220
COPY . ./
23-
RUN dotnet build Microsoft.DotNet.ImageBuilder.sln
24-
RUN dotnet test tests/Microsoft.DotNet.ImageBuilder.Tests.csproj
2521
RUN dotnet publish ./src/Microsoft.DotNet.ImageBuilder.csproj -c Release -o out -r linux-musl-$RID_ARCH /p:ShowLinkerSizeComparison=true
2622

2723

‎src/Microsoft.DotNet.ImageBuilder/Dockerfile.windows

+2-11
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
33
WORKDIR /image-builder
44

55
# restore packages before copying entire source - provides optimizations when rebuilding
6-
COPY Microsoft.DotNet.ImageBuilder.sln ./
76
COPY NuGet.config ./
87
COPY src/Microsoft.DotNet.ImageBuilder.csproj ./src/
9-
COPY tests/Microsoft.DotNet.ImageBuilder.Tests.csproj ./tests/
10-
RUN dotnet restore Microsoft.DotNet.ImageBuilder.sln
8+
RUN dotnet restore ./src/Microsoft.DotNet.ImageBuilder.csproj
119

12-
# copy everything else and build
10+
# copy everything else and publish
1311
COPY . ./
14-
RUN dotnet build Microsoft.DotNet.ImageBuilder.sln
15-
16-
# Workaround: Tests rely on Path.GetTempPath which isn't compatible with the default ContainerUser.
17-
USER ContainerAdministrator
18-
RUN dotnet test tests/Microsoft.DotNet.ImageBuilder.Tests.csproj
19-
USER ContainerUser
20-
2112
RUN dotnet publish ./src/Microsoft.DotNet.ImageBuilder.csproj -c Release -o out -r win7-x64
2213

2314

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env pwsh
2+
#
3+
# Copyright (c) .NET Foundation and contributors. All rights reserved.
4+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
#
6+
7+
Set-StrictMode -Version Latest
8+
$ErrorActionPreference = 'Stop'
9+
10+
$dotnetInstallDir = "$PSScriptRoot/../../.dotnet"
11+
12+
Push-Location $PSScriptRoot
13+
14+
try {
15+
& ../../eng/common/Install-DotNetSdk.ps1 $dotnetInstallDir
16+
17+
$cmd = "$DotnetInstallDir/dotnet test --logger:trx"
18+
19+
Write-Output "Executing '$cmd'"
20+
Invoke-Expression $cmd
21+
if ($LASTEXITCODE -ne 0) {
22+
throw "Failed: '$cmd'"
23+
}
24+
}
25+
finally {
26+
Pop-Location
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.