|
| 1 | +# Railway Deployment Guide |
| 2 | + |
| 3 | +This guide will help you deploy CrystalShards.org to Railway. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Railway account (https://railway.app) |
| 8 | +- Railway CLI installed (optional, but recommended) |
| 9 | +- GitHub token for indexing repositories |
| 10 | + |
| 11 | +## Services Required |
| 12 | + |
| 13 | +This application requires the following services: |
| 14 | + |
| 15 | +1. **PostgreSQL Database** - Primary data store |
| 16 | +2. **Redis** - Caching and job queue |
| 17 | +3. **Web Service** - Main web application |
| 18 | +4. **Job Runner** - Background job processor |
| 19 | + |
| 20 | +## Deployment Steps |
| 21 | + |
| 22 | +### Option 1: Deploy via Railway Dashboard |
| 23 | + |
| 24 | +1. **Create a new project on Railway** |
| 25 | + - Go to https://railway.app |
| 26 | + - Click "New Project" |
| 27 | + - Select "Deploy from GitHub repo" |
| 28 | + - Select this repository |
| 29 | + |
| 30 | +2. **Add PostgreSQL Database** |
| 31 | + - Click "New Service" |
| 32 | + - Select "Database" |
| 33 | + - Choose "PostgreSQL" |
| 34 | + - Railway will automatically set DATABASE_URL |
| 35 | + |
| 36 | +3. **Add Redis** |
| 37 | + - Click "New Service" |
| 38 | + - Select "Database" |
| 39 | + - Choose "Redis" |
| 40 | + - Railway will automatically set REDIS_URL |
| 41 | + |
| 42 | +4. **Configure Web Service** |
| 43 | + - Select the main service (auto-created from repo) |
| 44 | + - Go to "Settings" → "Deploy" |
| 45 | + - Set Dockerfile path: `Dockerfile` |
| 46 | + - Go to "Variables" and add: |
| 47 | + - `PORT` = 3000 |
| 48 | + - `GITHUB_TOKEN` = your GitHub personal access token |
| 49 | + - `DATABASE_URL` = (reference from PostgreSQL service) |
| 50 | + - `REDIS_URL` = (reference from Redis service) |
| 51 | + |
| 52 | +5. **Add Job Runner Service** |
| 53 | + - Click "New Service" |
| 54 | + - Select "GitHub Repo" |
| 55 | + - Choose the same repository |
| 56 | + - Go to "Settings" → "Deploy" |
| 57 | + - Set Dockerfile path: `Dockerfile.job_runner` |
| 58 | + - Go to "Variables" and add the same environment variables as web service |
| 59 | + |
| 60 | +6. **Run Database Migrations** |
| 61 | + - After first deployment, run migrations: |
| 62 | + - In Railway dashboard, go to web service |
| 63 | + - Open "Deploy Logs" |
| 64 | + - Or use Railway CLI: `railway run bin/migrate` |
| 65 | + |
| 66 | +### Option 2: Deploy via Railway CLI |
| 67 | + |
| 68 | +```bash |
| 69 | +# Install Railway CLI |
| 70 | +npm i -g @railway/cli |
| 71 | + |
| 72 | +# Login to Railway |
| 73 | +railway login |
| 74 | + |
| 75 | +# Create new project |
| 76 | +railway init |
| 77 | + |
| 78 | +# Add PostgreSQL |
| 79 | +railway add --database postgresql |
| 80 | + |
| 81 | +# Add Redis |
| 82 | +railway add --database redis |
| 83 | + |
| 84 | +# Set environment variables |
| 85 | +railway variables set GITHUB_TOKEN=your_github_token_here |
| 86 | +railway variables set PORT=3000 |
| 87 | + |
| 88 | +# Deploy |
| 89 | +railway up |
| 90 | + |
| 91 | +# Run migrations (after first deploy) |
| 92 | +railway run bin/migrate |
| 93 | +``` |
| 94 | + |
| 95 | +## Environment Variables |
| 96 | + |
| 97 | +| Variable | Description | Required | |
| 98 | +|----------|-------------|----------| |
| 99 | +| DATABASE_URL | PostgreSQL connection string | Yes (auto-set by Railway) | |
| 100 | +| REDIS_URL | Redis connection string | Yes (auto-set by Railway) | |
| 101 | +| GITHUB_TOKEN | GitHub personal access token for API | Yes | |
| 102 | +| PORT | Port for web service to listen on | Yes (default: 3000) | |
| 103 | + |
| 104 | +## Post-Deployment |
| 105 | + |
| 106 | +1. **Run migrations**: Ensure database schema is created |
| 107 | +2. **Start indexing**: The job runner will automatically start indexing GitHub repositories |
| 108 | +3. **Monitor logs**: Check Railway dashboard for any errors |
| 109 | + |
| 110 | +## Troubleshooting |
| 111 | + |
| 112 | +- **Build fails**: Check that Crystal 1.8.1 is compatible with all dependencies |
| 113 | +- **Database connection issues**: Verify DATABASE_URL is set correctly |
| 114 | +- **Redis connection issues**: Verify REDIS_URL is set correctly |
| 115 | +- **No data appearing**: Check job_runner logs to ensure indexing is working |
| 116 | + |
| 117 | +## Custom Domain (Optional) |
| 118 | + |
| 119 | +1. Go to web service settings |
| 120 | +2. Click "Domains" |
| 121 | +3. Add your custom domain |
| 122 | +4. Update DNS records as instructed by Railway |
0 commit comments