DevOps Workflow Improvements
- `VirtualBox-Wrapper.ps1` now takes 'up' or 'down' as opposed to a machine name. This allows start/stop of a virtualmachine. - `VirtualBox-Wrapper.ps1` now relies on a gitignored `localenv.json` to work. - `VirtualBox-Wrapper.ps1` can also optionally monitor the log file generated from the serial adapter in VirtualBox. - `readme.md` updated to provide instructions on how to populate the `localenv.json` file. - `tasks.json` updated to have a "Clean" task to --remove-orphans, the Build task depends on this. - `tasks.json` updated to have a "Close VirtualBox" task, this runs the `virtualbox-wrapper.ps1` in 'down' mode. The Build task depends on this. - `launch.json` updated to run the `VirtualBox-Wrapper.ps1` with the "-Command up" argument, instead of machine name. - .gitignore updated to ignore any instances of `localenv.json`.
This commit is contained in:
1 parent
07106b9aed
commit
5f3de290f3
6 files changed
+93
-28
No files matched your search
+52
-10
@@ -1,16 +1,58 @@
|
||||
<#
|
||||
You need a local git-ignored localenv.json file with the following content:
|
||||
{
|
||||
"virtualbox": {
|
||||
"MachineName": "your-machine-name or guid"
|
||||
}
|
||||
}
|
||||
#>
|
||||
|
||||
param (
|
||||
$MachineName
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet('up', 'down')]
|
||||
[String]$Command
|
||||
)
|
||||
|
||||
VBoxManage.exe startvm $MachineName
|
||||
$Config = Get-Content .\localenv.json | ConvertFrom-Json
|
||||
$MachineName = $Config.virtualbox.MachineName
|
||||
$LogLocation = $Config.virtualbox.LogLocation
|
||||
$LogOutputEnabled = $LogLocation -ne $null
|
||||
|
||||
$running=$true
|
||||
while($running) {
|
||||
Start-Sleep -Seconds 1
|
||||
$status=(VBoxManage.exe list runningvms)
|
||||
if($status) {
|
||||
$running=$status.contains($MachineName)
|
||||
} else {
|
||||
$running=$false
|
||||
if ($Command -eq 'up') {
|
||||
|
||||
if($LogOutputEnabled) {
|
||||
Clear-Content $LogLocation
|
||||
}
|
||||
|
||||
$MonitorJob = Start-Job -ArgumentList $MachineName -ScriptBlock {
|
||||
param($MachineName)
|
||||
Write-Output "Starting $MachineName"
|
||||
VBoxManage.exe startvm $MachineName
|
||||
$running=$true
|
||||
while($running) {
|
||||
$status=(VBoxManage.exe list runningvms)
|
||||
if($status) {
|
||||
$running=$status.contains($MachineName)
|
||||
} else {
|
||||
$running=$false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($LogOutputEnabled) {
|
||||
$LogJob = Start-Job -ArgumentList $LogLocation -ScriptBlock {
|
||||
param($LogLocation)
|
||||
Get-Content -Path $LogLocation -Wait
|
||||
}
|
||||
}
|
||||
|
||||
while($MonitorJob.State -eq 'Running') {
|
||||
if($LogOutputEnabled) {
|
||||
Receive-Job $LogJob
|
||||
}
|
||||
Receive-Job $MonitorJob
|
||||
}
|
||||
} elseif ($Command -eq 'down') {
|
||||
Write-Output "Stopping $MachineName"
|
||||
VBoxManage.exe controlvm $MachineName poweroff
|
||||
}
|
||||
Reference in new issue
Block a user