Test / docker-start.sh
Rox-Turbo's picture
Upload 10 files
55896b1 verified
#!/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}"