ci: deploy via tar over SSH with atomic swap (runner has no rsync)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Asger Geel Weirsøe
2026-06-11 19:19:08 +02:00
co-authored by Claude Opus 4.8
parent 7e583af822
commit 86d4fbf81c
+11 -3
View File
@@ -32,6 +32,9 @@ jobs:
- name: Build site
run: npm run build
# tar over SSH (the runner image has no rsync). Build is unpacked into
# a .new dir on CT148 and atomically swapped in, so the live web root is
# never left half-written.
- name: Deploy dist/ to CT148 over SSH
env:
DEPLOY_HOST: 192.168.10.148
@@ -42,7 +45,12 @@ jobs:
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
SSH="ssh -i $HOME/.ssh/deploy_key -o StrictHostKeyChecking=accept-new"
ssh-keyscan -t ed25519 "$DEPLOY_HOST" >> ~/.ssh/known_hosts 2>/dev/null || true
rsync -az --delete \
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=accept-new" \
dist/ "$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/"
$SSH "$DEPLOY_USER@$DEPLOY_HOST" "rm -rf $DEPLOY_PATH.new && mkdir -p $DEPLOY_PATH.new"
tar -C dist -czf - . | $SSH "$DEPLOY_USER@$DEPLOY_HOST" \
"tar -C $DEPLOY_PATH.new -xzf - \
&& rm -rf $DEPLOY_PATH.old \
&& { mv $DEPLOY_PATH $DEPLOY_PATH.old 2>/dev/null || true; } \
&& mv $DEPLOY_PATH.new $DEPLOY_PATH \
&& rm -rf $DEPLOY_PATH.old"