forked from dotnet/dotnet-buildtools-prereqs-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
40 lines (33 loc) · 900 Bytes
/
build.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
[cmdletbinding()]
param(
[string]$DockerfilePath = "*",
[string]$ImageBuilderCustomArgs,
[string]$RunCustomArgs,
[switch]$CleanupDocker
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Invoke-CleanupDocker()
{
if ($CleanupDocker) {
docker system prune -a -f
}
}
Invoke-CleanupDocker
try {
& docker build -t imagebuilder --pull -f ./Dockerfile.linux.imagebuilder .
if ($LastExitCode -ne 0) {
throw "Failed building ImageBuilder."
}
$expression = "docker run --rm " +
"-v /var/run/docker.sock:/var/run/docker.sock " +
"$RunCustomArgs imagebuilder " +
"build --manifest manifest.json --path '$DockerfilePath' $ImageBuilderCustomArgs"
Invoke-Expression $expression
if ($LastExitCode -ne 0) {
throw "Failed executing ImageBuilder."
}
}
finally {
Invoke-CleanupDocker
}