GuidesDevOps
Tutorial: deploying an Astro site to a VPS with GitHub Actions
1. Prepare the VPS
- A
deployuser owning/var/www/site. - Its public key in
~/.ssh/authorized_keys. - Caddy serving
/var/www/site: see install Caddy.
2. Repository secrets
In GitHub: Settings, Secrets and variables, Actions. Add SSH_KEY (the private key), HOST and USER.
3. The workflow
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- name: Upload to the VPS
run: |
install -m 600 -D /dev/null ~/.ssh/id_ed25519
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
ssh-keyscan -H "${{ secrets.HOST }}" >> ~/.ssh/known_hosts
rsync -az --delete dist/ "${{ secrets.USER }}@${{ secrets.HOST }}:/var/www/site/"
4. The pipeline
- 1Push to mainAfter reviewing the working branch.
- 2BuildOn a GitHub machine, clean every time.
- 3Uploadrsync only transfers the changed files.
- 4LiveCaddy serves the new version immediately.
The principle: CI/CD, deploy on every push. The server: hosting on a VPS.
Frequently asked questions
- Do I need Node.js on the VPS?
- Not for a static site: the build happens at GitHub, the VPS only receives the files. A web server like Caddy serves them.
- How do I protect the SSH key?
- A key dedicated to deployment, stored in the repository secrets, tied to a VPS user that can only reach the site folder.
- What if the build fails?
- The workflow stops before the upload: the live site does not change. GitHub notifies you by email.