forked from dotnet/dotnet-docker-nightly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-test.ps1
57 lines (48 loc) · 1.48 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
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
[ValidateSet("win", "linux")]
[string]$Platform,
[switch]$UseImageCache
)
Set-StrictMode -Version Latest
$ErrorActionPreference="Stop"
$dockerRepo="microsoft/dotnet-nightly"
$dirSeparator = [IO.Path]::DirectorySeparatorChar
if ($UseImageCache) {
$optionalDockerBuildArgs=""
}
else {
$optionalDockerBuildArgs = "--no-cache"
}
if ($Platform -eq "win") {
$imageOs = "nanoserver"
$tagSuffix = "-nanoserver"
}
else {
$imageOs = "debian"
$tagSuffix = ""
}
pushd $PSScriptRoot
$tags = [System.Collections.ArrayList]@()
Get-ChildItem -Recurse -Filter Dockerfile |
where {$_.DirectoryName.TrimStart($PSScriptRoot) -like "*$dirSeparator$imageOs*"} |
# sort in descending order to ensure runtime-deps get built before runtime to satisfy dependency
Sort-Object {$_.DirectoryName} -Descending |
foreach {
$tag = "${dockerRepo}:" +
$_.DirectoryName.
Replace("$PSScriptRoot$dirSeparator", '').
Replace("$dirSeparator$imageOs", '').
Replace($dirSeparator, '-') +
$tagSuffix
$tags.Add($tag) | Out-Null
Write-Host "--- Building $tag from $($_.DirectoryName) ---"
docker build $optionalDockerBuildArgs -t $tag $_.DirectoryName
if (-NOT $?) {
throw "Failed building $tag"
}
}
popd
./test/run-test.ps1 -Platform $Platform
Write-Host "Tags built and tested:`n$($tags | Out-String)"