Skip to content

chore: add CI/CD pipeline #2

chore: add CI/CD pipeline

chore: add CI/CD pipeline #2

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
check:
name: Type Check & Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Type check
run: npx tsc --noEmit
- name: Build Docker image
run: docker build -t sulum:test .
deploy:
name: Deploy to Production
needs: check
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
- name: Deploy
run: |
ssh -i ~/.ssh/deploy_key -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }} << 'SCRIPT'
set -e
cd /root/server/products/product-sulum
echo "=== Pull latest code ==="
git fetch origin main
git reset --hard origin/main
echo "=== Rebuild and restart ==="
docker compose build --no-cache
docker compose up -d
echo "=== Health check ==="
sleep 20
curl -sf http://localhost:3000/health || docker compose logs --tail 20
echo "=== Deploy complete ==="
SCRIPT
- name: Cleanup
if: always()
run: rm -f ~/.ssh/deploy_key