Skip to content

Commit 0d2d360

Browse files
i have test it working fine
1 parent 302d9e0 commit 0d2d360

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

‎api/Dockerfile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ WORKDIR /api
6565
RUN apk add --no-cache \
6666
curl \
6767
dumb-init \
68+
xdg-utils \
6869
&& rm -rf /var/cache/apk/*
6970

7071
COPY --from=builder --chown=mrdas:mrdas /api/node_modules ./node_modules
@@ -89,7 +90,7 @@ RUN mkdir -p /api/logs && \
8990
RUN chmod +x /api/start.sh
9091

9192
USER mrdas
92-
EXPOSE 3000
93+
EXPOSE 3000 51212
9394

9495
# Health check
9596
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \

‎api/start.sh‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/bin/sh
22

3-
# Start Node.js application with PM2 process manager
4-
# PM2 will handle process management, clustering, and auto-restart
3+
# ==============================================================================
4+
# Node.js backend start script with PM2 and Prisma setup
5+
# ==============================================================================
6+
# Prisma DB push and seed run ONLY in development mode
7+
# ==============================================================================
58

6-
# Determine which app to start based on environment
7-
# Default to development if API_MODE is not set
9+
# Default API_MODE
810
API_MODE=${API_MODE:-development}
911

12+
# Determine PM2 app name
1013
if [ "$API_MODE" = "staging" ]; then
1114
APP_NAME="nodejs-backend-with-postgresql-staging"
1215
elif [ "$API_MODE" = "development" ]; then
@@ -18,5 +21,45 @@ else
1821
APP_NAME="nodejs-backend-with-postgresql-dev"
1922
fi
2023

21-
echo "Starting PM2 with app: $APP_NAME (API_MODE: $API_MODE)"
24+
echo "=============================================="
25+
echo "API_MODE: $API_MODE"
26+
echo "PM2 App Name: $APP_NAME"
27+
echo "=============================================="
28+
29+
# ------------------------------------------------------------------------------
30+
# Load environment variables
31+
# ------------------------------------------------------------------------------
32+
if [ -f .env ]; then
33+
echo "Loading .env file"
34+
export $(grep -v '^#' .env | xargs)
35+
fi
36+
37+
# ------------------------------------------------------------------------------
38+
# Run Prisma DB push + seed ONLY in development
39+
# ------------------------------------------------------------------------------
40+
if [ "$API_MODE" = "development" ]; then
41+
echo "Running Prisma steps (dev only)..."
42+
43+
echo "Running Prisma DB push..."
44+
npx prisma db push --accept-data-loss
45+
if [ $? -ne 0 ]; then
46+
echo "Error: Prisma db push failed!"
47+
exit 1
48+
fi
49+
50+
if [ -f prisma/seed.js ]; then
51+
echo "Running Prisma seed script..."
52+
node prisma/seed.js
53+
if [ $? -ne 0 ]; then
54+
echo "Warning: Prisma seed failed, continuing..."
55+
fi
56+
fi
57+
else
58+
echo "Skipping Prisma steps (not dev mode)"
59+
fi
60+
61+
# ------------------------------------------------------------------------------
62+
# Start Node.js app with PM2
63+
# ------------------------------------------------------------------------------
64+
echo "Starting Node.js app with PM2..."
2265
exec npx pm2-runtime start ecosystem.config.js --only $APP_NAME

‎docker-compose.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ services:
8484
# - ./api:/api
8585
ports:
8686
- "${API_DEBUG_PORT:-8900}:3000"
87+
- "${PRISMA_STUDIO_PORT:-8901}:51212"
8788
networks:
8889
- nodejs_backend_with_postgresql_network
8990
depends_on:

0 commit comments

Comments
 (0)