Initial commit for deployment
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Production deployment script for AI Service
|
||||
# This script deploys the AI service in a production environment
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
echo "Starting AI Service deployment..."
|
||||
|
||||
# Check if virtual environment exists
|
||||
if [ ! -d "venv" ]; then
|
||||
echo "Creating virtual environment..."
|
||||
python3 -m venv venv
|
||||
fi
|
||||
|
||||
# Activate virtual environment
|
||||
source venv/bin/activate
|
||||
|
||||
# Install dependencies
|
||||
echo "Installing dependencies..."
|
||||
pip install --upgrade pip
|
||||
pip install -r ai_service/requirements.txt
|
||||
|
||||
# Check if .env file exists, if not copy from .env.production
|
||||
if [ ! -f "ai_service/.env" ]; then
|
||||
echo "Creating .env file from .env.production..."
|
||||
cp ai_service/.env.production ai_service/.env
|
||||
echo "Please edit ai_service/.env to add your API keys before continuing."
|
||||
echo "Then run this script again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create data directory if it doesn't exist
|
||||
mkdir -p ai_service/data
|
||||
|
||||
# Check if Pinecone API key is set
|
||||
PINECONE_API_KEY=$(grep PINECONE_API_KEY ai_service/.env | cut -d '=' -f2)
|
||||
if [ "$PINECONE_API_KEY" = "your-pinecone-api-key-here" ]; then
|
||||
echo "Warning: Pinecone API key not set. Vector storage will not be available."
|
||||
echo "Edit ai_service/.env to set your Pinecone API key."
|
||||
fi
|
||||
|
||||
# Check if OpenAI API key is set
|
||||
OPENAI_API_KEY=$(grep OPENAI_API_KEY ai_service/.env | cut -d '=' -f2)
|
||||
if [ "$OPENAI_API_KEY" = "your-openai-api-key-here" ]; then
|
||||
echo "Warning: OpenAI API key not set. AI responses will be placeholders."
|
||||
echo "Edit ai_service/.env to set your OpenAI API key."
|
||||
fi
|
||||
|
||||
# Stop any existing service
|
||||
echo "Stopping any existing AI service..."
|
||||
pkill -f "uvicorn ai_service.run:app" || true
|
||||
|
||||
# Start the service with nohup
|
||||
echo "Starting AI service..."
|
||||
cd $(dirname "$0")
|
||||
nohup uvicorn ai_service.run:app --host 0.0.0.0 --port 5251 > ai_service.log 2>&1 &
|
||||
|
||||
# Wait for service to start
|
||||
sleep 2
|
||||
|
||||
# Check if service is running
|
||||
if pgrep -f "uvicorn ai_service.run:app" > /dev/null; then
|
||||
echo "AI service started successfully!"
|
||||
echo "Service is running on http://0.0.0.0:5251"
|
||||
echo "Logs are available in ai_service.log"
|
||||
else
|
||||
echo "Failed to start AI service. Check ai_service.log for details."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test the service
|
||||
echo "Testing service health..."
|
||||
if curl -s http://localhost:5251/health | grep -q "healthy"; then
|
||||
echo "Service is healthy!"
|
||||
else
|
||||
echo "Service health check failed. Check ai_service.log for details."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Deployment complete!"
|
||||
Reference in New Issue
Block a user