This repository has been archived by the owner on Feb 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
build-and-test.ps1
90 lines (81 loc) · 3.12 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
[cmdletbinding()]
param(
[switch]$UseImageCache,
[string]$VersionFilter,
[string]$ArchitectureFilter,
[string]$OSFilter,
[switch]$CleanupDocker
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Invoke-CleanupDocker($ActiveOS)
{
if ($CleanupDocker) {
if ("$ActiveOS" -eq "windows") {
# Windows base images are large, preserve them to avoid the overhead of pulling each time.
docker images |
Where-Object {
-Not ($_.StartsWith("microsoft/nanoserver ")`
-Or $_.StartsWith("microsoft/windowsservercore ")`
-Or $_.StartsWith("REPOSITORY ")) } |
ForEach-Object { $_.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries)[2] } |
Select-Object -Unique |
ForEach-Object { docker rmi -f $_ }
}
else {
docker system prune -a -f
}
}
}
$(docker version) | % { Write-Host "$_" }
$activeOS = docker version -f "{{ .Server.Os }}"
Invoke-CleanupDocker $activeOS
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/*"
}
try {
$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 })
if ([bool]($images.PSobject.Properties.name -match "sharedtags")) {
$tags += [array]($images.sharedtags | 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
}
}
./test/run-test.ps1 -VersionFilter $VersionFilter -ArchitectureFilter $ArchitectureFilter -OSFilter $OSFilter
Write-Host "Tags built and tested:`n$($builtTags | Out-String)"
}
finally {
Invoke-CleanupDocker $activeOS
}