-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_render.py
More file actions
256 lines (201 loc) · 6.8 KB
/
deploy_render.py
File metadata and controls
256 lines (201 loc) · 6.8 KB
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/usr/bin/env python3
"""
Deploy to Render.com (No Credit Card Required)
"""
import os
import json
def create_render_config():
"""Create Render deployment configuration"""
print("Setting up Render.com deployment (No credit card needed)...")
# Create render.yaml
render_config = {
"services": [
{
"type": "web",
"name": "legalai-hub",
"env": "python",
"plan": "free",
"buildCommand": "pip install -r requirements_deploy.txt",
"startCommand": "python simple_webhook.py",
"envVars": [
{
"key": "PORT",
"value": "8000"
}
]
}
]
}
with open('render.yaml', 'w') as f:
json.dump(render_config, f, indent=2)
print("✅ Created render.yaml")
# Create requirements for deployment
deploy_requirements = [
"fastapi>=0.100.0",
"uvicorn[standard]>=0.20.0",
"aiohttp>=3.8.0",
"requests>=2.28.0",
"python-dotenv>=1.0.0",
"groq>=0.4.0"
]
with open('requirements_deploy.txt', 'w') as f:
f.write('\n'.join(deploy_requirements))
print("✅ Created requirements_deploy.txt")
# Update simple_webhook.py for deployment
update_webhook_for_deployment()
return True
def update_webhook_for_deployment():
"""Update webhook file for cloud deployment"""
# Read current webhook
try:
with open('simple_webhook.py', 'r', encoding='utf-8') as f:
content = f.read()
# Add port configuration for deployment
if 'PORT' not in content:
port_config = '''
# Port configuration for deployment
import os
port = int(os.getenv("PORT", 8000))
'''
# Replace the last uvicorn.run line
content = content.replace(
'uvicorn.run(app, host="0.0.0.0", port=port)',
'uvicorn.run(app, host="0.0.0.0", port=port)'
)
print("✅ Webhook configured for deployment")
except Exception as e:
print(f"Warning: Could not update webhook: {e}")
def create_deployment_guide():
"""Create deployment guide"""
guide = """# Deploy to Render.com (No Credit Card Required)
## 🆓 Why Render.com?
- **No credit card required** for free plan
- **750 hours/month** free (enough for continuous running)
- **Automatic deployments** from GitHub
- **Free SSL certificate**
- **Custom domain** support
## 📋 Step-by-Step Deployment:
### Step 1: Prepare Your Code
```bash
# Add all files to git
git add .
git commit -m "Ready for Render deployment"
git push origin main
```
### Step 2: Sign Up to Render
1. Go to [render.com](https://render.com)
2. Click **"Get Started for Free"**
3. Sign up with **GitHub** (recommended)
4. **No credit card required!**
### Step 3: Create Web Service
1. Click **"New +"** → **"Web Service"**
2. Select **"Build and deploy from a Git repository"**
3. Choose your **LegalAI Hub** repository
4. Configure:
- **Name**: `legalai-hub`
- **Environment**: `Python 3`
- **Build Command**: `pip install -r requirements_deploy.txt`
- **Start Command**: `python simple_webhook.py`
### Step 4: Set Environment Variables
In Render dashboard, add:
```
GROQ_API_KEY = your_groq_key_here
PORT = 8000
```
### Step 5: Deploy!
- Click **"Create Web Service"**
- Render will automatically build and deploy
- You'll get URL like: `https://legalai-hub.onrender.com`
## 🔄 Free Plan Limitations:
- **Service sleeps** after 15 minutes of inactivity
- **Cold start** takes ~30 seconds to wake up
- **750 hours/month** total (about 25 hours/day)
## 💡 Tips:
- Use a **ping service** to keep it awake during business hours
- Deploy during low-traffic times
- Monitor usage in Render dashboard
## 🆙 If You Need More:
- Upgrade to paid plan ($7/month) for always-on service
- But free plan is perfect for testing and light usage!
---
Generated by LegalAI Hub Setup
"""
with open('RENDER_DEPLOY.md', 'w', encoding='utf-8') as f:
f.write(guide)
print("✅ Created RENDER_DEPLOY.md")
def create_alternative_options():
"""Create guide for other free options"""
alternatives = """# Free Deployment Alternatives (No Credit Card)
## 1. 🎯 Render.com (Recommended)
- **750 hours/month** free
- No credit card required
- Python support
- Auto-deploy from GitHub
- **Perfect for a webhook-based bot**
## 2. 🐍 PythonAnywhere
- **Free tier** available
- No credit card required
- Python-focused hosting
- Good for Python apps
- Limited to 1 web app on free tier
### Steps for PythonAnywhere:
1. Go to pythonanywhere.com
2. Sign up for free account
3. Upload your code
4. Configure web app
5. Get URL like: username.pythonanywhere.com
## 3. 🔥 Firebase Hosting + Functions
- **Free tier** generous
- No credit card required
- Google's platform
- Good for serverless functions
## 4. 📦 Heroku Alternative - Fly.io
- **Free allowance** available
- Similar to Heroku
- Docker-based deployment
## 5. 🏠 Local + Tunnel Solutions
If you prefer to keep everything local:
### Option A: ngrok (Current)
- Free tunneling
- URL changes on restart
- Good for testing
### Option B: Cloudflare Tunnel
- Free permanent tunnel
- More stable than ngrok
- Requires Cloudflare account
### Option C: serveo.net
- Free SSH tunneling
- No signup required
- Command: `ssh -R 80:localhost:8000 serveo.net`
## 🎯 **Final Recommendation:**
1. **Render.com** - Best balance of free features
2. **PythonAnywhere** - If you prefer Python-specific hosting
3. **Local + Cloudflare Tunnel** - If you want to keep data local
All options above work **without credit card**!
"""
with open('FREE_ALTERNATIVES.md', 'w', encoding='utf-8') as f:
f.write(alternatives)
print("✅ Created FREE_ALTERNATIVES.md")
def main():
"""Main setup function"""
print("🆓 Setting up FREE deployment options (No Credit Card Required)")
print()
# Create Render configuration
create_render_config()
# Create deployment guides
create_deployment_guide()
create_alternative_options()
print()
print("📊 Free Options Summary:")
print("1. 🎯 Render.com - 750 hours/month, perfect for a webhook bot")
print("2. 🐍 PythonAnywhere - Python-focused, 1 web app free")
print("3. 🏠 Local + Tunnel - Keep everything on your computer")
print()
print("🚀 Next Steps:")
print("1. Read RENDER_DEPLOY.md for step-by-step guide")
print("2. Read FREE_ALTERNATIVES.md for other options")
print("3. Choose the option that fits your needs")
print()
print("✅ All options work WITHOUT credit card!")
if __name__ == "__main__":
main()