Skip to content

Commit 5e70e21

Browse files
committed
fix: increase ssh-keyscan retries and wait for SSH port before scanning
1 parent afb5bd4 commit 5e70e21

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,38 @@ jobs:
6969
echo "ip=${VPS_IP}" >> "$GITHUB_OUTPUT"
7070
7171
# ---- SSH setup ----
72+
- name: Wait for SSH to become available
73+
run: |
74+
VPS_IP="${{ steps.vps.outputs.ip }}"
75+
echo "Waiting for SSH port 22 on ${VPS_IP}..."
76+
for i in $(seq 1 30); do
77+
if nc -z -w5 "$VPS_IP" 22 2>/dev/null; then
78+
echo "SSH port open on attempt $i"
79+
break
80+
fi
81+
echo "SSH port not ready yet (attempt $i/30), retrying in 10s..."
82+
sleep 10
83+
done
84+
7285
- name: Setup SSH key
7386
run: |
7487
mkdir -p ~/.ssh
7588
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
7689
chmod 600 ~/.ssh/deploy_key
77-
for i in 1 2 3; do
78-
keys=$(ssh-keyscan -H "${{ steps.vps.outputs.ip }}" 2>/dev/null) || true
79-
if [ -n "$keys" ]; then
80-
echo "$keys" >> ~/.ssh/known_hosts
90+
for i in $(seq 1 10); do
91+
keys=$(ssh-keyscan -H "${{ steps.vps.outputs.ip }}" 2>&1) || true
92+
# Filter to only key lines (ignore stderr/warnings)
93+
key_lines=$(echo "$keys" | grep -v '^#' | grep -v '^$' | grep -v 'getaddrinfo' || true)
94+
if [ -n "$key_lines" ]; then
95+
echo "$key_lines" >> ~/.ssh/known_hosts
8196
echo "ssh-keyscan succeeded on attempt $i"
8297
exit 0
8398
fi
84-
echo "ssh-keyscan attempt $i failed, retrying in 10s..."
85-
sleep 10
99+
echo "ssh-keyscan attempt $i failed, retrying in 15s..."
100+
echo "Output was: $keys"
101+
sleep 15
86102
done
87-
echo "ssh-keyscan failed after 3 attempts"
103+
echo "ssh-keyscan failed after 10 attempts"
88104
exit 1
89105
90106
# ---- Detect first deployment ----

0 commit comments

Comments
 (0)