Skip to content

Commit b337c7f

Browse files
authored
Windows: Ensure Docker engine is running (#259)
When running a swift_package_tests.yaml workflow, workflows running in a docker container on windows would often fails as the docker engine was not currently ready to accept requests. Add a step that ensure the docker engine is started and ready, by calling `docker info` command before performing any other docker steps to ensure the engine is ready.
1 parent f84da04 commit b337c7f

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

.github/workflows/swift_package_test.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,40 @@ jobs:
750750
foreach ($line in $lines) {
751751
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
752752
}
753+
- name: Ensure Docker engine is ready
754+
if: ${{ inputs.enable_windows_docker }}
755+
run: |
756+
# Start Docker service
757+
Write-Host "Starting Docker service..."
758+
Start-Service docker
759+
760+
# Wait for Docker to be ready with exponential backoff
761+
$maxRetries = 10
762+
$retryCount = 0
763+
$baseDelay = 1
764+
$maxDelay = 30
765+
while ($retryCount -lt $maxRetries) {
766+
try {
767+
docker info | Out-Null
768+
if ($LASTEXITCODE) {
769+
throw "docker engine is not ready"
770+
}
771+
Write-Host "Docker engine is ready"
772+
break
773+
} catch {
774+
$retryCount++
775+
if ($retryCount -lt $maxRetries) {
776+
# Exponential backoff: 2^retryCount * baseDelay, capped at maxDelay
777+
$delay = [Math]::Min([Math]::Pow(2, $retryCount) * $baseDelay, $maxDelay)
778+
Write-Host "Waiting for Docker engine to be ready... (attempt $retryCount/$maxRetries, waiting $delay seconds)"
779+
Start-Sleep -Seconds $delay
780+
}
781+
}
782+
}
783+
if ($retryCount -eq $maxRetries) {
784+
Write-Error "Docker engine failed to start after $maxRetries attempts"
785+
exit 1
786+
}
753787
- name: Pull Docker image
754788
id: pull_docker_image
755789
if: ${{ inputs.enable_windows_docker }}

0 commit comments

Comments
 (0)