|
| 1 | +# Full-Stack Railway Deployment |
| 2 | + |
| 3 | +Deploy the entire DevOps Learn platform to Railway as a single service. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +- **Single Railway Service**: Backend serves both WebSocket API and static frontend |
| 8 | +- **Frontend**: Next.js static export served by Express |
| 9 | +- **Backend**: Node.js WebSocket server with Docker scenario support |
| 10 | +- **Scenarios**: Kubernetes containers with kind clusters |
| 11 | + |
| 12 | +## Deployment Steps |
| 13 | + |
| 14 | +### 1. Deploy to Railway |
| 15 | + |
| 16 | +1. **Create Railway Account**: Go to [railway.app](https://railway.app) |
| 17 | +2. **New Project** → **Deploy from GitHub repo** |
| 18 | +3. **Select this repository** (root directory) |
| 19 | +4. **Set Environment Variables**: |
| 20 | + ``` |
| 21 | + NODE_ENV=production |
| 22 | + PORT=3000 |
| 23 | + ``` |
| 24 | +5. **Deploy**: Railway will use the root Dockerfile automatically |
| 25 | + |
| 26 | +### 2. How It Works |
| 27 | + |
| 28 | +1. **Build Process**: |
| 29 | + - Frontend builds to static files (`out/`) |
| 30 | + - Backend TypeScript compiles to JavaScript |
| 31 | + - Docker scenario images are built |
| 32 | + - Everything is packaged in a single container |
| 33 | + |
| 34 | +2. **Runtime**: |
| 35 | + - Express server serves static frontend files |
| 36 | + - Same server handles WebSocket connections for scenarios |
| 37 | + - Frontend connects to backend on same domain (no CORS issues) |
| 38 | + |
| 39 | +### 3. Benefits |
| 40 | + |
| 41 | +✅ **Simplified Deployment**: One service, one URL |
| 42 | +✅ **No CORS Issues**: Frontend and backend on same domain |
| 43 | +✅ **Cost Effective**: Single Railway service ($5/month free credit) |
| 44 | +✅ **Docker Support**: Full scenario functionality |
| 45 | +✅ **WebSocket Support**: Real-time terminal connections |
| 46 | + |
| 47 | +### 4. Local Development |
| 48 | + |
| 49 | +```bash |
| 50 | +# Frontend development |
| 51 | +npm run dev |
| 52 | + |
| 53 | +# Backend development |
| 54 | +cd src/server |
| 55 | +npm run dev |
| 56 | + |
| 57 | +# Full stack test |
| 58 | +npm run build |
| 59 | +npm run railway:start |
| 60 | +``` |
| 61 | + |
| 62 | +### 5. Environment Variables |
| 63 | + |
| 64 | +**Required**: |
| 65 | +- `PORT` - Server port (set by Railway automatically) |
| 66 | + |
| 67 | +**Optional**: |
| 68 | +- `NODE_ENV=production` |
| 69 | +- `FRONTEND_URL` - For CORS (not needed in full-stack mode) |
| 70 | + |
| 71 | +## File Structure |
| 72 | + |
| 73 | +``` |
| 74 | +/ |
| 75 | +├── Dockerfile # Full-stack Railway build |
| 76 | +├── railway.toml # Railway configuration |
| 77 | +├── src/ |
| 78 | +│ ├── components/ # React components |
| 79 | +│ ├── pages/ # Next.js pages |
| 80 | +│ └── server/ # Backend WebSocket server |
| 81 | +├── scenarios/ # Docker scenario definitions |
| 82 | +├── docker/ # Docker base images |
| 83 | +└── public/ # Static assets |
| 84 | +``` |
| 85 | + |
| 86 | +## Cost Estimate |
| 87 | + |
| 88 | +- **Railway**: $5/month free credit |
| 89 | +- **Total**: $0/month for starter projects |
| 90 | + |
| 91 | +Perfect for learning and prototyping! 🚀 |
0 commit comments