66 lines
1.6 KiB
YAML
66 lines
1.6 KiB
YAML
name: Deploy to VPS
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
env:
|
|
IMAGE_NAME: biztaghavi
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v4
|
|
with:
|
|
version: latest
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Lint
|
|
run: pnpm lint
|
|
|
|
- name: Type check
|
|
run: pnpm exec tsc --noEmit
|
|
|
|
- name: Build Docker image
|
|
run: docker build -t $IMAGE_NAME:${{ github.sha }} .
|
|
|
|
- name: Save Docker image
|
|
run: docker save $IMAGE_NAME:${{ github.sha }} | gzip > image.tar.gz
|
|
|
|
- name: Copy image to VPS
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_USER }}
|
|
key: ${{ secrets.VPS_SSH_KEY }}
|
|
source: image.tar.gz
|
|
target: /tmp/
|
|
|
|
- name: Deploy on VPS
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.VPS_HOST }}
|
|
username: ${{ secrets.VPS_USER }}
|
|
key: ${{ secrets.VPS_SSH_KEY }}
|
|
script: |
|
|
cd /srv/biztaghavi
|
|
docker load < /tmp/image.tar.gz
|
|
docker tag biztaghavi:${{ github.sha }} biztaghavi:latest
|
|
docker compose up -d --no-build --remove-orphans
|
|
docker image prune -f
|
|
rm /tmp/image.tar.gz
|
|
echo "✅ Deployed ${{ github.sha }}"
|