forked from dotnet/dotnet-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-and-test.ps1
executable file
·63 lines (53 loc) · 2.05 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
#!/usr/bin/env pwsh
[cmdletbinding()]
param(
[switch]$UseImageCache,
[string]$VersionFilter,
[string]$ArchitectureFilter,
[string]$OSFilter
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$(docker version) | % { Write-Host "$_" }
$activeOS = docker version -f "{{ .Server.Os }}"
if ($UseImageCache) {
$optionalDockerBuildArgs = ""
}
else {
$optionalDockerBuildArgs = "--no-cache"
}
$manifest = Get-Content "manifest.json" | ConvertFrom-Json
$manifestRepo = $manifest.Repos[0]
$builtTags = @()
$buildFilter = "*"
if (-not [string]::IsNullOrEmpty($versionFilter))
{
$buildFilter = "$versionFilter/$buildFilter"
}
if (-not [string]::IsNullOrEmpty($OsFilter))
{
$buildFilter = "$buildFilter/$OsFilter/*"
}
$manifestRepo.Images |
ForEach-Object {
$images = $_
$_.Platforms |
Where-Object { $_.os -eq "$activeOS" } |
Where-Object { [string]::IsNullOrEmpty($buildFilter) -or $_.dockerfile -like "$buildFilter" } |
Where-Object { ( [string]::IsNullOrEmpty($ArchitectureFilter) -and -not [bool]($_.PSobject.Properties.name -match "architecture"))`
-or ( [bool]($_.PSobject.Properties.name -match "architecture") -and $_.architecture -eq "$ArchitectureFilter" ) } |
ForEach-Object {
$dockerfilePath = $_.dockerfile
$tags = [array]($_.Tags | ForEach-Object { $_.PSobject.Properties })
$qualifiedTags = $tags | ForEach-Object { $manifestRepo.Name + ':' + $_.Name}
$formattedTags = $qualifiedTags -join ', '
Write-Host "--- Building $formattedTags from $dockerfilePath ---"
Invoke-Expression "docker build $optionalDockerBuildArgs -t $($qualifiedTags -join ' -t ') $dockerfilePath"
if ($LastExitCode -ne 0) {
throw "Failed building $formattedTags"
}
$builtTags += $formattedTags
}
}
./tests/run-tests.ps1 -VersionFilter $VersionFilter -ArchitectureFilter $ArchitectureFilter -OSFilter $OSFilter -IsLocalRun
Write-Host "Tags built and tested:`n$($builtTags | Out-String)"