File size: 4,305 Bytes
55896b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | #!/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}"
|