Skip to content

Commit 4288e0c

Browse files
authored
fix: simplify deploy.yml by removing sudo commands
Refactor deployment script to remove sudo and simplify commands.
1 parent 1937f40 commit 4288e0c

1 file changed

Lines changed: 18 additions & 24 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ jobs:
2525
node-version: '20'
2626

2727
- name: 📦 Install pnpm
28-
run: npm install -g pnpm@latest-10
28+
uses: pnpm/action-setup@v4
29+
with:
30+
version: 10
2931

3032
- name: 📥 Install dependencies
3133
# On self-hosted, this is lightning fast because the store is local
@@ -46,49 +48,41 @@ jobs:
4648
- name: 🚀 Deploy backend
4749
run: |
4850
BACKEND_PATH="${{ secrets.BACKEND_PATH }}"
51+
echo "📤 Copying backend files to $BACKEND_PATH ..."
52+
mkdir -p "$BACKEND_PATH"
53+
rsync -az --delete --exclude 'node_modules' --exclude '.git' --exclude '__tests__' --exclude 'coverage' --exclude 'lcov-report' backend/ "$BACKEND_PATH/"
4954
50-
# 1. Sync files and ensure directory exists
51-
sudo mkdir -p "$BACKEND_PATH"
52-
sudo rsync -az --delete --exclude 'node_modules' --exclude '.git' backend/ "$BACKEND_PATH/"
53-
54-
# 2. Fix permissions & create the uploads folder Multer needs
55-
sudo mkdir -p "$BACKEND_PATH/uploads"
56-
sudo chown -R ubuntu:ubuntu "$BACKEND_PATH"
57-
sudo chmod -R 755 "$BACKEND_PATH"
58-
59-
echo "🔑 Setting up .env..."
60-
sudo -u ubuntu tee "$BACKEND_PATH/.env" << ENVEOF > /dev/null
55+
echo "🔑 Setting up environment variables..."
56+
cat > "$BACKEND_PATH/.env" << ENVEOF
6157
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
6258
TURNSTILE_SECRET_KEY=${{ secrets.TURNSTILE_SECRET_KEY }}
6359
PORT=5000
6460
NODE_ENV=production
6561
ENVEOF
62+
chmod 600 "$BACKEND_PATH/.env"
6663
67-
# 3. Production install and restart
64+
echo "🚀 Starting backend with PM2..."
6865
cd "$BACKEND_PATH"
69-
sudo -u ubuntu -E pnpm install --prod
70-
sudo -u ubuntu -E pm2 restart "stackconverter-backend" --update-env || sudo -u ubuntu -E pm2 start index.js --name "stackconverter-backend"
71-
sudo -u ubuntu -E pm2 save
72-
66+
pnpm install --prod
67+
pm2 restart "stackconverter-backend" --update-env || pm2 start index.js --name "stackconverter-backend"
68+
pm2 save
7369
- name: 🚀 Deploy frontend
7470
run: |
7571
FRONTEND_PATH="${{ secrets.FRONTEND_PATH }}"
7672
echo "📤 Copying frontend build to $FRONTEND_PATH ..."
7773
mkdir -p "$FRONTEND_PATH"
7874
rsync -az --delete frontend/dist/ "$FRONTEND_PATH/"
79-
8075
- name: ✅ Run health check
8176
run: |
8277
echo "🔍 Checking PM2 status and backend health..."
83-
# Check the list specifically for the ubuntu user
84-
sudo -u ubuntu pm2 status | grep stackconverter-backend
85-
sleep 5
86-
curl -s http://localhost:5000/ > /dev/null && echo "✅ Backend healthy" || (echo "❌ Backend not responding" && exit 1)
78+
pm2 status | grep stackconverter-backend
79+
curl -s http://localhost:5000/ > /dev/null && echo "✅ Backend healthy" || (echo "❌ Backend not responding")
8780
echo "🎉 Deployment Summary:"
8881
echo "✅ Frontend: https://amiroff.org/stackconverter/"
8982
echo "✅ Backend: http://localhost:5000"
9083
echo "✅ PM2 managing backend process"
9184
echo "✅ Environment variables configured"
9285
echo ""
93-
echo "Check PM2 logs: pm2 logs stackconverter-backend"
94-
echo "Monitor with: pm2 monit"
86+
echo "📝 Next steps:"
87+
echo "1. Check PM2 logs: pm2 logs stackconverter-backend"
88+
echo "2. Monitor with: pm2 monit"

0 commit comments

Comments
 (0)