Skip to content

Commit 1f651ae

Browse files
Prisma fix.
1 parent d129e70 commit 1f651ae

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

β€Ždocker-entrypoint.sh

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
1-
#!/usr/bin/env sh
1+
#!/bin/sh
22
#
3-
# Entrypoint for NestJS container.
4-
# - waits for the database
5-
# - runs migrations
6-
# - starts the app
3+
# This script is the entrypoint for the Docker container.
4+
# It ensures the database is ready before running migrations and starting the app.
75

6+
# Exit immediately if a command exits with a non-zero status.
87
set -e
98

10-
# Color codes for output
9+
# Enable color output
10+
export FORCE_COLOR=1
11+
export NODE_ENV=${NODE_ENV:-production}
12+
13+
# The host for the database, read from an environment variable.
14+
# We'll set this to 'db' in the docker-compose.yml file.
15+
DB_HOST=${DATABASE_HOST:-db}
16+
DB_PORT=${DATABASE_PORT:-5432}
17+
18+
# Colors for output
1119
RED='\033[0;31m'
1220
GREEN='\033[0;32m'
1321
YELLOW='\033[1;33m'
1422
BLUE='\033[0;34m'
1523
NC='\033[0m' # No Color
1624

17-
export FORCE_COLOR=1
18-
export NODE_ENV=${NODE_ENV:-production}
25+
echo -e "${BLUE}🐳 Starting CodeBuilder application...${NC}"
26+
echo -e "${YELLOW}⏳ Waiting for database at $DB_HOST:$DB_PORT to be ready...${NC}"
1927

20-
DB_HOST=${DB_HOST:-db}
21-
DB_PORT=${DB_PORT:-5432}
22-
23-
echo -e "${BLUE}🐳 Starting NestJS application...${NC}"
24-
echo -e "${YELLOW}⏳ Waiting for database at ${DB_HOST}:${DB_PORT}...${NC}"
25-
26-
# Wait until the DB port is open
28+
# Loop until we can successfully connect to the database port.
29+
# nc (netcat) is a small utility perfect for this.
2730
while ! nc -z $DB_HOST $DB_PORT; do
28-
sleep 1
31+
sleep 1 # wait for 1 second before trying again
2932
done
3033

3134
echo -e "${GREEN}βœ… Database is ready.${NC}"
32-
echo -e "${YELLOW}πŸ”„ Running database migrations...${NC}"
3335

34-
# run migrations (adjust script name if needed)
35-
pnpm run migration:run
36+
# Run Prisma migrations.
37+
# 'prisma migrate deploy' is the command intended for production/CI/CD environments.
38+
# It applies pending migrations without generating new ones.
39+
echo -e "${YELLOW}πŸ”„ Running database migrations...${NC}"
40+
npx prisma migrate deploy
3641

3742
echo -e "${GREEN}βœ… Migrations complete.${NC}"
38-
echo -e "${BLUE}πŸš€ Launching NestJS (prod)...${NC}"
3943

40-
# Replace this shell with the main process (PID 1)
41-
exec node dist/main.js
44+
echo -e "${BLUE}πŸš€ Starting NestJS application...${NC}"
45+
46+
# Now, execute the main command provided to the container (e.g., "pnpm start").
47+
# 'exec "$@"' replaces the shell process with the given command,
48+
# ensuring it becomes the main process (PID 1) and receives signals correctly.
49+
exec "$@"

0 commit comments

Comments
Β (0)