#!/bin/bash # VIMS Setup Script # Sets up the complete VIMS environment set -e echo "🚀 VIMS Setup Script" echo "====================" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check prerequisites echo -e "${YELLOW}Checking prerequisites...${NC}" if ! command -v docker &> /dev/null; then echo -e "${RED}Docker not found. Please install Docker first.${NC}" exit 1 fi if ! command -v docker-compose &> /dev/null; then echo -e "${RED}Docker Compose not found. Please install Docker Compose first.${NC}" exit 1 fi if ! command -v node &> /dev/null; then echo -e "${RED}Node.js not found. Please install Node.js 18+ first.${NC}" exit 1 fi echo -e "${GREEN}✓ Prerequisites met${NC}" # Create directories echo -e "${YELLOW}Creating directories...${NC}" mkdir -p data/{models,reference-images,training,observations} mkdir -p logs mkdir -p uploads echo -e "${GREEN}✓ Directories created${NC}" # Setup environment echo -e "${YELLOW}Setting up environment...${NC}" if [ ! -f .env ]; then cp .env.example .env echo -e "${GREEN}✓ Created .env file${NC}" echo -e "${YELLOW}Please edit .env with your configuration${NC}" else echo -e "${GREEN}✓ .env already exists${NC}" fi # Install dependencies echo -e "${YELLOW}Installing dependencies...${NC}" npm install echo -e "${GREEN}✓ Dependencies installed${NC}" # Start infrastructure echo -e "${YELLOW}Starting infrastructure...${NC}" docker-compose up -d postgres redis minio # Wait for services echo -e "${YELLOW}Waiting for services to start...${NC}" sleep 10 # Check if postgres is ready until docker-compose exec -T postgres pg_isready -U vims > /dev/null 2>&1; do echo -e "${YELLOW}Waiting for PostgreSQL...${NC}" sleep 2 done echo -e "${GREEN}✓ PostgreSQL ready${NC}" # Check if redis is ready until docker-compose exec -T redis redis-cli ping > /dev/null 2>&1; do echo -e "${YELLOW}Waiting for Redis...${NC}" sleep 2 done echo -e "${GREEN}✓ Redis ready${NC}" # Setup database echo -e "${YELLOW}Setting up database...${NC}" npm run db:setup echo -e "${GREEN}✓ Database setup complete${NC}" # Create MinIO bucket echo -e "${YELLOW}Setting up MinIO...${NC}" docker-compose exec -T minio mc alias set local http://localhost:9000 vims vims-secret-key || true docker-compose exec -T minio mc mb local/vims-images || true echo -e "${GREEN}✓ MinIO setup complete${NC}" # Seed data echo -e "${YELLOW}Seeding test data...${NC}" npm run db:seed echo -e "${GREEN}✓ Test data seeded${NC}" # Build application echo -e "${YELLOW}Building application...${NC}" npm run build || true echo -e "${GREEN}✓ Build complete${NC}" echo "" echo -e "${GREEN}🎉 VIMS setup complete!${NC}" echo "" echo "Next steps:" echo "1. Edit .env with your configuration" echo "2. Start the application: docker-compose up -d" echo "3. Access the API at http://localhost:3450" echo "4. Check health: curl http://localhost:3450/health" echo "" echo "Documentation:" echo "- API docs: docs/API.md" echo "- Deployment: docs/DEPLOYMENT.md"