-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
41 lines (33 loc) · 1.22 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
#!/usr/bin/env pwsh
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
# Get component data and set necessary variables
$component = Get-Content -Path "component.json" | ConvertFrom-Json
$buildImage="$($component.registry)/$($component.name):$($component.version)-$($component.build)-build"
$container=$component.name
# Get buildnumber from teamcity agent
$component.build = $env:BUILD_NUMBER
Set-Content -Path "component.json" -Value $($component | ConvertTo-Json)
# Remove build files
if (Test-Path "obj") {
Remove-Item -Recurse -Force -Path "obj"
}
# Copy private keys to access git repo
if (-not (Test-Path -Path "docker/id_rsa")) {
if ($env:GIT_PRIVATE_KEY -ne $null) {
Set-Content -Path "docker/id_rsa" -Value $env:GIT_PRIVATE_KEY
} else {
Copy-Item -Path "~/.ssh/id_rsa" -Destination "docker"
}
}
# Build docker image
docker build -f docker/Dockerfile.build -t $buildImage .
# Create and copy compiled files, then destroy
docker create --name $container $buildImage
docker cp "$($container):/obj" ./obj
docker cp "$($container):/dist" ./dist
docker rm $container
if (!(Test-Path ./obj)) {
Write-Host "obj folder doesn't exist in root dir. Build failed. Watch logs above."
exit 1
}