#!/bin/bash # ============================================ # Premium Valentine Website - Docker Quick Start # Automated build and deployment script # ============================================ set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration IMAGE_NAME="valentine-app" IMAGE_TAG="3.0.0" CONTAINER_NAME="valentine-experience" PORT="8080" echo -e "${BLUE}╔════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ Valentine Experience - Docker Setup ║${NC}" echo -e "${BLUE}╚════════════════════════════════════════╝${NC}" echo "" # Check if Docker is installed if ! command -v docker &> /dev/null; then echo -e "${RED}❌ Docker is not installed. Please install Docker first.${NC}" exit 1 fi echo -e "${GREEN}✅ Docker is installed${NC}" # Check if Docker Compose is installed if command -v docker-compose &> /dev/null; then echo -e "${GREEN}✅ Docker Compose is installed${NC}" USE_COMPOSE=true else echo -e "${YELLOW}⚠️ Docker Compose not found, using Docker CLI${NC}" USE_COMPOSE=false fi echo "" echo -e "${BLUE}Building Docker image...${NC}" # Build the image if [ "$USE_COMPOSE" = true ]; then docker-compose build else docker build -t ${IMAGE_NAME}:${IMAGE_TAG} . fi if [ $? -eq 0 ]; then echo -e "${GREEN}✅ Image built successfully${NC}" else echo -e "${RED}❌ Build failed${NC}" exit 1 fi echo "" echo -e "${BLUE}Starting container...${NC}" # Stop and remove existing container if it exists if [ "$(docker ps -aq -f name=${CONTAINER_NAME})" ]; then echo -e "${YELLOW}⚠️ Stopping existing container...${NC}" docker stop ${CONTAINER_NAME} 2>/dev/null || true docker rm ${CONTAINER_NAME} 2>/dev/null || true fi # Start the container if [ "$USE_COMPOSE" = true ]; then docker-compose up -d else docker run -d \ --name ${CONTAINER_NAME} \ -p ${PORT}:8080 \ --restart unless-stopped \ ${IMAGE_NAME}:${IMAGE_TAG} fi if [ $? -eq 0 ]; then echo -e "${GREEN}✅ Container started successfully${NC}" else echo -e "${RED}❌ Failed to start container${NC}" exit 1 fi # Wait for container to be healthy echo "" echo -e "${BLUE}Waiting for application to be ready...${NC}" sleep 3 # Check if container is running if [ "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then echo -e "${GREEN}✅ Container is running${NC}" # Test the application if curl -s -o /dev/null -w "%{http_code}" http://localhost:${PORT} | grep -q "200"; then echo -e "${GREEN}✅ Application is responding${NC}" else echo -e "${YELLOW}⚠️ Application may still be starting...${NC}" fi else echo -e "${RED}❌ Container is not running${NC}" echo -e "${YELLOW}Showing logs:${NC}" docker logs ${CONTAINER_NAME} exit 1 fi echo "" echo -e "${GREEN}╔════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ Deployment Successful! 🎉 ║${NC}" echo -e "${GREEN}╚════════════════════════════════════════╝${NC}" echo "" echo -e "${BLUE}📍 Application URL:${NC} http://localhost:${PORT}" echo -e "${BLUE}🏥 Health Check:${NC} http://localhost:${PORT}/health" echo "" echo -e "${YELLOW}Useful Commands:${NC}" echo -e " View logs: docker logs -f ${CONTAINER_NAME}" echo -e " Stop container: docker stop ${CONTAINER_NAME}" echo -e " Restart: docker restart ${CONTAINER_NAME}" echo -e " Remove: docker rm -f ${CONTAINER_NAME}" echo "" echo -e "${BLUE}Opening browser...${NC}" # Try to open browser (works on most systems) if command -v xdg-open &> /dev/null; then xdg-open http://localhost:${PORT} 2>/dev/null & elif command -v open &> /dev/null; then open http://localhost:${PORT} 2>/dev/null & elif command -v start &> /dev/null; then start http://localhost:${PORT} 2>/dev/null & fi echo -e "${GREEN}✅ Setup complete!${NC}"