Skip to content

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 โ€‹

Deploy on Railway

After clicking the button:

  1. Sign in to your Railway account
  2. Choose the GitHub repository
  3. Configure environment variables
  4. 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 up

Method 3: GitHub Integration โ€‹

  1. Fork the halolight-railway repository
  2. In the Railway console select "Deploy from GitHub repo"
  3. Choose your forked repo
  4. 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 โ€‹

VariableDescriptionExample
NODE_ENVRuntime environmentproduction
PORTServer port3000 (Railway sets automatically)
NEXT_PUBLIC_API_URLAPI base URL/api
NEXT_PUBLIC_MOCKEnable mock datafalse
NEXT_PUBLIC_APP_TITLEApp titleAdmin 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 automatically

Generated environment variables:

  • DATABASE_URL - Full connection string
  • PGHOST - Host
  • PGPORT - Port
  • PGUSER - Username
  • PGPASSWORD - Password
  • PGDATABASE - 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 automatically

Generated environment variables:

  • REDIS_URL - Full connection string
  • REDISHOST - Host
  • REDISPORT - Port
  • REDISPASSWORD - Password

Custom Domains โ€‹

Add a Domain โ€‹

  1. In service settings click "Settings"
  2. Find the "Domains" section
  3. Click "Generate Domain" (free Railway domain)
  4. Or click "Add Custom Domain" (custom domain)

DNS Configuration โ€‹

Type: CNAME
Name: your-subdomain
Value: <your-app>.up.railway.app

HTTPS โ€‹

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=value

Monitoring and Logs โ€‹

Real-Time Logs โ€‹

bash
# View logs via CLI
railway logs -f

# Or in the console
# Service โ†’ Deployments โ†’ click a deployment โ†’ View Logs

Resource Monitoring โ€‹

Railway console provides:

  • CPU usage
  • Memory usage
  • Network traffic
  • Request count/response time
  • Error rate

Alerting โ€‹

  1. Go to project settings
  2. Configure webhook notifications
  3. 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 โ€‹

PlanPriceFeatures
Hobby$5/mo500 execution hours, 1GB RAM
Pro$20/mo+Unlimited hours, more resources
EnterpriseContact salesDedicated support, SLA guarantees

FAQ โ€‹

Q: What if deployment fails? โ€‹

A: Check these items:

  1. Inspect build logs to confirm dependencies installed correctly
  2. Make sure pnpm-lock.yaml is committed
  3. Verify environment variables are set correctly
  4. Confirm the start command is correct

Q: How to roll back a deployment? โ€‹

A: In the Deployments page:

  1. Find a previous successful deployment
  2. Click "Redeploy"
  3. 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/db

Comparison with Other Platforms โ€‹

FeatureRailwayVercelFly.io
One-Click Deployโœ…โœ…โš ๏ธ CLI required
Managed Databaseโœ… Built-inโŒ External neededโœ… Built-in
Free Tier/Credit$5/mo credit100GB3 shared VMs
Auto Scalingโœ… Proโœ…โœ…
Private Networkโœ…โš ๏ธ Limitedโœ