Blueprints · Systemd & Agents
Production
25 min · GitHub Actions
Zero-downtime GitHub Actions SSH deploy
A deploy key restricted to one command, a release directory with an atomic current symlink, and a reload of PHP-FPM or PM2. None of these files are installed into authorized_keys by the bundle.
Live config
Baked-in protections
- The key can run only the deploy script
- Port forwarding, X11, agent forwarding, and a TTY are disabled
- The current symlink is swapped after the new release is ready
- PHP-FPM or PM2 is reloaded, not the whole machine
Step 1 · text
authorized_keys line
/root/portgate-blueprints/deploy-authorized_keys
Append this as the deploy user. Do not put it on an interactive admin key.
command="/var/www/app/deploy.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAA deploy@github
Step 2 · bash
Deploy script
/var/www/app/deploy.sh
The workflow rsyncs a release directory, then this script points current at it and reloads the app process.
#!/bin/sh set -eu BASE="/var/www/app" LATEST="$(ls -1d "$BASE/releases/"* | tail -1)" test -d "$LATEST" ln -sfn "$LATEST" "$BASE/current" if command -v systemctl >/dev/null 2>&1 && systemctl list-units --type=service | grep -q php.*fpm; then systemctl reload php8.4-fpm || systemctl reload php-fpm || true fi if command -v pm2 >/dev/null 2>&1; then sudo -u "deploy" pm2 reload all || true fi
Step 3 · yaml
Workflow
.github/workflows/deploy.yml
Store the private key in the DEPLOY_KEY secret. The public half is the authorized_keys line.
name: deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Load the deploy key
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "$DEPLOY_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
- name: Upload release
run: |
RELEASE="/var/www/app/releases/${GITHUB_SHA}"
ssh -o StrictHostKeyChecking=accept-new "[email protected]" "mkdir -p '$RELEASE'"
rsync -a --delete ./ "[email protected]:$RELEASE/"
ssh "[email protected]" "/var/www/app/deploy.sh"