build.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Inventory Management System Docker Build Script
  3. # This script builds and deploys the complete inventory solution
  4. set -e
  5. echo "🚀 Building Inventory Management System..."
  6. # Check if Docker is installed
  7. if ! command -v docker &> /dev/null; then
  8. echo "❌ Docker is not installed. Please install Docker first."
  9. exit 1
  10. fi
  11. # Check if Docker Compose is installed
  12. if ! command -v docker-compose &> /dev/null; then
  13. echo "❌ Docker Compose is not installed. Please install Docker Compose first."
  14. exit 1
  15. fi
  16. # Check if .env file exists, if not copy from example
  17. if [ ! -f .env ]; then
  18. echo "📝 Creating .env file from .env.example..."
  19. cp .env.example .env
  20. echo "⚠️ Please edit .env file with your configuration before running the application."
  21. fi
  22. # Create uploads directory if it doesn't exist
  23. if [ ! -d uploads ]; then
  24. echo "📁 Creating uploads directory..."
  25. mkdir -p uploads
  26. chmod 755 uploads
  27. fi
  28. # Build and start the application
  29. echo "🔨 Building Docker containers..."
  30. docker-compose build
  31. echo "🚀 Starting application..."
  32. docker-compose up -d
  33. # Wait for database to be ready
  34. echo "⏳ Waiting for database to be ready..."
  35. sleep 30
  36. # Check if containers are running
  37. echo "🔍 Checking container status..."
  38. docker-compose ps
  39. # Show logs
  40. echo "📋 Showing application logs..."
  41. docker-compose logs inventory-app
  42. echo "✅ Build complete!"
  43. echo ""
  44. echo "🌐 Application is available at: http://localhost"
  45. echo "🔧 API endpoints are available at: http://localhost/api"
  46. echo "📊 Database is available at: localhost:3306"
  47. echo ""
  48. echo "📝 To stop the application: docker-compose down"
  49. echo "📝 To view logs: docker-compose logs -f"
  50. echo "📝 To rebuild: docker-compose build --no-cache"