forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-test.ps1
executable file
·72 lines (62 loc) · 2.79 KB
/
build-and-test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env pwsh
[cmdletbinding()]
param(
[string]$VersionFilter = "*",
[string]$OSFilter = "*",
[string]$ArchitectureFilter = "amd64",
[string]$ImageBuilderCustomArgs,
[switch]$SkipTesting = $false
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Log {
param ([string] $Message)
Write-Output $Message
}
function Exec {
param ([string] $Cmd)
Log "Executing: '$Cmd'"
Invoke-Expression $Cmd
if ($LASTEXITCODE -ne 0) {
throw "Failed: '$Cmd'"
}
}
$windowsImageBuilder = 'microsoft/dotnet-buildtools-prereqs:image-builder-nanoserver-20181022125001'
$linuxImageBuilder = 'microsoft/dotnet-buildtools-prereqs:image-builder-debian-20181022195013'
$imageBuilderContainerName = "ImageBuilder-$(Get-Date -Format yyyyMMddhhmmss)"
pushd $PSScriptRoot
try {
$activeOS = docker version -f "{{ .Server.Os }}"
if ($activeOS -eq "linux") {
# On Linux, ImageBuilder is run within a container. The local repo is copied into a Docker volume
# in order to support running with a remote Docker server.
./scripts/Invoke-WithRetry "docker pull $linuxImageBuilder"
$repoVolume = "repo-$(Get-Date -Format yyyyMMddhhmmss)"
Exec "docker create -v ${repoVolume}:/repo --name $imageBuilderContainerName $linuxImageBuilder"
Exec "docker cp ${PSScriptRoot}/. ${imageBuilderContainerName}:/repo"
Exec "docker container rm -f $imageBuilderContainerName"
$imageBuilderCmd = "docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v ${repoVolume}:/repo -w /repo $linuxImageBuilder"
}
else {
# On Windows, ImageBuild is run locally due to limitations with running Docker client within a container.
$imageBuilderFolder = [System.IO.Path]::Combine($PSScriptRoot, ".Microsoft.DotNet.ImageBuilder")
$imageBuilderCmd = [System.IO.Path]::Combine($imageBuilderFolder, "image-builder", "Microsoft.DotNet.ImageBuilder.exe")
if (-not (Test-Path -Path "$imageBuilderCmd" -PathType Leaf)) {
./scripts/Invoke-WithRetry "docker pull $windowsImageBuilder"
Exec "docker create --name $imageBuilderContainerName $windowsImageBuilder"
New-Item -Path "$imageBuilderFolder" -ItemType Directory -Force
Exec "docker cp ${imageBuilderContainerName}:/image-builder $imageBuilderFolder"
Exec "docker container rm -f $imageBuilderContainerName"
}
}
Exec "$imageBuilderCmd build --path '$VersionFilter/*/$OSFilter/$ArchitectureFilter' $ImageBuilderCustomArgs"
if ($activeOS -eq "linux") {
Exec "docker volume rm -f $repoVolume"
}
if (-not $SkipTesting) {
./tests/run-tests.ps1 -VersionFilter $VersionFilter -ArchitectureFilter $ArchitectureFilter -OSFilter $OSFilter -IsLocalRun
}
}
finally {
popd
}