|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to test ghcr.io connectivity and image access |
| 4 | +# Run this on your server to diagnose connection issues |
| 5 | + |
| 6 | +echo "=== Testing ghcr.io Connectivity ===" |
| 7 | +echo "" |
| 8 | + |
| 9 | +# Test 1: Basic connectivity to ghcr.io |
| 10 | +echo "1. Testing basic connectivity to ghcr.io..." |
| 11 | +if curl -I --max-time 10 https://ghcr.io 2>&1 | grep -q "HTTP"; then |
| 12 | + echo " ✓ ghcr.io is reachable" |
| 13 | +else |
| 14 | + echo " ✗ Cannot reach ghcr.io" |
| 15 | + echo " Check your internet connection and firewall settings" |
| 16 | +fi |
| 17 | +echo "" |
| 18 | + |
| 19 | +# Test 2: Test Docker registry API |
| 20 | +echo "2. Testing Docker registry API..." |
| 21 | +if curl -I --max-time 10 https://ghcr.io/v2/ 2>&1 | grep -q "HTTP"; then |
| 22 | + echo " ✓ Docker registry API is accessible" |
| 23 | + curl -I --max-time 10 https://ghcr.io/v2/ 2>&1 | head -1 |
| 24 | +else |
| 25 | + echo " ✗ Cannot access Docker registry API" |
| 26 | +fi |
| 27 | +echo "" |
| 28 | + |
| 29 | +# Test 3: Check if you're logged in to ghcr.io |
| 30 | +echo "3. Checking Docker login status for ghcr.io..." |
| 31 | +if docker login ghcr.io --username test --password-stdin <<< "test" 2>&1 | grep -q "unauthorized\|authentication required"; then |
| 32 | + echo " ⚠ Not logged in (this is expected if you haven't logged in)" |
| 33 | +else |
| 34 | + echo " Checking current login status..." |
| 35 | + cat ~/.docker/config.json 2>/dev/null | grep -q "ghcr.io" && echo " ✓ Found ghcr.io in Docker config" || echo " ✗ Not logged in to ghcr.io" |
| 36 | +fi |
| 37 | +echo "" |
| 38 | + |
| 39 | +# Test 4: Test specific image access (without pulling) |
| 40 | +echo "4. Testing access to specific images..." |
| 41 | +echo " Testing MongoDB image..." |
| 42 | +if curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library_mongodb/manifests/4.4.28" 2>&1 | grep -q "HTTP.*200\|HTTP.*401\|HTTP.*404"; then |
| 43 | + STATUS=$(curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library_mongodb/manifests/4.4.28" 2>&1 | head -1) |
| 44 | + echo " MongoDB image: $STATUS" |
| 45 | + if echo "$STATUS" | grep -q "401\|403"; then |
| 46 | + echo " ⚠ Image exists but requires authentication" |
| 47 | + elif echo "$STATUS" | grep -q "404"; then |
| 48 | + echo " ✗ Image not found (404)" |
| 49 | + elif echo "$STATUS" | grep -q "200"; then |
| 50 | + echo " ✓ Image is accessible" |
| 51 | + fi |
| 52 | +else |
| 53 | + echo " ✗ Cannot check image (timeout or connection error)" |
| 54 | +fi |
| 55 | +echo "" |
| 56 | + |
| 57 | +echo " Testing Nginx image..." |
| 58 | +if curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library_nginx/manifests/latest" 2>&1 | grep -q "HTTP.*200\|HTTP.*401\|HTTP.*404"; then |
| 59 | + STATUS=$(curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library_nginx/manifests/latest" 2>&1 | head -1) |
| 60 | + echo " Nginx image: $STATUS" |
| 61 | + if echo "$STATUS" | grep -q "401\|403"; then |
| 62 | + echo " ⚠ Image exists but requires authentication" |
| 63 | + elif echo "$STATUS" | grep -q "404"; then |
| 64 | + echo " ✗ Image not found (404)" |
| 65 | + elif echo "$STATUS" | grep -q "200"; then |
| 66 | + echo " ✓ Image is accessible" |
| 67 | + fi |
| 68 | +else |
| 69 | + echo " ✗ Cannot check image (timeout or connection error)" |
| 70 | +fi |
| 71 | +echo "" |
| 72 | + |
| 73 | +echo " Testing App image..." |
| 74 | +if curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library/manifests/latest" 2>&1 | grep -q "HTTP.*200\|HTTP.*401\|HTTP.*404"; then |
| 75 | + STATUS=$(curl -I --max-time 10 "https://ghcr.io/v2/navidshad/chord_library/manifests/latest" 2>&1 | head -1) |
| 76 | + echo " App image: $STATUS" |
| 77 | + if echo "$STATUS" | grep -q "401\|403"; then |
| 78 | + echo " ⚠ Image exists but requires authentication" |
| 79 | + elif echo "$STATUS" | grep -q "404"; then |
| 80 | + echo " ✗ Image not found (404)" |
| 81 | + elif echo "$STATUS" | grep -q "200"; then |
| 82 | + echo " ✓ Image is accessible" |
| 83 | + fi |
| 84 | +else |
| 85 | + echo " ✗ Cannot check image (timeout or connection error)" |
| 86 | +fi |
| 87 | +echo "" |
| 88 | + |
| 89 | +# Test 5: DNS resolution |
| 90 | +echo "5. Testing DNS resolution..." |
| 91 | +if nslookup ghcr.io > /dev/null 2>&1; then |
| 92 | + echo " ✓ DNS resolution works" |
| 93 | + nslookup ghcr.io | grep -A 1 "Name:" |
| 94 | +else |
| 95 | + echo " ✗ DNS resolution failed" |
| 96 | +fi |
| 97 | +echo "" |
| 98 | + |
| 99 | +# Test 6: Docker pull test (dry run - will fail but shows if connection works) |
| 100 | +echo "6. Testing Docker pull (this will fail but shows connection)..." |
| 101 | +echo " Attempting to pull (will timeout after 10 seconds)..." |
| 102 | +timeout 10 docker pull ghcr.io/navidshad/chord_library_mongodb:4.4.28 2>&1 | head -5 |
| 103 | +echo "" |
| 104 | + |
| 105 | +echo "=== Summary ===" |
| 106 | +echo "If you see connection timeouts:" |
| 107 | +echo " 1. Check your server's internet connection" |
| 108 | +echo " 2. Check firewall/proxy settings" |
| 109 | +echo " 3. Check if ghcr.io is blocked in your region" |
| 110 | +echo "" |
| 111 | +echo "If images require authentication:" |
| 112 | +echo " 1. You need to login: docker login ghcr.io -u YOUR_GITHUB_USERNAME" |
| 113 | +echo " 2. Use a GitHub Personal Access Token (PAT) with 'read:packages' permission" |
| 114 | +echo " 3. Or make the packages public in GitHub repository settings" |
| 115 | + |
0 commit comments