forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-and-test.ps1
56 lines (46 loc) · 1.45 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
[cmdletbinding()]
param(
[switch]$UseImageCache
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$dockerRepo="microsoft/dotnet"
$dirSeparator = [IO.Path]::DirectorySeparatorChar
if ($UseImageCache) {
$optionalDockerBuildArgs = ""
}
else {
$optionalDockerBuildArgs = "--no-cache"
}
$platform = docker version -f "{{ .Server.Os }}"
if ($platform -eq "windows") {
$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 -UseImageCache:$UseImageCache
Write-Host "Tags built and tested:`n$($tags | Out-String)"