Spaces:
Sleeping
Sleeping
Commit
·
d0baa2b
1
Parent(s):
6ae3186
Add Railway deployment configuration for full Docker-in-Docker support
Browse files- DEPLOY_RAILWAY.md +172 -0
- Dockerfile.railway +35 -0
- railway.json +12 -0
DEPLOY_RAILWAY.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 Deploy to Railway (Full Docker Support)
|
| 2 |
+
|
| 3 |
+
## Prerequisites
|
| 4 |
+
|
| 5 |
+
- Railway account (sign up at https://railway.app)
|
| 6 |
+
- GitHub repository connected (already done - your code is on GitHub/HF)
|
| 7 |
+
|
| 8 |
+
## Option 1: Deploy via Railway CLI (Recommended)
|
| 9 |
+
|
| 10 |
+
### Install Railway CLI
|
| 11 |
+
|
| 12 |
+
```powershell
|
| 13 |
+
# Install via npm
|
| 14 |
+
npm install -g @railway/cli
|
| 15 |
+
|
| 16 |
+
# Or download from https://railway.app/cli
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### Deploy Steps
|
| 20 |
+
|
| 21 |
+
```powershell
|
| 22 |
+
# 1. Login to Railway
|
| 23 |
+
railway login
|
| 24 |
+
|
| 25 |
+
# 2. Initialize project
|
| 26 |
+
railway init
|
| 27 |
+
|
| 28 |
+
# 3. Link to your project (create new or select existing)
|
| 29 |
+
railway link
|
| 30 |
+
|
| 31 |
+
# 4. Set environment variables (optional)
|
| 32 |
+
railway variables set MAX_EXECUTION_TIME=30
|
| 33 |
+
railway variables set MAX_MEMORY_MB=512
|
| 34 |
+
railway variables set ENABLE_NETWORK=true
|
| 35 |
+
|
| 36 |
+
# 5. Deploy!
|
| 37 |
+
railway up
|
| 38 |
+
|
| 39 |
+
# 6. Get your deployment URL
|
| 40 |
+
railway domain
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
## Option 2: Deploy via Railway Dashboard
|
| 44 |
+
|
| 45 |
+
1. **Go to Railway**: https://railway.app/new
|
| 46 |
+
|
| 47 |
+
2. **Deploy from GitHub**:
|
| 48 |
+
- Click "Deploy from GitHub repo"
|
| 49 |
+
- Authorize Railway to access your repositories
|
| 50 |
+
- Select your repository
|
| 51 |
+
|
| 52 |
+
3. **Configure Service**:
|
| 53 |
+
- Railway will auto-detect the Dockerfile
|
| 54 |
+
- Set environment variables:
|
| 55 |
+
- `NIXPACKS_DOCKERFILE` = `Dockerfile.railway`
|
| 56 |
+
- `MAX_EXECUTION_TIME` = `30`
|
| 57 |
+
- `MAX_MEMORY_MB` = `512`
|
| 58 |
+
- `ENABLE_NETWORK` = `true`
|
| 59 |
+
|
| 60 |
+
4. **Deploy**:
|
| 61 |
+
- Click "Deploy Now"
|
| 62 |
+
- Wait 5-10 minutes for build
|
| 63 |
+
- Get your URL from the "Deployments" tab
|
| 64 |
+
|
| 65 |
+
## Option 3: Deploy to Render.com
|
| 66 |
+
|
| 67 |
+
### Prerequisites
|
| 68 |
+
- Render account (https://render.com)
|
| 69 |
+
|
| 70 |
+
### Steps
|
| 71 |
+
|
| 72 |
+
1. **Create New Web Service**:
|
| 73 |
+
- Go to https://dashboard.render.com
|
| 74 |
+
- Click "New +" → "Web Service"
|
| 75 |
+
- Connect your GitHub repository
|
| 76 |
+
|
| 77 |
+
2. **Configure**:
|
| 78 |
+
- **Name**: `isolated-sandbox`
|
| 79 |
+
- **Environment**: `Docker`
|
| 80 |
+
- **Region**: Select closest to you
|
| 81 |
+
- **Branch**: `master`
|
| 82 |
+
- **Dockerfile Path**: `Dockerfile.railway` (or leave default)
|
| 83 |
+
|
| 84 |
+
3. **Plan**:
|
| 85 |
+
- Free tier: Limited resources
|
| 86 |
+
- Starter ($7/mo): Recommended for production
|
| 87 |
+
|
| 88 |
+
4. **Environment Variables**:
|
| 89 |
+
```
|
| 90 |
+
MAX_EXECUTION_TIME=30
|
| 91 |
+
MAX_MEMORY_MB=512
|
| 92 |
+
ENABLE_NETWORK=true
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
5. **Create Web Service**:
|
| 96 |
+
- Click "Create Web Service"
|
| 97 |
+
- Wait for deployment
|
| 98 |
+
|
| 99 |
+
## Verify Deployment
|
| 100 |
+
|
| 101 |
+
Once deployed, test your API:
|
| 102 |
+
|
| 103 |
+
```powershell
|
| 104 |
+
# Replace with your Railway/Render URL
|
| 105 |
+
$API_URL = "https://your-app.railway.app"
|
| 106 |
+
|
| 107 |
+
# Test health
|
| 108 |
+
Invoke-RestMethod "$API_URL/health"
|
| 109 |
+
|
| 110 |
+
# Test stateless execution
|
| 111 |
+
Invoke-RestMethod "$API_URL/execute" -Method POST -Body (@{
|
| 112 |
+
code = "print('Hello from Railway!')"
|
| 113 |
+
language = "python"
|
| 114 |
+
} | ConvertTo-Json) -ContentType "application/json"
|
| 115 |
+
|
| 116 |
+
# Test session creation
|
| 117 |
+
$session = Invoke-RestMethod "$API_URL/sessions" -Method POST -Body (@{
|
| 118 |
+
metadata = @{user = "test"}
|
| 119 |
+
timeout_minutes = 30
|
| 120 |
+
} | ConvertTo-Json) -ContentType "application/json"
|
| 121 |
+
|
| 122 |
+
Write-Host "Session created: $($session.session_id)"
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Expected Results
|
| 126 |
+
|
| 127 |
+
✅ **All features should work**:
|
| 128 |
+
- Session management
|
| 129 |
+
- File upload/download
|
| 130 |
+
- Persistent state
|
| 131 |
+
- Multi-language execution
|
| 132 |
+
- Docker-in-Docker
|
| 133 |
+
|
| 134 |
+
## Troubleshooting
|
| 135 |
+
|
| 136 |
+
### Build fails
|
| 137 |
+
- Check that `Dockerfile.railway` exists
|
| 138 |
+
- Verify all files pushed to repository
|
| 139 |
+
- Check Railway build logs
|
| 140 |
+
|
| 141 |
+
### Container starts but sessions fail
|
| 142 |
+
- Railway needs Docker-in-Docker capability
|
| 143 |
+
- Ensure using `docker:dind` base image
|
| 144 |
+
- Check container has sufficient resources (2GB+ RAM)
|
| 145 |
+
|
| 146 |
+
### Port issues
|
| 147 |
+
- Ensure app listens on `0.0.0.0:7860`
|
| 148 |
+
- Railway automatically assigns `PORT` variable (we use 7860)
|
| 149 |
+
|
| 150 |
+
## Cost Estimates
|
| 151 |
+
|
| 152 |
+
**Railway**:
|
| 153 |
+
- Hobby plan: $5/month + usage
|
| 154 |
+
- ~$10-20/month for moderate use
|
| 155 |
+
- Includes 512GB transfer
|
| 156 |
+
|
| 157 |
+
**Render**:
|
| 158 |
+
- Free tier: Limited (may sleep)
|
| 159 |
+
- Starter: $7/month (recommended)
|
| 160 |
+
- Professional: $25/month
|
| 161 |
+
|
| 162 |
+
## Next Steps
|
| 163 |
+
|
| 164 |
+
After deployment:
|
| 165 |
+
1. Run verification script: `python verify_enhanced_features.py` (pointing to your Railway URL)
|
| 166 |
+
2. Build devenv image on first session creation (~15 min)
|
| 167 |
+
3. Test all features
|
| 168 |
+
4. Update documentation with your production URL
|
| 169 |
+
|
| 170 |
+
---
|
| 171 |
+
|
| 172 |
+
**Need help?** Check Railway docs: https://docs.railway.app/
|
Dockerfile.railway
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Railway Dockerfile - Full Docker-in-Docker Support
|
| 2 |
+
# This enables ALL features: sessions, file operations, multi-language execution
|
| 3 |
+
|
| 4 |
+
FROM docker:24-dind
|
| 5 |
+
|
| 6 |
+
# Install Python 3.11 and dependencies
|
| 7 |
+
RUN apk add --no-cache \
|
| 8 |
+
python3 \
|
| 9 |
+
py3-pip \
|
| 10 |
+
python3-dev \
|
| 11 |
+
gcc \
|
| 12 |
+
musl-dev \
|
| 13 |
+
linux-headers
|
| 14 |
+
|
| 15 |
+
# Create app directory
|
| 16 |
+
WORKDIR /app
|
| 17 |
+
|
| 18 |
+
# Copy requirements and install
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
+
RUN pip3 install --no-cache-dir -r requirements.txt --break-system-packages
|
| 21 |
+
|
| 22 |
+
# Copy application
|
| 23 |
+
COPY . .
|
| 24 |
+
|
| 25 |
+
# Expose port
|
| 26 |
+
EXPOSE 7860
|
| 27 |
+
|
| 28 |
+
# Health check
|
| 29 |
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
| 30 |
+
CMD wget -q --spider http://localhost:7860/health || exit 1
|
| 31 |
+
|
| 32 |
+
# Start Docker daemon in background and run app
|
| 33 |
+
CMD dockerd-entrypoint.sh & \
|
| 34 |
+
sleep 5 && \
|
| 35 |
+
python3 app.py
|
railway.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://railway.app/railway.schema.json",
|
| 3 |
+
"build": {
|
| 4 |
+
"builder": "DOCKERFILE",
|
| 5 |
+
"dockerfilePath": "Dockerfile.railway"
|
| 6 |
+
},
|
| 7 |
+
"deploy": {
|
| 8 |
+
"numReplicas": 1,
|
| 9 |
+
"restartPolicyType": "ON_FAILURE",
|
| 10 |
+
"restartPolicyMaxRetries": 10
|
| 11 |
+
}
|
| 12 |
+
}
|