Get the FREE Ultimate OpenClaw Setup Guide →

railway

Scanned
npx machina-cli add skill Makiya1202/ai-agents-skills/railway --openclaw
Files (1)
SKILL.md
3.1 KB

Railway Deployment

Deploy and manage applications on Railway's platform.

Quick Start

# Install Railway CLI
npm i -g @railway/cli

# Login
railway login

# Initialize project
railway init

# Deploy
railway up

railway.toml Configuration

[build]
builder = "nixpacks"
buildCommand = "npm run build"

[deploy]
startCommand = "npm start"
healthcheckPath = "/health"
healthcheckTimeout = 300
restartPolicyType = "on_failure"
restartPolicyMaxRetries = 3

[service]
internalPort = 3000

Nixpacks Configuration

# nixpacks.toml
[phases.setup]
nixPkgs = ["nodejs-18_x", "python311"]

[phases.install]
cmds = ["npm ci"]

[phases.build]
cmds = ["npm run build"]

[start]
cmd = "npm start"

Environment Variables

# Set variable
railway variables set DATABASE_URL="postgres://..."

# Set from file
railway variables set < .env

# Link to service
railway service
railway variables set API_KEY="secret"

Database Services

PostgreSQL

# Add PostgreSQL
railway add -d postgres

# Get connection string
railway variables get DATABASE_URL

Redis

railway add -d redis
# Access via REDIS_URL

MySQL

railway add -d mysql
# Access via MYSQL_URL

Private Networking

# Services can communicate via internal DNS
# Format: ${{service-name}}.railway.internal

# Example: API calling database service
DATABASE_HOST: ${{postgres.railway.internal}}
DATABASE_PORT: 5432

Volumes (Persistent Storage)

# Create volume
railway volume create my-data

# Mount in service
railway volume attach my-data:/app/data

In code:

// Data persists across deploys
const dataPath = '/app/data';
fs.writeFileSync(`${dataPath}/file.json`, JSON.stringify(data));

Cron Jobs

# railway.toml
[deploy]
startCommand = "node cron.js"
cronSchedule = "0 */6 * * *"  # Every 6 hours

Multi-Service Setup

my-project/
├── api/
│   ├── railway.toml
│   └── ...
├── worker/
│   ├── railway.toml
│   └── ...
└── frontend/
    ├── railway.toml
    └── ...

Deploy each:

cd api && railway up
cd ../worker && railway up
cd ../frontend && railway up

Dockerfile Deploy

FROM node:18-alpine

WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .

EXPOSE 3000
CMD ["npm", "start"]
# railway.toml
[build]
builder = "dockerfile"
dockerfilePath = "./Dockerfile"

Health Checks

// Express health endpoint
app.get('/health', (req, res) => {
  res.status(200).json({ 
    status: 'healthy',
    timestamp: new Date().toISOString()
  });
});
# railway.toml
[deploy]
healthcheckPath = "/health"
healthcheckTimeout = 100

Resources

Source

git clone https://github.com/Makiya1202/ai-agents-skills/blob/master/skills/railway/SKILL.mdView on GitHub

Overview

Railway deployment lets you deploy containerized apps and manage related services on Railway. It supports adding databases (PostgreSQL, Redis, MySQL), setting up private networking, persistent volumes, and multi-service projects. Deploys are driven by the Railway CLI (railway init, railway up) and configuration files like railway.toml or Dockerfile.

How This Skill Works

Install the Railway CLI, log in, and run railway init to scaffold your project, then deploy with railway up. Railway uses nixpacks or a Dockerfile to build and run your app, exposing the internal port and applying health checks and restart policies. You can add databases, manage environment variables with railway variables, and enable private networking so services communicate via internal DNS like ${service}.railway.internal.

When to Use It

  • Deploy a containerized app on Railway
  • Provision PostgreSQL, Redis, or MySQL and connect them via connection strings
  • Configure private networking for inter-service calls
  • Manage a multi-service project with per-service railway.toml files
  • Schedule cron jobs and implement health checks for deployments

Quick Start

  1. Step 1: Install the Railway CLI (npm i -g @railway/cli)
  2. Step 2: Login and initialize (railway login; railway init)
  3. Step 3: Deploy (railway up)

Best Practices

  • Use per-service railway.toml to explicitly define build and deploy settings
  • Manage secrets with railway variables instead of hard-coding
  • Leverage internal DNS (e.g., ${{service}}.railway.internal) for service calls
  • Attach persistent volumes for data storage and mount them to services
  • Choose nixpacks or Dockerfile builders and define clear health checks

Example Use Cases

  • Deploy a Node.js API with nixpacks and PostgreSQL backing database
  • Add Redis for caching and access via REDIS_URL
  • Deploy api, worker, and frontend as separate services in a single project
  • Create a persistent volume and mount it at /data for logs or app data
  • Configure a cron job in railway.toml to run every 6 hours using cronSchedule

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers