-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch_cluster.ps1
50 lines (42 loc) · 1.76 KB
/
launch_cluster.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
# Arguments
param (
[int]$NUM_CONTAINERS = 4 # Default if no argument is provided
)
Write-Host "Building docker image..."
$buildResult = docker build -t maplejuice-image .
$buildResultOutput = $buildResult | Format-List | Out-String
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build docker image. Exiting script. Here is the output from 'docker build' command"
Write-Error $buildResultOutput
exit 1
}
# Check if the network exists
$networkExists = docker network ls --format '{{.Name}}' | Where-Object { $_ -eq 'maplejuice-net' }
# Create the network if it doesn't exist
if (-not $networkExists) {
Write-Host "`nCreating maplejuice-net network..."
docker network create maplejuice-net
} else {
Write-Host "`nmaplejuice-net network already exists."
}
Write-Host "`nCreating Docker volumes...`n"
for ($i = 1; $i -le $NUM_CONTAINERS; $i++) {
# Format the container number with leading zero
$CONTAINER_NUM = "{0:D2}" -f $i
# Create the Docker volume
$VOLUME_NAME = "mj-vm-$CONTAINER_NUM-output"
Write-Host "Creating volume $VOLUME_NAME..."
docker volume create $VOLUME_NAME
}
Write-Host "`nLaunching $NUM_CONTAINERS Docker containers...`n"
for ($i = 1; $i -le $NUM_CONTAINERS; $i++) {
# Format the container number with leading zero
$CONTAINER_NUM = "{0:D2}" -f $i
# Construct the command to run
$VOLUME_NAME = "mj-vm-$CONTAINER_NUM-output"
$CMD = "docker run -it --rm --name mj-vm-$CONTAINER_NUM --hostname VM$CONTAINER_NUM --network maplejuice-net -v ${VOLUME_NAME}:/src/app_data maplejuice-image"
# Start a new PowerShell window and run the command
Write-Host "Launching container mj-vm-$CONTAINER_NUM..."
Start-Process powershell -ArgumentList "-NoExit", "-Command", $CMD
Start-Sleep -Milliseconds 100
}