diff --git a/docs/CACHE_TROUBLESHOOTING.md b/docs/CACHE_TROUBLESHOOTING.md index c5d3143..eaf2b37 100644 --- a/docs/CACHE_TROUBLESHOOTING.md +++ b/docs/CACHE_TROUBLESHOOTING.md @@ -32,7 +32,7 @@ This ensures that cache failures don't cause the entire pipeline to fail. ### 2. Runner Configuration Fixes Updated all existing runner configuration files with: -- **Fixed Host**: `host.docker.internal` (allows containers to access host) +- **Auto-detect Host**: Empty host field (allows act_runner to auto-detect the correct IP) - **Fixed Port**: `44029` (instead of random port 0) - **Host Network**: Uses host networking for better connectivity @@ -91,7 +91,7 @@ Update your runner configuration with these key changes: ```yaml cache: enabled: true - host: "host.docker.internal" # Fixed host + host: "" # Auto-detect host IP port: 44029 # Fixed port container: diff --git a/runners/config_docker.yaml b/runners/config_docker.yaml index 1e1b4ac..861ffe7 100644 --- a/runners/config_docker.yaml +++ b/runners/config_docker.yaml @@ -54,9 +54,9 @@ cache: # If it's empty, the cache data will be stored in $HOME/.cache/actcache. dir: "" # The host of the cache server. - # Use host.docker.internal to allow containers to access the host - # This fixes the common networking issue where containers can't reach the cache server - host: "host.docker.internal" + # Leave empty to auto-detect the host IP address + # This is more compatible across different Docker setups + host: "" # Use a fixed port instead of random to avoid connection issues port: 44029 # The external cache server URL. Valid only when enable is true. diff --git a/runners/config_heavy.yaml b/runners/config_heavy.yaml index 1e1b4ac..861ffe7 100644 --- a/runners/config_heavy.yaml +++ b/runners/config_heavy.yaml @@ -54,9 +54,9 @@ cache: # If it's empty, the cache data will be stored in $HOME/.cache/actcache. dir: "" # The host of the cache server. - # Use host.docker.internal to allow containers to access the host - # This fixes the common networking issue where containers can't reach the cache server - host: "host.docker.internal" + # Leave empty to auto-detect the host IP address + # This is more compatible across different Docker setups + host: "" # Use a fixed port instead of random to avoid connection issues port: 44029 # The external cache server URL. Valid only when enable is true. diff --git a/runners/config_light.yaml b/runners/config_light.yaml index 1e1b4ac..861ffe7 100644 --- a/runners/config_light.yaml +++ b/runners/config_light.yaml @@ -54,9 +54,9 @@ cache: # If it's empty, the cache data will be stored in $HOME/.cache/actcache. dir: "" # The host of the cache server. - # Use host.docker.internal to allow containers to access the host - # This fixes the common networking issue where containers can't reach the cache server - host: "host.docker.internal" + # Leave empty to auto-detect the host IP address + # This is more compatible across different Docker setups + host: "" # Use a fixed port instead of random to avoid connection issues port: 44029 # The external cache server URL. Valid only when enable is true. diff --git a/runners/config_security.yaml b/runners/config_security.yaml index 1e1b4ac..861ffe7 100644 --- a/runners/config_security.yaml +++ b/runners/config_security.yaml @@ -54,9 +54,9 @@ cache: # If it's empty, the cache data will be stored in $HOME/.cache/actcache. dir: "" # The host of the cache server. - # Use host.docker.internal to allow containers to access the host - # This fixes the common networking issue where containers can't reach the cache server - host: "host.docker.internal" + # Leave empty to auto-detect the host IP address + # This is more compatible across different Docker setups + host: "" # Use a fixed port instead of random to avoid connection issues port: 44029 # The external cache server URL. Valid only when enable is true. diff --git a/runners/fix-cache-issues.ps1 b/runners/fix-cache-issues.ps1 index ee9dd7e..7c9a1cc 100644 --- a/runners/fix-cache-issues.ps1 +++ b/runners/fix-cache-issues.ps1 @@ -68,6 +68,35 @@ function Test-NetworkConnectivity { } } +# Function to detect the correct host IP +function Get-HostIP { + Write-Host "🔍 Detecting host IP address..." -ForegroundColor Cyan + + try { + # Try to get the IP address of the default gateway interface + $networkAdapters = Get-NetAdapter | Where-Object { $_.Status -eq "Up" -and $_.Name -notlike "*Loopback*" } + if ($networkAdapters) { + $ipConfig = Get-NetIPAddress -AddressFamily IPv4 | Where-Object { + $_.InterfaceAlias -in $networkAdapters.Name -and $_.IPAddress -ne "127.0.0.1" + } | Select-Object -First 1 + + if ($ipConfig) { + $hostIP = $ipConfig.IPAddress + Write-Host "✅ Detected host IP: $hostIP" -ForegroundColor Green + return $hostIP + } + } + + # Fallback to localhost + Write-Host "⚠️ Could not detect host IP, using localhost" -ForegroundColor Yellow + return "127.0.0.1" + } catch { + Write-Host "⚠️ Error detecting host IP: $($_.Exception.Message)" -ForegroundColor Yellow + Write-Host " Using localhost as fallback" -ForegroundColor Gray + return "127.0.0.1" + } +} + # Function to fix common cache issues function Fix-CacheIssues { Write-Host "🔧 Applying cache fixes..." -ForegroundColor Cyan @@ -76,12 +105,15 @@ function Fix-CacheIssues { $cacheDir = "$env:USERPROFILE\.cache\actcache" New-Item -ItemType Directory -Path $cacheDir -Force | Out-Null + # Detect host IP + $hostIP = Get-HostIP + # Set proper environment variables - $env:ACTIONS_CACHE_URL = "http://host.docker.internal:44029/" - $env:ACTIONS_RUNTIME_URL = "http://host.docker.internal:44029/" + $env:ACTIONS_CACHE_URL = "http://${hostIP}:44029/" + $env:ACTIONS_RUNTIME_URL = "http://${hostIP}:44029/" Write-Host "✅ Cache directory created and configured" -ForegroundColor Green - Write-Host "✅ Environment variables set" -ForegroundColor Green + Write-Host "✅ Environment variables set with host IP: $hostIP" -ForegroundColor Green } # Function to restart cache service diff --git a/runners/fix-cache-issues.sh b/runners/fix-cache-issues.sh index a3ed1ca..62589d2 100644 --- a/runners/fix-cache-issues.sh +++ b/runners/fix-cache-issues.sh @@ -62,6 +62,35 @@ test_network() { fi } +# Function to detect the correct host IP +detect_host_ip() { + echo "🔍 Detecting host IP address..." + + # Try different methods to get the host IP + if command -v ip > /dev/null 2>&1; then + # Linux with ip command + HOST_IP=$(ip route get 1.1.1.1 | awk '{print $7; exit}' 2>/dev/null) + elif command -v hostname > /dev/null 2>&1; then + # Try hostname -I (Linux) + HOST_IP=$(hostname -I | awk '{print $1}' 2>/dev/null) + elif command -v ifconfig > /dev/null 2>&1; then + # Try ifconfig (macOS/BSD) + HOST_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1) + else + # Fallback to localhost + HOST_IP="127.0.0.1" + fi + + if [ -z "$HOST_IP" ] || [ "$HOST_IP" = "127.0.0.1" ]; then + echo "⚠️ Could not detect host IP, using localhost" + HOST_IP="127.0.0.1" + else + echo "✅ Detected host IP: $HOST_IP" + fi + + echo "$HOST_IP" +} + # Function to fix common cache issues fix_cache_issues() { echo "🔧 Applying cache fixes..." @@ -71,12 +100,15 @@ fix_cache_issues() { mkdir -p "$CACHE_DIR" chmod 755 "$CACHE_DIR" + # Detect host IP + HOST_IP=$(detect_host_ip) + # Set proper environment variables - export ACTIONS_CACHE_URL="http://host.docker.internal:44029/" - export ACTIONS_RUNTIME_URL="http://host.docker.internal:44029/" + export ACTIONS_CACHE_URL="http://${HOST_IP}:44029/" + export ACTIONS_RUNTIME_URL="http://${HOST_IP}:44029/" echo "✅ Cache directory created and configured" - echo "✅ Environment variables set" + echo "✅ Environment variables set with host IP: $HOST_IP" } # Function to restart cache service