-
Notifications
You must be signed in to change notification settings - Fork 40
/
build.ps1
41 lines (32 loc) · 1.38 KB
/
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
41
# Exit on error and undefined variables
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
function Main {
Write-Host "Gocesiumtiler build script" -ForegroundColor Green
Write-Host -NoNewline " => Removing old build artifacts... " -ForegroundColor Blue
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue ".\build"
Write-Host "done" -ForegroundColor Blue
Write-Host " => Starting dockerized build..." -ForegroundColor Blue
# Generate a unique build ID
$build_id = Get-Date -Format "yyyyMMddHHmmss-fffffff"
Write-Host " => Build id: $build_id" -ForegroundColor Blue
Write-Host " => Building..." -ForegroundColor Blue
docker build -t gocesiumtiler:build --target=final --output .\build --build-arg BUILD_ID=$build_id .
# ensure that the command exited cleanly
CheckLastExitCode
# Get the full path to the build directory
$build_dir = (Get-Item -Path ".\build").FullName
Write-Host "=> Build complete, artifacts saved in: $build_dir" -ForegroundColor Green
}
function CheckLastExitCode {
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null)
if ($SuccessCodes -notcontains $LastExitCode) {
if ($CleanupScript) {
"Executing cleanup script: $CleanupScript"
&$CleanupScript
}
$msg = "Build failed, check docker logs"
throw $msg
}
}
Main