forked from microsoft/opengcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
57 lines (44 loc) · 1.71 KB
/
Copy pathbuild.ps1
File metadata and controls
57 lines (44 loc) · 1.71 KB
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
<#
.NOTES
Summary: Simple wrapper to build a local initrd.img and rootfs.tar.gz from sources and optionally install it.
License: See https://github.com/Microsoft/opengcs/blob/master/LICENSE
.Parameter Install
Installs the built initrd.img
#>
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)`n"
&docker build --platform=linux -t opengcs .
if ( $LastExitCode -ne 0 ) {
Throw "failed to build opengcs image"
}
$d=New-TemporaryDirectory
Write-Host -ForegroundColor Yellow "INFO: Copying targets to $d"
docker run --rm -v $d`:/build/out opengcs
if ( $LastExitCode -ne 0 ) {
Throw "failed to build"
}
Write-Host -ForegroundColor Yellow "INFO: Use rootfs2vhd in Microsoft/hcsshim to make a rootfs VHD if needed"
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"
}
}
Catch [Exception] {
Throw $_
}
Finally {
Write-Host -ForegroundColor Yellow "INFO: Exiting at $(date)"
}