-
Notifications
You must be signed in to change notification settings - Fork 250
/
psakeBuild.ps1
50 lines (41 loc) · 2.17 KB
/
psakeBuild.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
$psake.use_exit_on_error = $true
properties {
$baseDir = $psake.build_script_dir
}
Task default -depends Build-Packer, prepare-hyperv, convert-tovhd, package-hyperv
task build-packer {
exec { packer build -force (Join-Path $baseDir vbox-2012r2.json) }
}
task prepare-hyperv {
$vmPath = "$baseDir\hyper-v-output\Virtual Machines\vm.xml"
[xml]$vmXml = Get-Content $vmPath
$vmXml.configuration.properties.name.'#text' = '2012R2Min'
$ticks = [int64](get-date).ToUniversalTime().Subtract([datetime]"12/31/1600 23:59:59").Ticks
$creation_time = [convert]::ToBase64String([bitconverter]::GetBytes($ticks))
$vmXml.configuration.properties.creation_time.'#text' = $creation_time
$vmXml.Save($vmPath)
$vboxDisk = Resolve-Path("$baseDir\output-virtualbox-iso\*.vmdk")
$hyperVDir = "$baseDir\hyper-v-output\Virtual Hard Disks"
if(!(Test-Path $hyperVDir)) { mkdir $hyperVDir }
$hyperVDisk = Join-Path $hyperVDir 'disk.vhd'
if(Test-Path $hyperVDisk) { Remove-Item $hyperVDisk -Force }
$hyperVVagrantFile = "$baseDir\hyper-v-output\Vagrantfile"
if(Test-Path $hyperVVagrantFile) { Remove-Item $hyperVVagrantFile -Force }
Copy-Item (Join-Path $baseDir vagrantfile-windows.template) $hyperVVagrantFile
}
task convert-tovhd {
$vboxDisk = Resolve-Path "$baseDir\output-virtualbox-iso\*.vmdk"
$hyperVDir = "$baseDir\hyper-v-output\Virtual Hard Disks"
$hyperVDisk = Join-Path $hyperVDir 'disk.vhd'
."$env:programfiles\oracle\VirtualBox\VBoxManage.exe" clonehd $vboxDisk $hyperVDisk --format vhd
}
task package-hyperv {
."$env:chocolateyInstall\tools\7za.exe" a -ttar (join-path $baseDir "package-hyper-v.tar") (Join-Path $baseDir "hyper-v-output\*")
."$env:chocolateyInstall\tools\7za.exe" a -tgzip (join-path $baseDir "package-hyper-v-$version.box") (join-path $baseDir "package-hyper-v.tar")
}
task Upload-Box {
$path = join-path $baseDir "package-hyper-v-$version.box"
$storageAccountKey = Get-AzureStorageKey wrock | %{ $_.Primary }
$context = New-AzureStorageContext -StorageAccountName wrock -StorageAccountKey $storageAccountKey
Set-AzureStorageBlobContent -Blob (Split-Path -Path $path -Leaf) -Container vhds -File $path -Context $context -Force
}