init windowshost

This commit is contained in:
Thomas Dhome-Casanova
2025-01-29 23:36:38 -08:00
parent b2d6bc5c3e
commit e8882d8484
20 changed files with 3270 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
function Create-VM {
if (-not (docker images windows-local -q)) {
Write-Host "Image not found locally. Building..."
docker build -t windows-local ..
} else {
Write-Host "Image found locally. Skipping build."
}
docker compose -f ../compose.yml up -d
while ($true) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:5000/probe" -Method GET -UseBasicParsing
if ($response.StatusCode -eq 200) {
break
}
} catch {
Write-Host "Waiting for a response from the computer control server. When first building the VM storage folder this can take a while..."
Start-Sleep -Seconds 5
}
}
Write-Host "VM + server is up and running!"
}
function Start-LocalVM {
Write-Host "Starting VM..."
docker compose -f ../compose.yml start
while ($true) {
try {
$response = Invoke-WebRequest -Uri "http://localhost:5000/probe" -Method GET -UseBasicParsing
if ($response.StatusCode -eq 200) {
break
}
} catch {
Write-Host "Waiting for a response from the computer control server"
Start-Sleep -Seconds 5
}
}
Write-Host "VM started"
}
function Stop-LocalVM {
Write-Host "Stopping VM..."
docker compose -f ../compose.yml stop
Write-Host "VM stopped"
}
function Remove-VM {
Write-Host "Removing VM and associated containers..."
docker compose -f ../compose.yml down
Write-Host "VM removed"
}
if (-not $args[0]) {
Write-Host "Usage: $($MyInvocation.MyCommand.Name) [create|start|stop|delete]"
exit 1
}
switch ($args[0]) {
"create" { Create-VM }
"start" { Start-LocalVM }
"stop" { Stop-LocalVM }
"delete" { Remove-VM }
default {
Write-Host "Invalid option: $($args[0])"
Write-Host "Usage: $($MyInvocation.MyCommand.Name) [create|start|stop|delete]"
exit 1
}
}

View File

@@ -0,0 +1,77 @@
#!/bin/bash
create_vm() {
if ! docker images windows-local -q | grep -q .; then
echo "Image not found locally. Building..."
docker build -t windows-local ..
else
echo "Image found locally. Skipping build."
fi
docker compose -f ../compose.yml up -d
# Wait for the VM to start up
while true; do
response=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe)
if [ $response -eq 200 ]; then
break
fi
echo "Waiting for a response from the computer control server. When first building the VM storage folder this can take a while..."
sleep 5
done
echo "VM + server is up and running!"
}
start_vm() {
echo "Starting VM..."
docker compose -f ../compose.yml start
while true; do
response=$(curl --write-out '%{http_code}' --silent --output /dev/null localhost:5000/probe)
if [ $response -eq 200 ]; then
break
fi
echo "Waiting for a response from the computer control server"
sleep 5
done
echo "VM started"
}
stop_vm() {
echo "Stopping VM..."
docker compose -f ../compose.yml stop
echo "VM stopped"
}
delete_vm() {
echo "Removing VM and associated containers..."
docker compose -f ../compose.yml down
echo "VM removed"
}
# Check if control parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 [create|start|stop|delete]"
exit 1
fi
# Execute the appropriate function based on the control parameter
case "$1" in
"create")
create_vm
;;
"start")
start_vm
;;
"stop")
stop_vm
;;
"delete")
delete_vm
;;
*)
echo "Invalid option: $1"
echo "Usage: $0 [create|start|stop|delete]"
exit 1
;;
esac