Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
57 lines
2.0 KiB
YAML
57 lines
2.0 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [master, main]
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
|
|
# The runner forces omit of optional deps, dropping @img/sharp-linux-x64
|
|
# (sharp's platform binary) -> astro:assets MissingSharp. Clear the omit
|
|
# env and force-install the linux/glibc/x64 sharp binary per sharp's
|
|
# official cross-platform install, then verify it loads.
|
|
- name: Install dependencies
|
|
env:
|
|
npm_config_omit: ""
|
|
npm_config_optional: "true"
|
|
run: |
|
|
npm install --include=optional
|
|
npm install --include=optional --os=linux --libc=glibc --cpu=x64 sharp
|
|
node -e "console.log('sharp', require('sharp').versions.sharp)"
|
|
|
|
- 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
|
|
DEPLOY_USER: root
|
|
DEPLOY_PATH: /var/www/asger
|
|
run: |
|
|
set -euo pipefail
|
|
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
|
|
$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"
|