Index of every page on this site: llms.txt
All skills
Run it yourself

Define and manage Railway projects with Infrastructure as Code in .railway/railway.ts. Use when authoring or editing Railway IaC files, running railway config init/pull/plan/apply, declaring services, databases, volumes, buckets, domains, or env vars in code, setting up multi-repo partials, or wiring railway config into CI. Triggers on "railway iac", "railway.ts", "infrastructure as code railway", "railway config plan", "define railway services in code". For migrating railway.json/railway.toml, use the railway-iac-migration skill instead.

Use this Skill: https://skilld.dev/gh/sivarampg/railway-iac-skill/railway-iac

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesdsl-reference.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Railway IaC TypeScript DSL Reference

All helpers import from railway/iac. A file exports defineRailway and returns one project.

import {
  bucket,
  defineRailway,
  github,
  group,
  image,
  postgres,
  preserve,
  project,
  redis,
  service,
  volume,
} from "railway/iac";

export default defineRailway((ctx) => {
  /* ...resources... */
  return project("my-project", { resources: [/* ... */] });
});

Environment context (ctx)

defineRailway receives a context object. Use it to render different desired state per Railway environment.

Field Description
ctx.command plan, apply, etc.
ctx.projectId Linked project ID
ctx.projectName Linked project name
ctx.environmentId Target environment ID
ctx.environment Target environment name
ctx.environmentName Alias for ctx.environment
ctx.isEnvironment(name) Boolean name check
ctx.shared.NAME Reference to an existing shared variable on the environment (compiles to ${{shared.NAME}}; does not create it)
const prod = ctx.isEnvironment("production");

Services

const web = service("web", {
  source: github("acme/web"),            // or image(...), see Sources
  build: "pnpm build",                   // build command
  start: "pnpm start",                   // start command
  healthcheck: "/health",                // healthcheck path
  healthcheckTimeout: 30,                // seconds
  preDeploy: "npx drizzle-kit migrate",  // runs between build and deploy
  replicas: 3,                           // number, or per-region map
  domains: ["app.example.com"],          // strings or { domain, port }
  env: { NODE_ENV: "production" },       // variables, see below
  volumeMounts: { "/data": dataVol },    // mount path -> volume(...) resource
});
  • Service names should match what users see in Railway; spaces are valid (service("Docs Frontend", {...})).
  • Omit source to manage service settings without declaring a repo/image.
  • preDeploy: "..." is equivalent to deploy: { preDeployCommand: ["..."] } (the form config pull renders).
  • Per-region replicas: replicas: { "us-west2": 2, "europe-west4": 1 }.

Sources

source: github("owner/repo")                                // GitHub, default branch
source: github("owner/repo", { branch: "main" })
source: github("acme/monorepo", { rootDirectory: "apps/api" })
source: image("ghcr.io/acme/worker:latest")                 // Docker image
source: image("ghcr.io/acme/worker:1.2.3", {
  autoUpdates: { type: "patch" },                           // disabled | patch | minor
})

autoUpdates works only for Docker Hub and GHCR images, not GitHub sources or other registries.

Environment variables

env: {
  NODE_ENV: "production",              // literal
  DATABASE_URL: db.env.DATABASE_URL,   // reference another resource's variable
  SENTRY_DSN: ctx.shared.SENTRY_DSN,   // existing shared variable on the environment
  STRIPE_SECRET_KEY: preserve(),       // keep whatever value Railway already has
  API_HOST: api.env.RAILWAY_PRIVATE_DOMAIN,
}

preserve() means "keep the value already set in Railway"; it is used for imported secrets the CLI can't read. Never paste secret literals into the file.

Tracing (not yet supported by SDKs)

The tracing: { enabled, autoInstrumentation } block exists in the compiled config but service() in TS/Python/Go drops it before the CLI sees it. Consequence: plan proposes to remove tracing from traced services. Until SDK support lands, manage tracing from the Traces page or railway trace, and do not apply a plan that removes a tracing block you didn't remove.

