fix: simplify deploy.yml by removing sudo commands #171
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🚀 Build & Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| concurrency: | |
| group: production_deploy | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: [self-hosted, linux, x64] | |
| environment: | |
| name: production | |
| steps: | |
| - name: 📥 Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: 🟩 Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: 📦 Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: 📥 Install dependencies | |
| # On self-hosted, this is lightning fast because the store is local | |
| run: pnpm install --frozen-lockfile | |
| - name: 🧪 Run backend tests | |
| run: | | |
| echo "🧪 Running backend test suite with coverage..." | |
| COVERAGE_REPORTERS=text pnpm --filter backend test:coverage | |
| echo "✅ All backend tests passed with coverage!" | |
| continue-on-error: false | |
| - name: 🏗️ Build frontend | |
| run: pnpm build:frontend | |
| env: | |
| VITE_TURNSTILE_SITE_KEY: ${{ secrets.VITE_TURNSTILE_SITE_KEY }} | |
| - name: 🚀 Deploy backend | |
| run: | | |
| BACKEND_PATH="${{ secrets.BACKEND_PATH }}" | |
| echo "📤 Copying backend files to $BACKEND_PATH ..." | |
| mkdir -p "$BACKEND_PATH" | |
| rsync -az --delete --exclude 'node_modules' --exclude '.git' --exclude '__tests__' --exclude 'coverage' --exclude 'lcov-report' backend/ "$BACKEND_PATH/" | |
| echo "🔑 Setting up environment variables..." | |
| cat > "$BACKEND_PATH/.env" << ENVEOF | |
| GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }} | |
| TURNSTILE_SECRET_KEY=${{ secrets.TURNSTILE_SECRET_KEY }} | |
| PORT=5000 | |
| NODE_ENV=production | |
| ENVEOF | |
| chmod 600 "$BACKEND_PATH/.env" | |
| echo "🚀 Starting backend with PM2..." | |
| cd "$BACKEND_PATH" | |
| pnpm install --prod | |
| pm2 restart "stackconverter-backend" --update-env || pm2 start index.js --name "stackconverter-backend" | |
| pm2 save | |
| - name: 🚀 Deploy frontend | |
| run: | | |
| FRONTEND_PATH="${{ secrets.FRONTEND_PATH }}" | |
| echo "📤 Copying frontend build to $FRONTEND_PATH ..." | |
| mkdir -p "$FRONTEND_PATH" | |
| rsync -az --delete frontend/dist/ "$FRONTEND_PATH/" | |
| - name: ✅ Run health check | |
| run: | | |
| echo "🔍 Checking PM2 status and backend health..." | |
| pm2 status | grep stackconverter-backend | |
| curl -s http://localhost:5000/ > /dev/null && echo "✅ Backend healthy" || (echo "❌ Backend not responding") | |
| echo "🎉 Deployment Summary:" | |
| echo "✅ Frontend: https://amiroff.org/stackconverter/" | |
| echo "✅ Backend: http://localhost:5000" | |
| echo "✅ PM2 managing backend process" | |
| echo "✅ Environment variables configured" | |
| echo "" | |
| echo "📝 Next steps:" | |
| echo "1. Check PM2 logs: pm2 logs stackconverter-backend" | |
| echo "2. Monitor with: pm2 monit" |