62 lines
1.7 KiB
YAML
62 lines
1.7 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/randify
|
|
NODE_ENV: test
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: randify
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
cache: npm
|
|
|
|
- run: npm ci
|
|
- run: npm run lint
|
|
- run: npm run test
|
|
- run: npm run build
|
|
|
|
- name: Run database migrations
|
|
run: npm run db:migrate
|
|
|
|
- name: Setup SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
printf '%s\n' "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
ssh-keyscan -H ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts
|
|
|
|
- name: Deploy Node.js app
|
|
run: |
|
|
rsync -avz --delete \
|
|
-e "ssh -i ~/.ssh/deploy_key" \
|
|
dist package*.json docker-compose.yml Dockerfile \
|
|
${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:~/www/randify.pro/
|
|
|
|
- name: Restart app
|
|
run: |
|
|
ssh -i ~/.ssh/deploy_key ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} \
|
|
"cd ~/www/randify.pro && docker compose down && docker compose up -d --build && sleep 5 && curl -sf http://localhost:4321/api/health || echo 'Health check skipped'"
|