# FleetOps installer for Windows (Docker Desktop, WSL 2 backend). # # irm https://fleetops.run/install.ps1 | iex # # With options: # & ([scriptblock]::Create((irm https://fleetops.run/install.ps1))) -Port 9100 # # Since 1.0 there is one image: it runs as Community until a license key is # installed in Admin -> License. -Edition ee is kept only for 0.x releases. # # It checks Docker, a free port and an existing install, runs FleetOps as a # container with its data in a Docker volume, and waits until it answers. # # Source: https://github.com/pravinbanjade/fleetops-web/blob/main/public/install.ps1 param( [int]$Port = 0, [ValidateSet("ce", "ee")][string]$Edition = "ce", [string]$Version = "", [switch]$Upgrade, [switch]$Uninstall, [switch]$Purge, [switch]$NoBrowser ) # Whether -Edition was given; an upgrade otherwise reads it from the installed image. $EditionSet = $PSBoundParameters.ContainsKey("Edition") # Everything runs from Install-FleetOps at the end, so a download cut short runs nothing. $ErrorActionPreference = "Stop" $Repo = "pravinbanjade/fleetops" $Site = "https://fleetops.run" $Name = if ($env:FLEETOPS_CONTAINER) { $env:FLEETOPS_CONTAINER } else { "fleetops" } $Volume = if ($env:FLEETOPS_VOLUME) { $env:FLEETOPS_VOLUME } else { "fleetops-data" } $Busybox = "busybox:1.37" # Docker Desktop and WSL run the daemon in a Linux VM, where the socket is here. $Sock = "/var/run/docker.sock" function Step($m) { Write-Host "==> $m" -ForegroundColor White } function Ok($m) { Write-Host " + $m" -ForegroundColor Green } function Warn($m) { Write-Host " ! $m" -ForegroundColor Yellow } function Hint($m) { Write-Host " $m" -ForegroundColor DarkGray } function Fail($m, [string[]]$hints = @()) { Write-Host "error: $m" -ForegroundColor Red foreach ($h in $hints) { Hint $h } throw "FleetOps install stopped: $m" } function Invoke-Docker { # Runs docker and returns its output; $LASTEXITCODE says how it went. $out = & docker @args 2>&1 return ($out | Out-String).Trim() } function Test-PortFree([int]$p) { $client = New-Object System.Net.Sockets.TcpClient try { $wait = $client.BeginConnect("127.0.0.1", $p, $null, $null).AsyncWaitHandle.WaitOne(500) return -not ($wait -and $client.Connected) } catch { return $true } finally { $client.Close() } } function Wait-Healthy([int]$p) { Step "Waiting for FleetOps to answer" for ($i = 0; $i -lt 60; $i++) { try { $r = Invoke-WebRequest -UseBasicParsing -TimeoutSec 2 "http://127.0.0.1:$p/api/v1/health" if ($r.StatusCode -eq 200) { Ok "healthy on port $p"; return $true } } catch { } Start-Sleep -Seconds 1 } return $false } function Get-ContainerPort { $p = Invoke-Docker port $Name 9000/tcp if ($LASTEXITCODE -eq 0 -and $p -match ':(\d+)') { return [int]$Matches[1] } return 0 } function Show-Done([int]$p) { Write-Host "" Write-Host "FleetOps is running." -ForegroundColor Green Write-Host "" Write-Host " Open http://localhost:$p" Write-Host "" Write-Host " Create the admin account now: setup locks 10 minutes after start." Write-Host " Before other machines use it, turn on HTTPS: $Site/install#s4" Write-Host " Upgrade later: & ([scriptblock]::Create((irm $Site/install.ps1))) -Upgrade" Write-Host " Remove: & ([scriptblock]::Create((irm $Site/install.ps1))) -Uninstall" Write-Host "" Write-Host " SSO, image scanning and CVE alerts come with a paid plan: $Site/pricing" Write-Host " If FleetOps helps, a star helps others find it: https://github.com/pravinbanjade/fleetops" Write-Host "" if (-not $NoBrowser) { try { Start-Process "http://localhost:$p" } catch { } } } function Install-FleetOps { if ($Purge -and -not $Uninstall) { Fail "-Purge only goes with -Uninstall" } Step "Checking this machine" $arch = $env:PROCESSOR_ARCHITECTURE Ok "Windows $arch" if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Fail "Docker is not installed" @( "Install Docker Desktop (https://docs.docker.com/desktop/setup/install/windows-install/),", "start it, then run this again.") } $info = Invoke-Docker info --format "{{.OSType}}" if ($LASTEXITCODE -ne 0) { Fail "Docker is installed but not running" @("Start Docker Desktop and wait until it says it is running, then run this again.") } if ($info -ne "linux") { Fail "Docker is running Windows containers" @("Switch Docker Desktop to Linux containers (tray icon menu), then run this again.") } Ok ("Docker " + (Invoke-Docker version --format "{{.Server.Version}}")) $exists = $false $null = Invoke-Docker container inspect $Name if ($LASTEXITCODE -eq 0) { $exists = $true } if ($Uninstall) { Step "Removing FleetOps" if ($exists) { $null = Invoke-Docker rm -f $Name; Ok "removed the container $Name" } else { Warn "no container named $Name" } if ($Purge) { $null = Invoke-Docker volume rm $Volume if ($LASTEXITCODE -eq 0) { Ok "deleted the volume $Volume" } } else { Hint "Your data is still in the volume $Volume. Delete it with -Uninstall -Purge." } return } if ($exists -and -not $Upgrade) { $running = Invoke-Docker container inspect -f "{{.State.Running}}" $Name if ($running -ne "true") { Step "Starting the existing $Name container"; $null = Invoke-Docker start $Name } $p = Get-ContainerPort if ($p -eq 0) { $p = 9000 } Ok "FleetOps is already installed as the container $Name" Hint "To move to the newest release: & ([scriptblock]::Create((irm $Site/install.ps1))) -Upgrade" if (-not (Wait-Healthy $p)) { Fail "it is not answering" @("See its log: docker logs $Name") } Show-Done $p return } $ver = $Version if (-not $ver) { try { $rel = Invoke-RestMethod -UseBasicParsing "https://api.github.com/repos/$Repo/releases/latest" $ver = $rel.tag_name } catch { Fail "could not reach GitHub to find the latest release" @("Check the network, or pass -Version v1.4.1.") } } if ($ver -notmatch '^v(\d+)\.(\d+)\.\d+$') { Fail "the version must look like v1.4.1, not '$ver'" } $tag = "$($Matches[1]).$($Matches[2])" $major = $Matches[1] $edition = $Edition $oldEe = $false if ($exists -and -not $EditionSet) { $current = Invoke-Docker container inspect -f "{{.Config.Image}}" $Name $oldEe = $current -like "*fleetops-ee*" $edition = if ($oldEe) { "ee" } else { "ce" } } # Releases before 1.0 had a separate Enterprise image. From 1.0 there is one # image that runs as Community until a license key is installed. $separateEe = ($edition -eq "ee") -and ($major -eq "0") $image = if ($separateEe) { "fleets/fleetops-ee:$tag" } else { "fleets/fleetops:$tag" } Step "Preparing" if ($edition -eq "ee" -and -not $separateEe) { Ok "one image since 1.0: fleets/fleetops runs Enterprise once a license key is installed" if ($oldEe) { Hint "Moving off fleets/fleetops-ee, a deprecated alias of the same image. Your license and data stay." } } Ok "image $image ($ver)" Write-Host " pulling..." $null = Invoke-Docker pull -q $image if ($LASTEXITCODE -ne 0) { Fail "could not pull $image" @("Check the network and that $ver exists.") } $null = Invoke-Docker pull -q $Busybox $gid = Invoke-Docker run --rm -v "${Sock}:/s" $Busybox stat -c %g /s if ($LASTEXITCODE -ne 0 -or $gid -notmatch '^\d+$') { Fail "could not read the group of the Docker socket" @($gid) } Ok "socket $Sock, group $gid" # Settle the port before touching the old container, so a clash leaves it running. $old = if ($exists) { Get-ContainerPort } else { 0 } $chosen = if ($Port -ne 0) { $Port } else { $old } if ($chosen -eq 0) { foreach ($p in 9000, 9100, 9200, 9300, 9400, 9500, 19000) { if (Test-PortFree $p) { $chosen = $p; break } } if ($chosen -eq 0) { Fail "ports 9000 to 9500 are all in use" @("Pick a free one with -Port.") } if ($chosen -ne 9000) { Warn "port 9000 is in use; using $chosen instead" } else { Ok "port 9000 is free" } } elseif ($chosen -ne $old -and -not (Test-PortFree $chosen)) { Fail "port $chosen is already in use" @("Pick another one with -Port.") } if ($exists) { Step "Replacing the $Name container (data in the $Volume volume stays)" $null = Invoke-Docker rm -f $Name } Step "Starting FleetOps" $out = Invoke-Docker run -d --name $Name --restart unless-stopped ` -p "${chosen}:9000" ` -v "${Volume}:/data" ` -v "${Sock}:/var/run/docker.sock" ` --group-add $gid ` $image if ($LASTEXITCODE -ne 0) { Fail "docker run failed" @($out) } Ok "container $Name" if (-not (Wait-Healthy $chosen)) { Invoke-Docker logs --tail 20 $Name | Write-Host Fail "FleetOps started but does not answer on port $chosen" @("The log above usually says why. Full log: docker logs $Name") } Show-Done $chosen } try { Install-FleetOps } catch { if ($_.Exception.Message -notlike "FleetOps install stopped*") { Write-Host "error: $($_.Exception.Message)" -ForegroundColor Red } }