Spaces:
Sleeping
Sleeping
File size: 5,676 Bytes
bb0c63f | 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | # Deployment Guide
> **Primary Responsibility:** Deployment procedures for all environments (local, Docker, cloud)
This guide explains how to deploy the Enterprise AI Gateway in different environments.
## Table of Contents
1. [Prerequisites](#prerequisites)
2. [Local Deployment](#local-deployment)
3. [Docker Deployment](#docker-deployment)
4. [Cloud Deployment](#cloud-deployment)
5. [Production Considerations](#production-considerations)
## Prerequisites
- Docker (for Docker deployment)
- Python 3.8+ (for local deployment)
- Git
- API keys for at least one LLM provider
## Local Deployment
### 1. Clone the Repository
```bash
git clone https://github.com/vn6295337/Enterprise-AI-Gateway.git
cd Enterprise-AI-Gateway
```
### 2. Set Up Environment
```bash
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment variables
cp .env.example .env
# Edit .env with your API keys
```
### 3. Run the Application
```bash
uvicorn src.main:app --host 0.0.0.0 --port 8000
```
The application will be available at `http://localhost:8000`.
## Docker Deployment
### 1. Build the Docker Image
```bash
docker build -t llm-secure-gateway .
```
### 2. Run with Environment Variables
```bash
docker run -d \
-e SERVICE_API_KEY=your_service_api_key \
-e GEMINI_API_KEY=your_gemini_api_key \
-e GROQ_API_KEY=your_groq_api_key \
-e OPENROUTER_API_KEY=your_openrouter_api_key \
-p 8000:8000 \
--name llm-gateway \
llm-secure-gateway
```
### 3. Run with Environment File
Create a `.env` file with your configuration, then:
```bash
docker run -d \
--env-file .env \
-p 8000:8000 \
--name llm-gateway \
llm-secure-gateway
```
## Cloud Deployment
### Hugging Face Spaces
1. Create a new Space at [https://huggingface.co/new-space](https://huggingface.co/new-space)
2. Choose "Docker" as the SDK
3. Select a Docker image (e.g., `python:3.11-slim`)
4. Add your repository URL
5. In Space settings, add the following secrets:
- `SERVICE_API_KEY`
- `GEMINI_API_KEY` (optional)
- `GROQ_API_KEY` (optional)
- `OPENROUTER_API_KEY` (optional)
### AWS Deployment
#### Using EC2
1. Launch an EC2 instance with Ubuntu
2. SSH into the instance
3. Install Docker:
```bash
sudo apt update
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
```
4. Deploy the container:
```bash
sudo docker run -d \
-e SERVICE_API_KEY=your_service_api_key \
-e GEMINI_API_KEY=your_gemini_api_key \
-e GROQ_API_KEY=your_groq_api_key \
-e OPENROUTER_API_KEY=your_openrouter_api_key \
-p 80:8000 \
--name llm-gateway \
llm-secure-gateway
```
#### Using ECS
1. Create an ECS cluster
2. Create a task definition with the container image
3. Configure environment variables in the task definition
4. Create a service to run the task
### Google Cloud Platform
#### Using Compute Engine
1. Create a Compute Engine instance
2. SSH into the instance
3. Install Docker and deploy as above
#### Using Cloud Run
1. Build and push the Docker image to Container Registry
2. Deploy to Cloud Run with environment variables
3. Configure authentication and networking
### Azure
#### Using Virtual Machines
1. Create a VM
2. SSH into the instance
3. Install Docker and deploy as above
#### Using Azure Container Instances
1. Create a container group
2. Specify the image and environment variables
3. Configure networking and authentication
## Production Considerations
### Security
1. **Use HTTPS**: Always deploy with SSL/TLS encryption
2. **Restrict CORS**: Set specific allowed origins instead of `*`
3. **Rotate API Keys**: Regularly rotate service and provider API keys
4. **Monitor Logs**: Set up logging and monitoring
5. **Rate Limiting**: Adjust rate limits based on expected usage
### Performance
1. **Load Balancing**: Use a load balancer for high availability
2. **Auto-scaling**: Configure auto-scaling based on demand
3. **Caching**: Implement caching for frequently requested responses
4. **Database**: Use a production database for storing logs/metrics
### Monitoring
1. **Health Checks**: Implement health checks for load balancers
2. **Metrics**: Collect and monitor performance metrics
3. **Alerts**: Set up alerts for errors and performance issues
4. **Logging**: Centralize logs for debugging and auditing
### Backup and Recovery
1. **Configuration Backup**: Backup environment configurations
2. **Disaster Recovery**: Plan for disaster recovery scenarios
3. **Rollback Strategy**: Have a rollback strategy for deployments
## Environment Configuration
See [Configuration Guide](configuration.md) for complete environment variable reference.
## Troubleshooting
See [Troubleshooting Guide](troubleshooting.md) for detailed help.
**Quick debugging:**
```bash
docker logs llm-gateway # View logs
docker ps # Check running containers
docker exec -it llm-gateway /bin/bash # Access shell
```
## Maintenance
### Updates
To update the application:
1. Pull the latest code or Docker image
2. Update environment variables if needed
3. Restart the service
### Monitoring
Regular monitoring tasks:
1. Check application logs
2. Monitor API usage and costs
3. Verify LLM provider availability
4. Review security logs
## Scaling
### Vertical Scaling
Increase resources allocated to the container/host:
- More CPU
- More memory
- Better network bandwidth
### Horizontal Scaling
Deploy multiple instances behind a load balancer:
- Use sticky sessions if needed
- Share configuration across instances
- Monitor individual instance health |