Railway Deployment โ
HaloLight Railway deployment edition, an optimized one-click deployment solution tailored for the Railway platform.
Live Preview: https://halolight-railway.h7ml.cn
GitHub: https://github.com/halolight/halolight-railway
Features โ
- ๐ One-Click Deploy - Templated fast deployment, live in 30 seconds
- ๐ Auto Scaling - On-demand auto scaling, zero-downtime deploys
- ๐ PostgreSQL - One-click managed database
- ๐ด Redis - Built-in cache service support
- ๐ Custom Domains - Free HTTPS with auto renewal
- โ๏ธ Environment Variables - Convenient config management with references
- ๐ Monitoring Panel - Real-time resource monitoring and log aggregation
- ๐ Auto Deployments - Git push triggers automatic deploys
Quick Start โ
Method 1: One-Click Deploy (Recommended) โ
After clicking the button:
- Sign in to your Railway account
- Choose the GitHub repository
- Configure environment variables
- Deployment completes automatically
Method 2: CLI Deployment โ
bash
# Install Railway CLI
npm install -g @railway/cli
# Sign in to Railway
railway login
# Clone the project
git clone https://github.com/halolight/halolight-railway.git
cd halolight-railway
# Initialize Railway project
railway init
# Link to an existing project (optional)
railway link
# Deploy
railway upMethod 3: GitHub Integration โ
- Fork the halolight-railway repository
- In the Railway console select "Deploy from GitHub repo"
- Choose your forked repo
- Configure environment variables and deploy
Configuration Files โ
railway.json โ
json
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "pnpm install && pnpm build"
},
"deploy": {
"startCommand": "pnpm start",
"healthcheckPath": "/api/health",
"healthcheckTimeout": 300,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10,
"numReplicas": 1
}
}nixpacks.toml (Optional) โ
toml
[phases.setup]
nixPkgs = ["nodejs_20", "pnpm"]
[phases.install]
cmds = ["pnpm install --frozen-lockfile"]
[phases.build]
cmds = ["pnpm build"]
[start]
cmd = "pnpm start"Environment Variables โ
App Configuration โ
| Variable | Description | Example |
|---|---|---|
NODE_ENV | Runtime environment | production |
PORT | Server port | 3000 (Railway sets automatically) |
NEXT_PUBLIC_API_URL | API base URL | /api |
NEXT_PUBLIC_MOCK | Enable mock data | false |
NEXT_PUBLIC_APP_TITLE | App title | Admin Pro |
Railway Variable References โ
Railway lets you reference other services in env vars:
bash
# Reference the auto-generated domain
NEXT_PUBLIC_API_URL=https://${{RAILWAY_PUBLIC_DOMAIN}}/api
# Reference PostgreSQL service
DATABASE_URL=${{Postgres.DATABASE_URL}}
# Reference Redis service
REDIS_URL=${{Redis.REDIS_URL}}
# Reference project variables
JWT_SECRET=${{shared.JWT_SECRET}}Add Services โ
PostgreSQL Database โ
bash
# Via CLI
railway add --database postgres
# Or in the console
# 1. Click "New Service"
# 2. Select "Database" โ "PostgreSQL"
# 3. DATABASE_URL is generated automaticallyGenerated environment variables:
DATABASE_URL- Full connection stringPGHOST- HostPGPORT- PortPGUSER- UsernamePGPASSWORD- PasswordPGDATABASE- Database name
Redis Cache โ
bash
# Via CLI
railway add --database redis
# Or in the console
# 1. Click "New Service"
# 2. Select "Database" โ "Redis"
# 3. REDIS_URL is generated automaticallyGenerated environment variables:
REDIS_URL- Full connection stringREDISHOST- HostREDISPORT- PortREDISPASSWORD- Password
Custom Domains โ
Add a Domain โ
- In service settings click "Settings"
- Find the "Domains" section
- Click "Generate Domain" (free Railway domain)
- Or click "Add Custom Domain" (custom domain)
DNS Configuration โ
Type: CNAME
Name: your-subdomain
Value: <your-app>.up.railway.appHTTPS โ
Railway automatically configures HTTPS for all domains:
- Automatically requests Let's Encrypt certificates
- Auto renews
- Forces HTTPS redirects
Common Commands โ
bash
# Sign in
railway login
# View status
railway status
# Deploy
railway up
# View logs
railway logs
# Open console
railway open
# Run remote command
railway run <command>
# Connect to database
railway connect postgres
# Environment variables
railway variables
railway variables set KEY=valueMonitoring and Logs โ
Real-Time Logs โ
bash
# View logs via CLI
railway logs -f
# Or in the console
# Service โ Deployments โ click a deployment โ View LogsResource Monitoring โ
Railway console provides:
- CPU usage
- Memory usage
- Network traffic
- Request count/response time
- Error rate
Alerting โ
- Go to project settings
- Configure webhook notifications
- Supports Slack, Discord, Email
Scaling โ
Manual Scaling โ
json
// railway.json
{
"deploy": {
"numReplicas": 3
}
}Auto Scaling (Pro Plan) โ
Railway Pro supports metric-based autoscaling:
- CPU threshold
- Memory threshold
- Request queue depth
Pricing โ
| Plan | Price | Features |
|---|---|---|
| Hobby | $5/mo | 500 execution hours, 1GB RAM |
| Pro | $20/mo+ | Unlimited hours, more resources |
| Enterprise | Contact sales | Dedicated support, SLA guarantees |
FAQ โ
Q: What if deployment fails? โ
A: Check these items:
- Inspect build logs to confirm dependencies installed correctly
- Make sure
pnpm-lock.yamlis committed - Verify environment variables are set correctly
- Confirm the
startcommand is correct
Q: How to roll back a deployment? โ
A: In the Deployments page:
- Find a previous successful deployment
- Click "Redeploy"
- Or use CLI:
railway rollback
Q: How to configure private networking? โ
A: Railway services communicate over the internal network:
bash
# Use internal DNS
DATABASE_URL=postgres://user:pass@postgres.railway.internal:5432/dbComparison with Other Platforms โ
| Feature | Railway | Vercel | Fly.io |
|---|---|---|---|
| One-Click Deploy | โ | โ | โ ๏ธ CLI required |
| Managed Database | โ Built-in | โ External needed | โ Built-in |
| Free Tier/Credit | $5/mo credit | 100GB | 3 shared VMs |
| Auto Scaling | โ Pro | โ | โ |
| Private Network | โ | โ ๏ธ Limited | โ |