Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ jobs:
runs-on: ubuntu-latest

steps:

# ---------------- CHECKOUT ----------------

- name: Checkout
uses: actions/checkout@v4


# ---------------- NODE + PNPM ----------------

- name: Setup pnpm
Expand All @@ -28,6 +30,7 @@ jobs:
node-version: 20
cache: pnpm


# ---------------- INSTALL + BUILD ----------------

- name: Install dependencies
Expand All @@ -36,6 +39,7 @@ jobs:
- name: Build workspace
run: pnpm -r run build


# ---------------- SSH SETUP ----------------

- name: Setup SSH
Expand All @@ -45,6 +49,7 @@ jobs:
chmod 600 ~/.ssh/ec2.pem
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts


# ---------------- PREPARE SERVER ----------------

- name: Prepare directories
Expand All @@ -63,6 +68,7 @@ jobs:

EOF


# ---------------- DEPLOY GATEWAY ----------------

- name: Deploy Gateway
Expand All @@ -77,6 +83,7 @@ jobs:
gateway/package.json \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/var/www/backend/gateway/


# ---------------- DEPLOY SERVICES ----------------

- name: Deploy Services
Expand All @@ -86,6 +93,7 @@ jobs:
services/ \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/var/www/backend/services/


# ---------------- DEPLOY NEXTJS ----------------

- name: Deploy Next standalone
Expand All @@ -95,20 +103,23 @@ jobs:
frontend/web/.next/standalone/ \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/var/www/frontend/


- name: Deploy Next static
run: |
rsync -avz \
-e "ssh -i ~/.ssh/ec2.pem" \
frontend/web/.next/static/ \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/var/www/frontend/.next/static/


- name: Deploy public assets
run: |
rsync -avz \
-e "ssh -i ~/.ssh/ec2.pem" \
frontend/web/public/ \
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:/var/www/frontend/public/


# ---------------- FIX MONOREPO NEXT STRUCTURE ----------------

- name: Fix standalone structure
Expand All @@ -122,6 +133,7 @@ jobs:

EOF


# ---------------- RESTART SERVICES ----------------

- name: Restart services
Expand All @@ -131,10 +143,7 @@ jobs:
echo "Restarting gateway..."

cd /var/www/backend/gateway

# install gateway dependencies
pnpm install --prod

pm2 reload gateway || pm2 start dist/server.js --name gateway


Expand All @@ -144,6 +153,9 @@ jobs:
cd "$dir"
name=$(basename "$dir")

# install dependencies for each service
pnpm install --prod

if [ -f "dist/server.js" ]; then
pm2 reload "$name" || pm2 start dist/server.js --name "$name"
fi
Expand All @@ -153,13 +165,10 @@ jobs:
echo "Restarting frontend..."

cd /var/www/frontend

# install frontend dependencies (fixes "Cannot find module 'next'")
pnpm install --prod

pm2 reload frontend || PORT=3000 pm2 start server.js --name frontend


pm2 save

EOF
EOF
1 change: 1 addition & 0 deletions services/checkout-service/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { env } from './config/env.js';
checkoutDBEvents();
connectDB();

//server
app.listen(env.port, () => {
console.log(`checkout service running on ${env.port}`);
});