Skip to content

Commit 4967f6c

Browse files
committed
Add script to test ghcr.io connectivity and image access, enhancing troubleshooting for Docker users
1 parent be745ef commit 4967f6c

2 files changed

Lines changed: 124 additions & 7 deletions

File tree

.github/workflows/deploy-to-ssh-server.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ name: Deploy To SSH Server
66

77
on:
88
push:
9-
branches: [ "main" ]
9+
branches: ["main"]
1010
pull_request:
11-
branches: [ "main" ]
11+
branches: ["main"]
1212
# Allows you to run this workflow manually from the Actions tab
1313
workflow_dispatch:
1414

@@ -26,7 +26,7 @@ jobs:
2626
- uses: actions/checkout@v3
2727
with:
2828
fetch-depth: 2
29-
29+
3030
- uses: dorny/paths-filter@v2
3131
id: filter
3232
with:
@@ -62,7 +62,7 @@ jobs:
6262
- uses: actions/setup-node@v3
6363
with:
6464
node-version: 14
65-
65+
6666
- name: Build nuxt app
6767
run: |
6868
cd website
@@ -87,7 +87,6 @@ jobs:
8787
run: |
8888
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_SERVER }}
8989
90-
9190
deploy:
9291
runs-on: ubuntu-latest
9392
needs: [build, build-nginx, check-changes]
@@ -104,20 +103,23 @@ jobs:
104103
source: "docker-compose.yaml"
105104
target: "."
106105
timeout: 30s
107-
108106

109107
- name: Fetch the Docker images from server
110108
uses: appleboy/ssh-action@v1
111109
env:
112110
SERVER_IMAGE_NAME: ${{ env.IMAGE_TAG_SERVER }}
113111
SERVER_ADMIN_EMAIL: ${{ vars.SERVER_ADMIN_EMAIL }}
114112
SERVER_ADMIN_PASSWORD: ${{ vars.SERVER_ADMIN_PASSWORD }}
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115114
with:
116115
host: ${{ secrets.SSH_HOST }}
117116
username: ${{ secrets.SSH_USERNAME }}
118117
key: ${{ secrets.SSH_KEY }}
119-
envs: SERVER_IMAGE_NAME, SERVER_ADMIN_EMAIL, SERVER_ADMIN_PASSWORD
118+
envs: SERVER_IMAGE_NAME, SERVER_ADMIN_EMAIL, SERVER_ADMIN_PASSWORD, GITHUB_TOKEN
120119
script: |
120+
# Login to GitHub Container Registry
121+
echo "$GITHUB_TOKEN" | docker login ghcr.io -u ${{ github.actor }} --password-stdin || true
122+
121123
# Remove the previous version of the app, if exists
122124
docker-compose down
123125
# Remove all stoped images

test-ghcr-access.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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

Comments
 (0)