Databases

const db = postgres("postgres");
const cache = redis("redis");
const mysqlDb = mysql("mysql");
const mongoDb = mongo("mongo");

Reference their variables from services: db.env.DATABASE_URL, cache.env.REDIS_URL. Provisioning is a Railway product workflow; don't attach volumes to managed database helpers yourself.

Volumes

const data = volume("backend-data", {
  region: "us-west2",
  sizeMB: 1024,
});

const backend = service("backend", {
  volumeMounts: { "/data": data },   // key = mount path in the container
});
  • One volume attaches to one service.
  • Increasing sizeMB is a non-destructive resize. Decreasing, deleting, detaching a mounted volume, or changing placement is destructive.
  • config pull may import managed-database volumes so Railway can preserve them; the postgres() helper still owns the database intent.

Buckets

const media = bucket("media", { region: "iad" });

Region is immutable after creation. To move regions: new bucket, copy data, repoint services, delete old bucket.

Custom domains

domains: ["app.example.com"]
domains: [{ domain: "api.example.com", port: 3000 }]

Generated *.up.railway.app domains are never imported or managed.

Groups

Canvas organization only: structural, no runtime effect.

const backend = group("Backend", [api, worker, db]);
return project("my-app", { resources: [backend, web] });

Partials (multi-repo)

Each repository manages its own slice of a shared environment:

export const partial = "api";   // Python: PARTIAL = "api"; Go: const Partial = "api"
  • Name: 1-64 chars from a-z A-Z 0-9 . _ -.
  • Once any partial in an environment has a name, every file targeting that environment must export one.
  • First apply claims ownership of everything the file declares (apply runs even with a no-change plan, to record the claim).
  • A partial deletes only resources it owns.
  • Renaming the export does not transfer ownership. Use railway config partials transfer.
  • Whole-environment planning requires all named ownership released (partials release).

Complete example

export default defineRailway((ctx) => {
  const prod = ctx.environment === "production";

  const db = postgres("postgres");
  const cache = redis("redis");
  const uploads = bucket("uploads", { region: "iad" });
  const workerData = volume("worker-data", { region: "us-west2", sizeMB: 1024 });

  const api = service("api", {
    source: github("acme/monorepo", { rootDirectory: "apps/api" }),
    build: "pnpm --filter api build",
    start: "pnpm --filter api start",
    healthcheck: "/health",
    replicas: prod ? { "us-west2": 2, "europe-west4": 1 } : 1,
    env: {
      DATABASE_URL: db.env.DATABASE_URL,
      REDIS_URL: cache.env.REDIS_URL,
      JWT_SECRET: preserve(),
    },
  });

  const web = service("web", {
    source: github("acme/monorepo", { rootDirectory: "apps/web" }),
    build: "pnpm --filter web build",
    start: "pnpm --filter web start",
    domains: prod ? ["app.example.com"] : [],
    env: { API_HOST: api.env.RAILWAY_PRIVATE_DOMAIN },
  });

  const worker = service("worker", {
    source: github("acme/monorepo", { rootDirectory: "apps/worker" }),
    build: "pnpm --filter worker build",
    start: "pnpm --filter worker start",
    volumeMounts: { "/data": workerData },
    env: { DATABASE_URL: db.env.DATABASE_URL, REDIS_URL: cache.env.REDIS_URL },
  });

  const backend = group("Backend", [db, cache, api, worker]);
  const storage = group("Storage", [uploads, workerData]);

  return project("acme", { resources: [backend, storage, web] });
});

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    The skill provides a secure and well-documented set of instructions for managing Railway Infrastructure as Code. It leverages official SDKs and GitHub Actions from the Railway organization and emphasizes security best practices, such as using the preserve() function to manage secrets and warning users about destructive operations and sensitive data exposure during configuration imports.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at ba3f473. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 2 months ago
metadata
{
  "version": "1.0.0"
}

README badge

README badge for sivarampg/railway-iac-skill/railway-iac