|
|
@@ -7,6 +7,15 @@ set -e
|
|
|
|
|
|
echo "🚀 Building Inventory Management System..."
|
|
|
|
|
|
+# Load environment variables from .env file
|
|
|
+if [ -f .env ]; then
|
|
|
+ echo "📝 Loading environment variables from .env..."
|
|
|
+ export $(cat .env | grep -v '^#' | xargs)
|
|
|
+else
|
|
|
+ echo "❌ .env file not found. Please copy .env.example to .env and configure it."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
# Check if Docker is installed
|
|
|
if ! command -v docker &> /dev/null; then
|
|
|
echo "❌ Docker is not installed. Please install Docker first."
|
|
|
@@ -19,11 +28,20 @@ if ! command -v docker-compose &> /dev/null; then
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
-# Check if .env file exists, if not copy from example
|
|
|
-if [ ! -f .env ]; then
|
|
|
- echo "📝 Creating .env file from .env.example..."
|
|
|
- cp .env.example .env
|
|
|
- echo "⚠️ Please edit .env file with your configuration before running the application."
|
|
|
+# Validate required environment variables
|
|
|
+if [ -z "$DB_HOST" ] || [ "$DB_HOST" = "your-external-db-host" ]; then
|
|
|
+ echo "❌ DB_HOST is not configured in .env. Please set your external database host."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+if [ -z "$DB_USER" ] || [ "$DB_USER" = "your-db-username" ]; then
|
|
|
+ echo "❌ DB_USER is not configured in .env. Please set your database username."
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
+if [ -z "$DB_PASS" ] || [ "$DB_PASS" = "your-db-password" ]; then
|
|
|
+ echo "❌ DB_PASS is not configured in .env. Please set your database password."
|
|
|
+ exit 1
|
|
|
fi
|
|
|
|
|
|
# Create uploads directory if it doesn't exist
|
|
|
@@ -33,6 +51,36 @@ if [ ! -d uploads ]; then
|
|
|
chmod 755 uploads
|
|
|
fi
|
|
|
|
|
|
+# Display configuration summary
|
|
|
+echo "📋 Configuration Summary:"
|
|
|
+echo " 🌐 App Port: ${APP_PORT:-80}"
|
|
|
+echo " 🗄️ Database Host: $DB_HOST"
|
|
|
+echo " 🗄️ Database Port: ${DB_PORT:-3306}"
|
|
|
+echo " 🗄️ Database Name: ${DB_NAME:-inventory_db}"
|
|
|
+echo " 🗄️ Database User: $DB_USER"
|
|
|
+echo " 🔴 Redis Port: ${REDIS_PORT:-6379}"
|
|
|
+echo ""
|
|
|
+
|
|
|
+# Test database connectivity
|
|
|
+echo "🔍 Testing database connectivity..."
|
|
|
+if ! docker-compose run --rm inventory-app php -r "
|
|
|
+try {
|
|
|
+ \$pdo = new PDO('mysql:host=$DB_HOST;dbname=$DB_NAME', '$DB_USER', '$DB_PASS');
|
|
|
+ echo '✅ Database connection successful';
|
|
|
+} catch (Exception \$e) {
|
|
|
+ echo '❌ Database connection failed: ' . \$e->getMessage();
|
|
|
+ exit(1);
|
|
|
+}
|
|
|
+" 2>/dev/null; then
|
|
|
+ echo "❌ Database connection test failed. Please check your database configuration and connectivity."
|
|
|
+ echo "💡 Make sure:"
|
|
|
+ echo " - Database server is running and accessible"
|
|
|
+ echo " - Database '$DB_NAME' exists"
|
|
|
+ echo " - User '$DB_USER' has proper permissions"
|
|
|
+ echo " - Network allows connection from Docker container"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+
|
|
|
# Build and start the application
|
|
|
echo "🔨 Building Docker containers..."
|
|
|
docker-compose build
|
|
|
@@ -40,6 +88,10 @@ docker-compose build
|
|
|
echo "🚀 Starting application..."
|
|
|
docker-compose up -d
|
|
|
|
|
|
+# Wait a moment for services to start
|
|
|
+echo "⏳ Waiting for services to start..."
|
|
|
+sleep 10
|
|
|
+
|
|
|
# Check if containers are running
|
|
|
echo "🔍 Checking container status..."
|
|
|
docker-compose ps
|
|
|
@@ -50,10 +102,12 @@ docker-compose logs inventory-app
|
|
|
|
|
|
echo "✅ Build complete!"
|
|
|
echo ""
|
|
|
-echo "🌐 Application is available at: http://localhost"
|
|
|
-echo "🔧 API endpoints are available at: http://localhost/api"
|
|
|
-echo "⚠️ Make sure your external database is accessible and configured in .env"
|
|
|
+echo "🌐 Application is available at: http://localhost:${APP_PORT:-80}"
|
|
|
+echo "🔧 API endpoints are available at: http://localhost:${APP_PORT:-80}/api"
|
|
|
+echo "🗄️ Connected to database: $DB_HOST:${DB_PORT:-3306}/$DB_NAME"
|
|
|
echo ""
|
|
|
-echo "📝 To stop the application: docker-compose down"
|
|
|
-echo "📝 To view logs: docker-compose logs -f"
|
|
|
-echo "📝 To rebuild: docker-compose build --no-cache"
|
|
|
+echo "📝 Management Commands:"
|
|
|
+echo " � Stop application: docker-compose down"
|
|
|
+echo " � View logs: docker-compose logs -f"
|
|
|
+echo " � Rebuild: docker-compose build --no-cache"
|
|
|
+echo " 🐚 Access container: docker-compose exec inventory-app bash"
|