Skip to content

Deploy to VPS

Deploy to VPS #13

Workflow file for this run

name: Deploy to VPS
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Build app
run: npm run build
env:
NUXT_PUBLIC_API_BASE: ${{ secrets.NUXT_PUBLIC_API_BASE }}
- name: Archive build
run: tar -czf release.tar.gz .output package.json package-lock.json
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
- name: Upload release
run: |
scp -i ~/.ssh/id_ed25519 release.tar.gz \
${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}:/var/www/release.tar.gz
- name: Deploy on VPS
run: |
ssh -i ~/.ssh/id_ed25519 ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << 'EOF'
set -e
cd /var/www
rm -rf avent-front
mkdir avent-front
tar -xzf release.tar.gz -C avent-front
cd avent-front
npm ci --omit=dev --ignore-scripts
pm2 delete avent-front || true
pm2 start .output/server/index.mjs --name avent-front
pm2 save
rm -f /var/www/release.tar.gz
EOF