# 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 updated configuration if (Test-Path "config_docker.yaml") { Write-Host "โœ… Using updated Docker configuration" -ForegroundColor Green Start-Process -FilePath ".\act_runner.exe" -ArgumentList "daemon", "--config", "config_docker.yaml" -WindowStyle Hidden } elseif (Test-Path "config_heavy.yaml") { Write-Host "โœ… Using updated heavy configuration" -ForegroundColor Green Start-Process -FilePath ".\act_runner.exe" -ArgumentList "daemon", "--config", "config_heavy.yaml" -WindowStyle Hidden } else { Write-Host "โš ๏ธ Updated 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