183 lines
5.7 KiB
Bash
183 lines
5.7 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# Complete Setup Script
|
||
|
|
# Sets up the entire development environment
|
||
|
|
|
||
|
|
echo -e "\n========================================"
|
||
|
|
echo -e " COMPLETE DEVELOPMENT SETUP"
|
||
|
|
echo -e "========================================\n"
|
||
|
|
|
||
|
|
# Colors
|
||
|
|
GREEN='\033[0;32m'
|
||
|
|
RED='\033[0;31m'
|
||
|
|
YELLOW='\033[0;33m'
|
||
|
|
CYAN='\033[0;36m'
|
||
|
|
NC='\033[0m' # No Color
|
||
|
|
|
||
|
|
ERRORS=0
|
||
|
|
|
||
|
|
# Check prerequisites
|
||
|
|
echo -e "${CYAN}Checking prerequisites...${NC}\n"
|
||
|
|
|
||
|
|
# Check Node.js
|
||
|
|
if command -v node &> /dev/null; then
|
||
|
|
NODE_VERSION=$(node --version)
|
||
|
|
echo -e "${GREEN}✅ Node.js: $NODE_VERSION${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${RED}❌ Node.js not found${NC}"
|
||
|
|
echo -e " Install: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt install -y nodejs"
|
||
|
|
((ERRORS++))
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check npm
|
||
|
|
if command -v npm &> /dev/null; then
|
||
|
|
NPM_VERSION=$(npm --version)
|
||
|
|
echo -e "${GREEN}✅ npm: $NPM_VERSION${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${RED}❌ npm not found${NC}"
|
||
|
|
((ERRORS++))
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check Docker
|
||
|
|
if command -v docker &> /dev/null; then
|
||
|
|
DOCKER_VERSION=$(docker --version | cut -d' ' -f3 | tr -d ',')
|
||
|
|
echo -e "${GREEN}✅ Docker: $DOCKER_VERSION${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${YELLOW}⚠️ Docker not found (optional for database)${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Check required tools
|
||
|
|
for tool in jq bc netcat-openbsd; do
|
||
|
|
if command -v $tool &> /dev/null 2>&1 || dpkg -l | grep -q "^ii.*$tool"; then
|
||
|
|
echo -e "${GREEN}✅ $tool available${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${YELLOW}⚠️ $tool not found (will install)${NC}"
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
if [ $ERRORS -gt 0 ]; then
|
||
|
|
echo -e "\n${RED}❌ Prerequisites check failed. Please install missing tools.${NC}"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Install missing tools
|
||
|
|
echo -e "\n${CYAN}Installing missing tools...${NC}"
|
||
|
|
sudo apt update -qq
|
||
|
|
sudo apt install -y jq bc netcat-openbsd postgresql-client > /dev/null 2>&1
|
||
|
|
|
||
|
|
# Setup environment files
|
||
|
|
echo -e "\n${CYAN}Setting up environment files...${NC}"
|
||
|
|
|
||
|
|
# Webapp .env.local
|
||
|
|
if [ ! -f "webapp/.env.local" ]; then
|
||
|
|
cat > webapp/.env.local << EOF
|
||
|
|
NEXT_PUBLIC_ORCH_URL=http://localhost:8080
|
||
|
|
NEXTAUTH_SECRET=dev-secret-change-in-production-min-32-chars-$(date +%s)
|
||
|
|
EOF
|
||
|
|
echo -e "${GREEN}✅ Created webapp/.env.local${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${GREEN}✅ webapp/.env.local exists${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Orchestrator .env
|
||
|
|
if [ ! -f "orchestrator/.env" ]; then
|
||
|
|
if [ -f "orchestrator/src/config/env.example" ]; then
|
||
|
|
cp orchestrator/src/config/env.example orchestrator/.env
|
||
|
|
# Update with defaults
|
||
|
|
sed -i 's|DATABASE_URL=.*|DATABASE_URL=postgresql://postgres:postgres@localhost:5432/comboflow|' orchestrator/.env
|
||
|
|
sed -i 's|SESSION_SECRET=.*|SESSION_SECRET=dev-secret-change-in-production-min-32-chars-'$(date +%s)'|' orchestrator/.env
|
||
|
|
sed -i 's|RUN_MIGRATIONS=.*|RUN_MIGRATIONS=true|' orchestrator/.env
|
||
|
|
echo -e "${GREEN}✅ Created orchestrator/.env${NC}"
|
||
|
|
else
|
||
|
|
cat > orchestrator/.env << EOF
|
||
|
|
NODE_ENV=development
|
||
|
|
PORT=8080
|
||
|
|
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/comboflow
|
||
|
|
REDIS_URL=redis://localhost:6379
|
||
|
|
SESSION_SECRET=dev-secret-change-in-production-min-32-chars-$(date +%s)
|
||
|
|
RUN_MIGRATIONS=true
|
||
|
|
LOG_LEVEL=info
|
||
|
|
EOF
|
||
|
|
echo -e "${GREEN}✅ Created orchestrator/.env${NC}"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo -e "${GREEN}✅ orchestrator/.env exists${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Install dependencies
|
||
|
|
echo -e "\n${CYAN}Installing dependencies...${NC}"
|
||
|
|
|
||
|
|
# Webapp
|
||
|
|
if [ ! -d "webapp/node_modules" ]; then
|
||
|
|
echo -e "Installing webapp dependencies..."
|
||
|
|
cd webapp && npm install && cd ..
|
||
|
|
echo -e "${GREEN}✅ Webapp dependencies installed${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${GREEN}✅ Webapp dependencies already installed${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Orchestrator
|
||
|
|
if [ ! -d "orchestrator/node_modules" ]; then
|
||
|
|
echo -e "Installing orchestrator dependencies..."
|
||
|
|
cd orchestrator && npm install && cd ..
|
||
|
|
echo -e "${GREEN}✅ Orchestrator dependencies installed${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${GREEN}✅ Orchestrator dependencies already installed${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Contracts
|
||
|
|
if [ ! -d "contracts/node_modules" ]; then
|
||
|
|
echo -e "Installing contracts dependencies..."
|
||
|
|
cd contracts && npm install && cd ..
|
||
|
|
echo -e "${GREEN}✅ Contracts dependencies installed${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${GREEN}✅ Contracts dependencies already installed${NC}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Setup database (optional)
|
||
|
|
echo -e "\n${CYAN}Database setup...${NC}"
|
||
|
|
if command -v docker &> /dev/null; then
|
||
|
|
echo -e "Setting up PostgreSQL with Docker..."
|
||
|
|
./scripts/setup-database.sh
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
echo -e "${GREEN}✅ Database setup complete${NC}"
|
||
|
|
|
||
|
|
# Run migrations
|
||
|
|
echo -e "\nRunning database migrations..."
|
||
|
|
./scripts/run-migrations.sh
|
||
|
|
if [ $? -eq 0 ]; then
|
||
|
|
echo -e "${GREEN}✅ Migrations complete${NC}"
|
||
|
|
else
|
||
|
|
echo -e "${YELLOW}⚠️ Migrations failed (database may not be ready yet)${NC}"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo -e "${YELLOW}⚠️ Database setup skipped or failed${NC}"
|
||
|
|
fi
|
||
|
|
else
|
||
|
|
echo -e "${YELLOW}⚠️ Docker not available, skipping database setup${NC}"
|
||
|
|
echo -e " You can set up PostgreSQL manually or use Azure Database"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Summary
|
||
|
|
echo -e "\n========================================"
|
||
|
|
echo -e " SETUP COMPLETE"
|
||
|
|
echo -e "========================================\n"
|
||
|
|
|
||
|
|
echo -e "${GREEN}✅ Development environment ready!${NC}\n"
|
||
|
|
|
||
|
|
echo -e "${CYAN}Next steps:${NC}"
|
||
|
|
echo -e " 1. Start all services:"
|
||
|
|
echo -e " ${CYAN}./scripts/start-all.sh${NC}"
|
||
|
|
echo -e ""
|
||
|
|
echo -e " 2. Check service status:"
|
||
|
|
echo -e " ${CYAN}./scripts/check-status.sh${NC}"
|
||
|
|
echo -e ""
|
||
|
|
echo -e " 3. Test endpoints:"
|
||
|
|
echo -e " ${CYAN}./scripts/test-curl.sh${NC}"
|
||
|
|
echo -e ""
|
||
|
|
echo -e " 4. Access services:"
|
||
|
|
echo -e " ${CYAN}Webapp: http://localhost:3000${NC}"
|
||
|
|
echo -e " ${CYAN}Orchestrator: http://localhost:8080${NC}"
|
||
|
|
echo -e " ${CYAN}Health: http://localhost:8080/health${NC}"
|
||
|
|
echo ""
|
||
|
|
|