feat: Initialize Prisma database schema and update deployment scripts for robust migration handling.
This commit is contained in:
44
deploy.sh
44
deploy.sh
@@ -1,7 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
|
||||
echo "Starting Production Deployment..."
|
||||
|
||||
# Load environment variables from .env if it exists
|
||||
if [ -f .env ]; then
|
||||
echo "Loading environment variables from .env..."
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
fi
|
||||
|
||||
@@ -11,23 +17,35 @@ if docker compose version >/dev/null 2>&1; then
|
||||
elif docker-compose version >/dev/null 2>&1; then
|
||||
COMPOSE_CMD="docker-compose"
|
||||
else
|
||||
echo "❌ Error: Docker Compose not found. Please install Docker Compose first."
|
||||
echo "Error: Docker Compose not found. Please install Docker Compose first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Name of the database container
|
||||
DB_CONTAINER_NAME="portfolio-db"
|
||||
# Configuration
|
||||
DB_CONTAINER_NAME="fikri-portfolio-db"
|
||||
DB_PORT="5429"
|
||||
|
||||
# Check if the database container is already running
|
||||
if [ "$(docker ps -q -f name=${DB_CONTAINER_NAME})" ]; then
|
||||
echo "✅ Database container '${DB_CONTAINER_NAME}' is already running."
|
||||
echo "🚀 Deploying/Updating only the application..."
|
||||
$COMPOSE_CMD up -d --no-recreate db
|
||||
$COMPOSE_CMD up -d app
|
||||
# Check if any container is using the DB port or if our specific container is running
|
||||
EXISTING_DB=$(docker ps -q -f publish=${DB_PORT})
|
||||
|
||||
if [ ! -z "$EXISTING_DB" ]; then
|
||||
echo "Database is already running on port ${DB_PORT}. Container ID: $EXISTING_DB"
|
||||
echo "Building and updating only the application..."
|
||||
# --build ensures we use the latest code
|
||||
# --no-deps ensures we don't restart the DB if it's healthy
|
||||
$COMPOSE_CMD up -d --build --no-deps app
|
||||
else
|
||||
echo "⚠️ Database container '${DB_CONTAINER_NAME}' not found or stopped."
|
||||
echo "🏗️ Deploying full stack (Database + App)..."
|
||||
$COMPOSE_CMD up -d
|
||||
echo "Database not found on port ${DB_PORT}."
|
||||
echo "Full deployment (Database + App)..."
|
||||
$COMPOSE_CMD up -d --build
|
||||
fi
|
||||
|
||||
echo "✨ Deployment script finished!"
|
||||
# Health check - optional but recommended
|
||||
echo "Waiting for application to be healthy..."
|
||||
# You could add a curl check here if desired
|
||||
|
||||
# Cleanup: remove dangling images to save disk space
|
||||
echo "Cleaning up old images..."
|
||||
docker image prune -f
|
||||
|
||||
echo "Deployment script finished successfully!"
|
||||
|
||||
Reference in New Issue
Block a user