forked from microsoft/opengcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
66 lines (52 loc) · 2.23 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
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
<#
.NOTES
Summary: Simple wrapper to build a local initrd.img and rootfs.vhd from sources and optionally install it.
License: See https://github.com/Microsoft/opengcs/blob/master/LICENSE
.Parameter Install
Installs the built initrd.img and rootfs.vhd
#>
param(
[Parameter(Mandatory=$false)][switch]$Install
)
$ErrorActionPreference = 'Stop'
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}
Try {
Write-Host -ForegroundColor Yellow "INFO: Starting at $(date)"
$commit = git rev-parse --short HEAD
$branch = git rev-parse --abbrev-ref HEAD
$d=New-TemporaryDirectory
echo "Commit:`t$commit`nRepo:`tmicrosoft/opengcs`nBranch:`t$branch`nBuilt:`t$(date)" > $d\opengcsversion.txt
&docker build --platform=linux -t opengcs .
if ( $LastExitCode -ne 0 ) {
Throw "failed to build opengcs image"
}
# Add SYS_ADMIN and loop device access (device group 7) to allow loopback
# mounting for creating rootfs.vhd. --privileged would also be sufficient
# but is not currently supported in LCOW.
Write-Host -ForegroundColor Yellow "INFO: Compiling targets"
docker run --cap-add SYS_ADMIN --device-cgroup-rule="c 7:* rmw" --rm -v $d`:/build/out opengcs sh -c 'make -f $SRC/Makefile all out/rootfs.vhd'
if ( $LastExitCode -ne 0 ) {
Throw "failed to build"
}
if ($Install) {
if (Test-Path "C:\Program Files\Linux Containers\initrd.img" -PathType Leaf) {
copy "C:\Program Files\Linux Containers\initrd.img" "C:\Program Files\Linux Containers\initrd.old"
Write-Host -ForegroundColor Yellow "INFO: Backed up previous initrd.img to C:\Program Files\Linux Containers\initrd.old"
}
copy "$d`\initrd.img" "C:\Program Files\Linux Containers\initrd.img"
Write-Host -ForegroundColor Yellow "INFO: Restart the docker daemon to pick up the new image"
}
Write-Host -ForegroundColor Yellow "`nINFO: Targets are in $d`n"
Get-Content "$d\opengcsversion.txt" | Write-Host
Write-Host
}
Catch [Exception] {
Throw $_
}
Finally {
Write-Host -ForegroundColor Yellow "INFO: Exiting at $(date)"
}