Modules/businessdev.ALbuild.RuntimePackages/Private/Get-BcRuntimeFreeDiskGb.ps1

function Get-BcRuntimeFreeDiskGb {
    <#
    .SYNOPSIS
        Free space in GB on the drive Docker stores containers on, or 0 when it cannot be determined.
 
    .DESCRIPTION
        Sizes the worker pool against disk, not just memory. Each BC container copies the service tier
        into its writable layer and restores a database there, so the drive - not RAM - is often what
        actually limits how many containers a host can carry. Running it to zero mid-start surfaces
        minutes later as a cryptic "failed to start service", which is a bad way to learn about capacity.
 
        The Containers module has an equivalent private helper, but private functions are not visible
        across modules, and promoting it would widen the public surface for one pool-sizing call. This
        goes through the public Invoke-BcDocker instead.
 
        Returning 0 rather than throwing keeps an unreadable drive from failing a build: the caller
        treats 0 as "not measured" and sizes on memory alone.
 
    .PARAMETER DockerExecutable
        Docker executable.
 
    .OUTPUTS
        System.Double
    #>

    [CmdletBinding()]
    [OutputType([double])]
    param(
        [string] $DockerExecutable = 'docker'
    )

    try {
        $info = Invoke-BcDocker -DockerExecutable $DockerExecutable -Quiet -PassThru -Arguments @('info', '--format', '{{.DockerRootDir}}')
        $probe = if ($info.Success -and -not [string]::IsNullOrWhiteSpace("$($info.StdOut)")) { "$($info.StdOut)".Trim() }
        else { [System.Environment]::GetEnvironmentVariable('SystemDrive') + '\' }

        $driveRoot = [System.IO.Path]::GetPathRoot($probe)
        if ([string]::IsNullOrWhiteSpace($driveRoot)) { return [double]0 }
        $drive = New-Object System.IO.DriveInfo($driveRoot)
        if (-not $drive.IsReady) { return [double]0 }
        return [double]($drive.AvailableFreeSpace / 1GB)
    }
    catch {
        Write-ALbuildLog -Level Verbose "Could not read free disk space: $($_.Exception.Message)"
        return [double]0
    }
}