Support non-standard SSH port in DEPLOY_HOST (fqdn:port)

ssh-keyscan and rsync's -e ssh both need the port passed via -p rather
than embedded in the hostname; parse DEPLOY_HOST accordingly, defaulting
to 22 when no port is given.
This commit is contained in:
2026-08-13 15:16:54 +00:00
parent ca521657f8
commit e96fd2d95b
+11 -3
View File
@@ -23,6 +23,7 @@ jobs:
- name: Set up SSH key - name: Set up SSH key
# Same key used both as the theme repo's deploy key (Gitea) and for # Same key used both as the theme repo's deploy key (Gitea) and for
# the webserver login (below) — one secret, two authorized_keys entries. # the webserver login (below) — one secret, two authorized_keys entries.
# DEPLOY_HOST may be "fqdn" or "fqdn:port" (non-standard SSH port).
env: env:
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }} DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }} DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
@@ -30,7 +31,11 @@ jobs:
mkdir -p ~/.ssh mkdir -p ~/.ssh
printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key printf '%s\n' "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H git.haemka.in "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null DEPLOY_HOSTNAME="${DEPLOY_HOST%%:*}"
DEPLOY_PORT="${DEPLOY_HOST#*:}"
[ "$DEPLOY_PORT" = "$DEPLOY_HOST" ] && DEPLOY_PORT=22
ssh-keyscan -H git.haemka.in >> ~/.ssh/known_hosts 2>/dev/null
ssh-keyscan -H -p "$DEPLOY_PORT" "$DEPLOY_HOSTNAME" >> ~/.ssh/known_hosts 2>/dev/null
- name: Fetch theme submodule - name: Fetch theme submodule
run: | run: |
@@ -53,6 +58,9 @@ jobs:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
run: | run: |
DEPLOY_HOSTNAME="${DEPLOY_HOST%%:*}"
DEPLOY_PORT="${DEPLOY_HOST#*:}"
[ "$DEPLOY_PORT" = "$DEPLOY_HOST" ] && DEPLOY_PORT=22
rsync -avz --delete \ rsync -avz --delete \
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=yes" \ -e "ssh -i ~/.ssh/deploy_key -p $DEPLOY_PORT -o StrictHostKeyChecking=yes" \
output/ "${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}" output/ "${DEPLOY_USER}@${DEPLOY_HOSTNAME}:${DEPLOY_PATH}"