Skip to main content

Railway Deployer

Infrastructure engineer specializing in Railway platform deployments and service configuration.

Quick Reference

PropertyValue
DomainDevOps
FORGE Stage4 (DEPLOY)
Version1.0.0
Output Typesrailway.json, deployment configs

Overview

Use this agent when you need to:
  • Deploy Hono APIs or Next.js apps to Railway
  • Configure environment variables and secrets
  • Set up PostgreSQL or Redis plugins
  • Configure domains, SSL, and health checks
  • Manage multi-environment deployments (staging, production)
The Railway Deployer automates the creation of Railway service configurations, handles environment variable management, and ensures deployments are healthy and production-ready.

Core Capabilities

Service Configuration

Define Railway services with proper resource allocation, build commands, and replica counts

Environment Management

Configure variables per environment with secret references and plugin linkage

Network Setup

Configure custom domains, internal networking, SSL certificates, and health checks

Database Provisioning

Set up PostgreSQL, Redis, and other Railway plugins with optimal configurations

When to Use

Deploying SO1 Control Plane API (Hono backend)
Deploying SO1 Console (Next.js frontend)
Setting up staging and production environments
Configuring PostgreSQL or Redis for an application
Setting up health check endpoints
Managing Railway environment variables
Not suitable for:
  • Non-Railway platforms (AWS, GCP, Azure)
  • Manual Railway console configuration
  • Non-containerized applications

Usage Examples

Deploy the SO1 Control Plane API with PostgreSQL and Redis:
{
  "railwayConfig": {
    "generatedBy": "railway-deployer",
    "version": "1.0.0",
    "project": {
      "name": "so1-control-plane",
      "description": "SO1 Control Plane API - Hono backend"
    },
    "environments": {
      "production": {
        "services": [{
          "name": "api",
          "source": {
            "repo": "so1-io/so1-control-plane-api",
            "branch": "main"
          },
          "build": {
            "builder": "NIXPACKS",
            "buildCommand": "pnpm install --frozen-lockfile && pnpm build"
          },
          "deploy": {
            "startCommand": "pnpm start",
            "healthcheckPath": "/health",
            "numReplicas": 2
          },
          "networking": {
            "publicDomain": "api.so1.io",
            "internalPort": 3000
          }
        }],
        "plugins": [
          {
            "type": "postgresql",
            "name": "so1-db",
            "config": { "version": "15" }
          },
          {
            "type": "redis",
            "name": "so1-cache",
            "config": { "version": "7" }
          }
        ],
        "variables": {
          "NODE_ENV": "production",
          "DATABASE_URL": "${{Postgres.DATABASE_URL}}",
          "REDIS_URL": "${{Redis.REDIS_URL}}"
        }
      }
    }
  }
}
Result: Complete Railway configuration for production API deployment with database, caching, and health checks.

Outputs

Railway Configuration File

// railway.json
{
  "$schema": "https://railway.app/railway.schema.json",
  "build": {
    "builder": "NIXPACKS",
    "buildCommand": "pnpm install --frozen-lockfile && pnpm build",
    "watchPatterns": ["src/**", "package.json"]
  },
  "deploy": {
    "numReplicas": 1,
    "startCommand": "pnpm start",
    "healthcheckPath": "/health",
    "healthcheckTimeout": 30,
    "restartPolicyType": "ON_FAILURE",
    "restartPolicyMaxRetries": 3
  }
}

Health Check Implementation

// src/routes/health.ts (Hono)
import { Hono } from 'hono';
import { db } from '../db';

const app = new Hono()
  .get('/health', async (c) => {
    const checks = {
      status: 'healthy',
      timestamp: new Date().toISOString(),
      checks: {
        database: 'unknown',
        redis: 'unknown',
      },
    };

    try {
      await db.execute('SELECT 1');
      checks.checks.database = 'healthy';
    } catch {
      checks.checks.database = 'unhealthy';
      checks.status = 'degraded';
    }

    return c.json(checks, checks.status === 'healthy' ? 200 : 503);
  });

export default app;

Resource Sizing Guide

Application TypeMemoryCPUReplicas
API (light)256MB0.251
API (standard)512MB0.52
API (heavy)1GB+1+2+
Next.js SSR512MB-1GB0.5-12
Static site256MB0.251
Worker/Cron256MB0.251

FORGE Gate Compliance

Entry Gates (Pre-conditions)

The application must have successfully passed all CI pipeline tests, linting, and build steps before deployment configuration begins.
All required environment variables must be listed in .env.example with descriptions of their purpose and where to obtain values.
Either the Railway project already exists in the Railway dashboard, or there is explicit approval to create a new project.

Exit Gates (Post-conditions)

The railway.json file is created with proper build commands, deploy settings, and resource allocation.
All environment variables are set in Railway dashboard with proper references to plugins and shared secrets.
The /health endpoint returns 200 OK and validates database/Redis connectivity.
The deployment completes without errors, health checks pass, and the service is accessible via its public domain.

Integration Points

Control Plane API

// Track deployment status
POST /api/v1/deployments
{
  "service": "so1-control-plane-api",
  "environment": "production",
  "status": "success",
  "healthCheckUrl": "https://api.so1.io/health",
  "deployedAt": "2024-01-15T10:30:00Z"
}

// Retrieve deployment history
GET /api/v1/deployments?service=so1-control-plane-api

Veritas Prompts

Prompt IDPurpose
vrt-g7h8i9j0Railway deployment best practices (service config, scaling, networking)
vrt-k1l2m3n4Container optimization guidelines (build optimization, image size, startup time)
AgentRelationshipUse Case
GitHub Actions EngineerUpstreamTriggers deployment after CI passes
Pipeline AuditorDownstreamReviews deployment config for security issues
Incident CommanderAlertsReceives alerts on deployment failures
Hono BackendCreatesBuilds the APIs that Railway Deployer deploys

Source Files

View Agent Source

Repository: so1-io/so1-agents
Path: agents/devops/railway-deployer.md
Version: 1.0.0

Common Patterns

Variable Reference Syntax

{
  "variables": {
    // Plugin variables
    "DATABASE_URL": "${{Postgres.DATABASE_URL}}",
    "REDIS_URL": "${{Redis.REDIS_URL}}",
    
    // Shared secrets
    "API_KEY": "${{shared.API_KEY}}",
    
    // Service URLs
    "OTHER_SERVICE_URL": "${{other-service.RAILWAY_PUBLIC_DOMAIN}}"
  }
}

Rollback Procedure

# Railway CLI rollback
railway rollback --service api --to <deployment-id>

# Or via API
curl -X POST "https://backboard.railway.app/graphql/v2" \
  -H "Authorization: Bearer $RAILWAY_TOKEN" \
  -d '{"query": "mutation { deploymentRollback(id: \"<deployment-id>\") { id } }"}'

Common Deployment Errors

ErrorCauseResolution
Build failedMissing dependencies or build errorCheck build logs, verify package.json
Health check timeoutApp not starting in timeIncrease timeout, check startup logs
OOM killedMemory limit exceededIncrease memory allocation
Deploy stuckHealth check never passesVerify health endpoint returns 200
Variable missingSecret not configuredAdd missing variables in Railway dashboard

Next Steps: