Spaces:
Running
Running
Pulastya B
commited on
Commit
·
c10a976
1
Parent(s):
48520bd
feat: Add Render deployment configuration
Browse files- Add render.yaml for automated deployment via Blueprint
- Update Dockerfile to use uvicorn for better performance
- Create comprehensive RENDER_DEPLOYMENT.md guide
- Configure health check endpoint at /api/health
- Set up environment variables for Render
- Optimize for ephemeral storage with /tmp directories
Deployment instructions:
1. Connect GitHub repo to Render
2. Deploy via Blueprint (render.yaml)
3. Add GOOGLE_API_KEY as secret
4. App will be live at https://data-science-agent.onrender.com
Supports both free tier and paid plans with clear upgrade path
- Dockerfile +2 -5
- RENDER_DEPLOYMENT.md +246 -0
- render.yaml +37 -0
Dockerfile
CHANGED
|
@@ -70,9 +70,6 @@ ENV ARTIFACT_BACKEND=local
|
|
| 70 |
# Cloud Run expects the service to listen on the PORT env variable
|
| 71 |
EXPOSE 8080
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
|
| 75 |
-
CMD python -c "import requests; requests.get('http://localhost:8080/health')" || exit 1
|
| 76 |
|
| 77 |
-
# Run the FastAPI application
|
| 78 |
-
CMD ["python", "src/api/app.py"]
|
|
|
|
| 70 |
# Cloud Run expects the service to listen on the PORT env variable
|
| 71 |
EXPOSE 8080
|
| 72 |
|
| 73 |
+
# Run the FastAPI application with uvicorn
|
| 74 |
+
CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "8080"]
|
|
|
|
| 75 |
|
|
|
|
|
|
RENDER_DEPLOYMENT.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Render Deployment Guide
|
| 2 |
+
|
| 3 |
+
## Prerequisites
|
| 4 |
+
|
| 5 |
+
1. A [Render account](https://render.com/) (free tier available)
|
| 6 |
+
2. Your GitHub repository connected to Render
|
| 7 |
+
3. Google Gemini API key
|
| 8 |
+
|
| 9 |
+
## Quick Deploy (Recommended)
|
| 10 |
+
|
| 11 |
+
### Option 1: Using render.yaml (Infrastructure as Code)
|
| 12 |
+
|
| 13 |
+
1. **Push your code to GitHub** (already done)
|
| 14 |
+
|
| 15 |
+
2. **Create a new Web Service on Render:**
|
| 16 |
+
- Go to https://dashboard.render.com/
|
| 17 |
+
- Click "New +" → "Blueprint"
|
| 18 |
+
- Connect your GitHub repository: `Pulastya-B/DevSprint-Data-Science-Agent`
|
| 19 |
+
- Render will automatically detect the `render.yaml` file
|
| 20 |
+
- Click "Apply"
|
| 21 |
+
|
| 22 |
+
3. **Add Secret Environment Variable:**
|
| 23 |
+
- Go to your service dashboard
|
| 24 |
+
- Navigate to "Environment" tab
|
| 25 |
+
- Add your `GOOGLE_API_KEY` (this is sensitive and not included in render.yaml)
|
| 26 |
+
- Click "Save Changes"
|
| 27 |
+
|
| 28 |
+
4. **Deploy:**
|
| 29 |
+
- Render will automatically build and deploy your application
|
| 30 |
+
- Wait for the build to complete (~5-10 minutes for first deploy)
|
| 31 |
+
- Your app will be available at: `https://data-science-agent.onrender.com`
|
| 32 |
+
|
| 33 |
+
### Option 2: Manual Setup
|
| 34 |
+
|
| 35 |
+
1. **Create a new Web Service:**
|
| 36 |
+
- Go to https://dashboard.render.com/
|
| 37 |
+
- Click "New +" → "Web Service"
|
| 38 |
+
- Connect your GitHub repository
|
| 39 |
+
|
| 40 |
+
2. **Configure the service:**
|
| 41 |
+
- **Name:** `data-science-agent`
|
| 42 |
+
- **Region:** Oregon (US West)
|
| 43 |
+
- **Branch:** `main`
|
| 44 |
+
- **Runtime:** Docker
|
| 45 |
+
- **Plan:** Free (or Starter for production)
|
| 46 |
+
|
| 47 |
+
3. **Add Environment Variables:**
|
| 48 |
+
```
|
| 49 |
+
LLM_PROVIDER=gemini
|
| 50 |
+
GOOGLE_API_KEY=<your-api-key-here>
|
| 51 |
+
GEMINI_MODEL=gemini-2.5-flash
|
| 52 |
+
REASONING_EFFORT=medium
|
| 53 |
+
CACHE_DB_PATH=/tmp/cache_db/cache.db
|
| 54 |
+
CACHE_TTL_SECONDS=86400
|
| 55 |
+
OUTPUT_DIR=/tmp/outputs
|
| 56 |
+
DATA_DIR=/tmp/data
|
| 57 |
+
MAX_PARALLEL_TOOLS=5
|
| 58 |
+
MAX_RETRIES=3
|
| 59 |
+
TIMEOUT_SECONDS=300
|
| 60 |
+
PORT=8080
|
| 61 |
+
ARTIFACT_BACKEND=local
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
4. **Configure Health Check:**
|
| 65 |
+
- **Health Check Path:** `/api/health`
|
| 66 |
+
|
| 67 |
+
5. **Deploy:**
|
| 68 |
+
- Click "Create Web Service"
|
| 69 |
+
- Wait for the build to complete
|
| 70 |
+
|
| 71 |
+
## Important Notes
|
| 72 |
+
|
| 73 |
+
### Free Tier Limitations
|
| 74 |
+
|
| 75 |
+
- **Spin down after inactivity:** Free tier services spin down after 15 minutes of inactivity
|
| 76 |
+
- **Cold starts:** First request after spin-down will take 30-60 seconds
|
| 77 |
+
- **Memory:** 512 MB RAM (may be tight for large ML models)
|
| 78 |
+
- **Build time:** Free tier has slower build times
|
| 79 |
+
|
| 80 |
+
### Upgrading to Paid Plan
|
| 81 |
+
|
| 82 |
+
For production use, consider upgrading to at least the **Starter plan ($7/month)**:
|
| 83 |
+
- No spin-down
|
| 84 |
+
- Faster builds
|
| 85 |
+
- More memory (512 MB → 2 GB)
|
| 86 |
+
- Better performance
|
| 87 |
+
|
| 88 |
+
### Storage Considerations
|
| 89 |
+
|
| 90 |
+
- Render uses **ephemeral storage** - files are lost on restart
|
| 91 |
+
- For persistent storage, consider:
|
| 92 |
+
- Connecting to external storage (S3, GCS)
|
| 93 |
+
- Using Render's persistent disk (paid plans only)
|
| 94 |
+
- Storing only temporary analysis results
|
| 95 |
+
|
| 96 |
+
### Performance Optimization
|
| 97 |
+
|
| 98 |
+
1. **Use caching:** The app includes SQLite caching for repeated queries
|
| 99 |
+
2. **Monitor memory usage:** Large datasets may exceed free tier limits
|
| 100 |
+
3. **Optimize docker image:** The multi-stage build already optimizes image size
|
| 101 |
+
4. **Regional selection:** Choose a region close to your users
|
| 102 |
+
|
| 103 |
+
## Deployment Commands
|
| 104 |
+
|
| 105 |
+
### Manual Rebuild (if needed)
|
| 106 |
+
```bash
|
| 107 |
+
# Trigger rebuild via Render Dashboard
|
| 108 |
+
# or use Render API
|
| 109 |
+
curl -X POST https://api.render.com/v1/services/<service-id>/deploys \
|
| 110 |
+
-H "Authorization: Bearer <your-api-key>"
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
### Check Logs
|
| 114 |
+
```bash
|
| 115 |
+
# View logs in Render Dashboard
|
| 116 |
+
# or use Render CLI
|
| 117 |
+
render logs -s data-science-agent
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
## Custom Domain (Optional)
|
| 121 |
+
|
| 122 |
+
1. Go to your service dashboard
|
| 123 |
+
2. Click "Settings" → "Custom Domain"
|
| 124 |
+
3. Add your domain (e.g., `agent.yourdomain.com`)
|
| 125 |
+
4. Update your DNS records as instructed
|
| 126 |
+
5. Render automatically provisions SSL certificates
|
| 127 |
+
|
| 128 |
+
## Troubleshooting
|
| 129 |
+
|
| 130 |
+
### Build Fails
|
| 131 |
+
|
| 132 |
+
**Issue:** Docker build timeout
|
| 133 |
+
- **Solution:** Increase build timeout in Render settings
|
| 134 |
+
- **Alternative:** Optimize Dockerfile to reduce build time
|
| 135 |
+
|
| 136 |
+
**Issue:** Out of memory during build
|
| 137 |
+
- **Solution:** Upgrade to paid plan with more memory
|
| 138 |
+
- **Alternative:** Reduce dependencies in requirements.txt
|
| 139 |
+
|
| 140 |
+
### App Crashes on Startup
|
| 141 |
+
|
| 142 |
+
**Issue:** Missing environment variables
|
| 143 |
+
- **Solution:** Verify all required env vars are set in Render dashboard
|
| 144 |
+
|
| 145 |
+
**Issue:** Port binding error
|
| 146 |
+
- **Solution:** Ensure app listens on `0.0.0.0` and PORT env variable
|
| 147 |
+
|
| 148 |
+
### Slow Performance
|
| 149 |
+
|
| 150 |
+
**Issue:** Cold starts on free tier
|
| 151 |
+
- **Solution:** Upgrade to paid plan to prevent spin-down
|
| 152 |
+
- **Workaround:** Use a cron job to ping your app every 10 minutes
|
| 153 |
+
|
| 154 |
+
**Issue:** Large dataset processing timeout
|
| 155 |
+
- **Solution:** Increase TIMEOUT_SECONDS env variable
|
| 156 |
+
- **Consider:** Processing large datasets asynchronously
|
| 157 |
+
|
| 158 |
+
## Monitoring
|
| 159 |
+
|
| 160 |
+
### Health Check
|
| 161 |
+
Your app exposes a health check endpoint at `/api/health`:
|
| 162 |
+
```bash
|
| 163 |
+
curl https://data-science-agent.onrender.com/api/health
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
### Logs
|
| 167 |
+
- View real-time logs in Render Dashboard
|
| 168 |
+
- Configure log drains for external monitoring (paid plans)
|
| 169 |
+
|
| 170 |
+
### Metrics
|
| 171 |
+
Render provides built-in metrics:
|
| 172 |
+
- CPU usage
|
| 173 |
+
- Memory usage
|
| 174 |
+
- Request count
|
| 175 |
+
- Response time
|
| 176 |
+
|
| 177 |
+
## Security Best Practices
|
| 178 |
+
|
| 179 |
+
1. **Never commit API keys** to Git (use environment variables)
|
| 180 |
+
2. **Enable CORS** only for trusted domains in production
|
| 181 |
+
3. **Use HTTPS** (Render provides this automatically)
|
| 182 |
+
4. **Rotate API keys** regularly
|
| 183 |
+
5. **Monitor usage** to detect anomalies
|
| 184 |
+
|
| 185 |
+
## Cost Estimation
|
| 186 |
+
|
| 187 |
+
### Free Tier
|
| 188 |
+
- Cost: $0/month
|
| 189 |
+
- Best for: Development, testing, hackathons
|
| 190 |
+
- Limitations: Spin-down, slower builds, 512MB RAM
|
| 191 |
+
|
| 192 |
+
### Starter Plan ($7/month)
|
| 193 |
+
- No spin-down
|
| 194 |
+
- 512MB RAM → 2GB RAM
|
| 195 |
+
- Faster builds
|
| 196 |
+
- Better for: Small production apps
|
| 197 |
+
|
| 198 |
+
### Standard Plan ($25/month)
|
| 199 |
+
- 4GB RAM
|
| 200 |
+
- High performance
|
| 201 |
+
- Best for: Production apps with moderate traffic
|
| 202 |
+
|
| 203 |
+
## Deployment Checklist
|
| 204 |
+
|
| 205 |
+
- [ ] Code pushed to GitHub
|
| 206 |
+
- [ ] `render.yaml` committed to repository
|
| 207 |
+
- [ ] Render account created
|
| 208 |
+
- [ ] GitHub repository connected to Render
|
| 209 |
+
- [ ] Blueprint deployed (or manual service created)
|
| 210 |
+
- [ ] `GOOGLE_API_KEY` added as secret environment variable
|
| 211 |
+
- [ ] Health check endpoint verified
|
| 212 |
+
- [ ] Application accessible at Render URL
|
| 213 |
+
- [ ] Custom domain configured (optional)
|
| 214 |
+
- [ ] Monitoring and alerts set up
|
| 215 |
+
|
| 216 |
+
## Support
|
| 217 |
+
|
| 218 |
+
- **Render Documentation:** https://render.com/docs
|
| 219 |
+
- **Render Community:** https://community.render.com/
|
| 220 |
+
- **GitHub Issues:** https://github.com/Pulastya-B/DevSprint-Data-Science-Agent/issues
|
| 221 |
+
|
| 222 |
+
## Next Steps
|
| 223 |
+
|
| 224 |
+
After successful deployment:
|
| 225 |
+
|
| 226 |
+
1. **Test the deployment:**
|
| 227 |
+
```bash
|
| 228 |
+
curl https://data-science-agent.onrender.com/api/health
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
2. **Upload a test dataset** via the web interface
|
| 232 |
+
|
| 233 |
+
3. **Monitor logs** for any errors
|
| 234 |
+
|
| 235 |
+
4. **Configure custom domain** (optional)
|
| 236 |
+
|
| 237 |
+
5. **Set up monitoring** and alerts
|
| 238 |
+
|
| 239 |
+
6. **Share your deployed app!** 🚀
|
| 240 |
+
|
| 241 |
+
---
|
| 242 |
+
|
| 243 |
+
**Your app will be live at:**
|
| 244 |
+
`https://data-science-agent.onrender.com`
|
| 245 |
+
|
| 246 |
+
(URL will be different if you choose a different service name)
|
render.yaml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
services:
|
| 2 |
+
- type: web
|
| 3 |
+
name: data-science-agent
|
| 4 |
+
runtime: docker
|
| 5 |
+
plan: free # Change to 'starter' or higher for production
|
| 6 |
+
region: oregon # Change to your preferred region
|
| 7 |
+
branch: main
|
| 8 |
+
dockerfilePath: ./Dockerfile
|
| 9 |
+
envVars:
|
| 10 |
+
- key: LLM_PROVIDER
|
| 11 |
+
value: gemini
|
| 12 |
+
- key: GOOGLE_API_KEY
|
| 13 |
+
sync: false # Mark as secret - add via Render dashboard
|
| 14 |
+
- key: GEMINI_MODEL
|
| 15 |
+
value: gemini-2.5-flash
|
| 16 |
+
- key: REASONING_EFFORT
|
| 17 |
+
value: medium
|
| 18 |
+
- key: CACHE_DB_PATH
|
| 19 |
+
value: /tmp/cache_db/cache.db
|
| 20 |
+
- key: CACHE_TTL_SECONDS
|
| 21 |
+
value: 86400
|
| 22 |
+
- key: OUTPUT_DIR
|
| 23 |
+
value: /tmp/outputs
|
| 24 |
+
- key: DATA_DIR
|
| 25 |
+
value: /tmp/data
|
| 26 |
+
- key: MAX_PARALLEL_TOOLS
|
| 27 |
+
value: 5
|
| 28 |
+
- key: MAX_RETRIES
|
| 29 |
+
value: 3
|
| 30 |
+
- key: TIMEOUT_SECONDS
|
| 31 |
+
value: 300
|
| 32 |
+
- key: PORT
|
| 33 |
+
value: 8080
|
| 34 |
+
- key: ARTIFACT_BACKEND
|
| 35 |
+
value: local
|
| 36 |
+
healthCheckPath: /api/health
|
| 37 |
+
autoDeploy: true
|