Files
labFusion/runners/fix-cache-issues.ps1
GSRN 5cecc52572 fix: Resolve cache timeout issues in CI/CD pipelines
- Add fail-on-cache-miss: false to all cache actions in workflows
- Create improved runner configuration (config_cache_fixed.yaml) with:
  - Fixed cache host: host.docker.internal
  - Fixed cache port: 44029
  - Host network mode for better container networking
- Add cache troubleshooting scripts:
  - fix-cache-issues.sh (Linux/macOS)
  - fix-cache-issues.ps1 (Windows)
- Update all workflows: api-gateway, frontend, service-adapters, api-docs, ci

This resolves the 'connect ETIMEDOUT 172.31.0.3:44029' errors by:
1. Making cache failures non-fatal
2. Using proper Docker networking configuration
3. Providing tools to diagnose and fix cache issues
2025-09-15 16:40:52 +02:00

177 lines
6.4 KiB
PowerShell

# Cache Troubleshooting and Fix Script for LabFusion CI/CD
# This script helps diagnose and fix common cache timeout issues
Write-Host "🔧 LabFusion Cache Troubleshooting Script" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
# Function to check if running in Docker
function Test-Docker {
if (Test-Path "/.dockerenv") {
Write-Host "🐳 Running inside Docker container" -ForegroundColor Green
return $true
} else {
Write-Host "🖥️ Running on host system" -ForegroundColor Yellow
return $false
}
}
# Function to check cache service status
function Test-CacheService {
Write-Host "📊 Checking cache service status..." -ForegroundColor Cyan
# Check if act_runner process is running
$processes = Get-Process -Name "act_runner" -ErrorAction SilentlyContinue
if ($processes) {
Write-Host "✅ act_runner process found" -ForegroundColor Green
} else {
Write-Host "❌ act_runner process not found" -ForegroundColor Red
return $false
}
# Check cache directory
$cacheDir = "$env:USERPROFILE\.cache\actcache"
if (Test-Path $cacheDir) {
Write-Host "✅ Cache directory exists: $cacheDir" -ForegroundColor Green
$size = (Get-ChildItem $cacheDir -Recurse | Measure-Object -Property Length -Sum).Sum
Write-Host " Size: $([math]::Round($size / 1MB, 2)) MB" -ForegroundColor Gray
} else {
Write-Host "⚠️ Cache directory not found: $cacheDir" -ForegroundColor Yellow
Write-Host " Creating cache directory..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path $cacheDir -Force | Out-Null
}
return $true
}
# Function to test network connectivity
function Test-NetworkConnectivity {
Write-Host "🌐 Testing network connectivity..." -ForegroundColor Cyan
# Test basic connectivity
try {
$ping = Test-Connection -ComputerName "8.8.8.8" -Count 1 -Quiet
if ($ping) {
Write-Host "✅ Internet connectivity OK" -ForegroundColor Green
} else {
Write-Host "❌ Internet connectivity failed" -ForegroundColor Red
}
} catch {
Write-Host "❌ Internet connectivity test failed: $($_.Exception.Message)" -ForegroundColor Red
}
# Test Docker daemon
try {
docker info | Out-Null
Write-Host "✅ Docker daemon accessible" -ForegroundColor Green
} catch {
Write-Host "❌ Docker daemon not accessible" -ForegroundColor Red
}
}
# Function to fix common cache issues
function Fix-CacheIssues {
Write-Host "🔧 Applying cache fixes..." -ForegroundColor Cyan
# Create cache directory with proper permissions
$cacheDir = "$env:USERPROFILE\.cache\actcache"
New-Item -ItemType Directory -Path $cacheDir -Force | Out-Null
# Set proper environment variables
$env:ACTIONS_CACHE_URL = "http://host.docker.internal:44029/"
$env:ACTIONS_RUNTIME_URL = "http://host.docker.internal:44029/"
Write-Host "✅ Cache directory created and configured" -ForegroundColor Green
Write-Host "✅ Environment variables set" -ForegroundColor Green
}
# Function to restart cache service
function Restart-CacheService {
Write-Host "🔄 Restarting cache service..." -ForegroundColor Cyan
# Stop existing runners
Get-Process -Name "act_runner" -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 2
# Start with fixed configuration
if (Test-Path "config_cache_fixed.yaml") {
Write-Host "✅ Using fixed configuration" -ForegroundColor Green
Start-Process -FilePath ".\act_runner.exe" -ArgumentList "daemon", "--config", "config_cache_fixed.yaml" -WindowStyle Hidden
} else {
Write-Host "⚠️ Fixed configuration not found, using default" -ForegroundColor Yellow
Start-Process -FilePath ".\act_runner.exe" -ArgumentList "daemon" -WindowStyle Hidden
}
Start-Sleep -Seconds 5
$processes = Get-Process -Name "act_runner" -ErrorAction SilentlyContinue
if ($processes) {
Write-Host "✅ Cache service restarted successfully" -ForegroundColor Green
} else {
Write-Host "❌ Failed to restart cache service" -ForegroundColor Red
return $false
}
return $true
}
# Function to test cache functionality
function Test-CacheFunctionality {
Write-Host "🧪 Testing cache functionality..." -ForegroundColor Cyan
# Create a test cache entry
$testKey = "test-cache-$(Get-Date -Format 'yyyyMMddHHmmss')"
$testValue = "test-value-$(Get-Date -Format 'yyyyMMddHHmmss')"
Write-Host " Creating test cache entry: $testKey" -ForegroundColor Gray
$testValue | Out-File -FilePath "C:\temp\cache-test.txt" -Force
# Try to test cache service (this will fail but we can check the error)
Write-Host " Testing cache service response..." -ForegroundColor Gray
try {
$response = Invoke-WebRequest -Uri "http://host.docker.internal:44029/cache/$testKey" -TimeoutSec 5 -ErrorAction SilentlyContinue
Write-Host "✅ Cache service responding" -ForegroundColor Green
} catch {
Write-Host "❌ Cache service not responding: $($_.Exception.Message)" -ForegroundColor Yellow
Write-Host " This is expected if no cache entry exists" -ForegroundColor Gray
}
# Clean up
Remove-Item "C:\temp\cache-test.txt" -ErrorAction SilentlyContinue
}
# Main execution
function Main {
Write-Host "Starting cache troubleshooting..." -ForegroundColor Cyan
Write-Host ""
Test-Docker
Write-Host ""
Test-CacheService
Write-Host ""
Test-NetworkConnectivity
Write-Host ""
Fix-CacheIssues
Write-Host ""
Restart-CacheService
Write-Host ""
Test-CacheFunctionality
Write-Host ""
Write-Host "🎉 Cache troubleshooting complete!" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host "1. Check runner logs in the current directory" -ForegroundColor White
Write-Host "2. Test a workflow to see if cache issues are resolved" -ForegroundColor White
Write-Host "3. If issues persist, check Docker networking configuration" -ForegroundColor White
Write-Host ""
Write-Host "For more help, see: https://gitea.com/gitea/act_runner/src/branch/main/docs/configuration.md" -ForegroundColor Cyan
}
# Run main function
Main