Assist_Design/apps/bff/scripts/docker-entrypoint.sh
barsa 29ad4236d6 Enhance development scripts and update package dependencies
- Added a new script command `dev:studio` to facilitate studio management in development.
- Updated the Prisma dependency in BFF package to version 6.16.0 for improved features and bug fixes.
- Refactored Dockerfiles for BFF and Portal to enhance health check mechanisms during startup.
- Removed deprecated WhmcsApiMethodsService to streamline the integration services.
- Cleaned up various components and services in the SIM management module for better maintainability and clarity.
2025-12-02 18:56:38 +09:00

66 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
set -e
# =============================================================================
# Docker Entrypoint Script
# =============================================================================
# Handles runtime setup before starting the application:
# - Waits for database and cache dependencies
# - Decodes SF_PRIVATE_KEY_BASE64 to file if provided
# - Runs Prisma migrations if RUN_MIGRATIONS=true
# =============================================================================
echo "🚀 Starting Customer Portal Backend..."
PRISMA_VERSION="${PRISMA_VERSION:-6.16.0}"
export PRISMA_SCHEMA_PATH="/app/prisma/schema.prisma"
# Handle Salesforce private key from base64 environment variable
if [ -n "$SF_PRIVATE_KEY_BASE64" ]; then
echo "📝 Decoding Salesforce private key..."
mkdir -p /app/secrets
echo "$SF_PRIVATE_KEY_BASE64" | base64 -d > /app/secrets/sf-private.key
chmod 600 /app/secrets/sf-private.key
export SF_PRIVATE_KEY_PATH=/app/secrets/sf-private.key
echo "✅ Salesforce private key configured"
fi
# Wait for database if DATABASE_URL is set
# Extract host:port from postgresql://user:pass@host:port/db
if [ -n "$DATABASE_URL" ]; then
DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^:/]+):([0-9]+)/.*|\1|')
DB_PORT=$(echo "$DATABASE_URL" | sed -E 's|.*@([^:/]+):([0-9]+)/.*|\2|')
if [ -n "$DB_HOST" ] && [ -n "$DB_PORT" ]; then
echo "⏳ Waiting for database ($DB_HOST:$DB_PORT)..."
until nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null; do
sleep 2
done
echo "✅ Database is ready"
fi
fi
# Wait for Redis if REDIS_URL is set
# Extract host:port from redis://host:port/db
if [ -n "$REDIS_URL" ]; then
REDIS_HOST=$(echo "$REDIS_URL" | sed -E 's|redis://([^:/]+):([0-9]+).*|\1|')
REDIS_PORT=$(echo "$REDIS_URL" | sed -E 's|redis://([^:/]+):([0-9]+).*|\2|')
if [ -n "$REDIS_HOST" ] && [ -n "$REDIS_PORT" ]; then
echo "⏳ Waiting for cache ($REDIS_HOST:$REDIS_PORT)..."
until nc -z "$REDIS_HOST" "$REDIS_PORT" 2>/dev/null; do
sleep 2
done
echo "✅ Cache is ready"
fi
fi
# Run database migrations if enabled
if [ "$RUN_MIGRATIONS" = "true" ] && [ -n "$DATABASE_URL" ]; then
echo "🗄️ Running database migrations..."
npx prisma@"${PRISMA_VERSION}" migrate deploy --schema=/app/prisma/schema.prisma
echo "✅ Migrations complete"
fi
echo "🌐 Starting server on port ${PORT:-4000}..."
# Execute the main command (node dist/main.js)
exec "$@"