earchibald avatar

railway-service-management

Specialized knowledge for managing multi-environment Railway deployments, including development bran

提供方 earchibald|开源

Contents

Quick Start for Cloud Agents

Railway CLI is automatically configured for Cloud Agents (GitHub Copilot Workspace).

  • Installs Railway CLI via npm
  • Authenticates using RAILWAY_API_TOKEN
  • Auto-detects and links to the correct environment (PR or production)
  • Links to project: yoto, service: yoto-smart-stream

You can immediately use Railway CLI commands:

railway status --json
railway logs --lines 50 --filter "@level:error" --json
railway var list --json
railway deployment list --json

For detailed instructions: See Cloud Agent Authentication

Quick Start

Monitoring Deployment Status Loop

 sleep 5 && while true; do STATUS=$(railway deployment list --json | jq -r '.[0].status'); echo "[$(date '+%H:%M:%S')] Deployment status: $STATUS"; if [ "$STATUS" = "SUCCESS" ]; then echo "✅ Deployment succeeded!"; break; elif [ "$STATUS" = "FAILURE" ]; then echo "❌ Deployment failed!"; exit 1; fi; sleep 5; done

Common CLI Commands

# Check deployment status
railway status --json

# View filtered logs (prefer filtering for efficiency)
railway logs --filter "@level:error"
railway logs --filter "\"uvicorn\" OR \"startup\""

# Link workspace to environment
railway link --project <project_id>
railway environment --environment develop

For complete CLI reference: See cli_scripts.md

Essential Workflows

1. Deployment Configuration

Railpack (preferred build system):

{
  "$schema": "https://schema.railpack.com",
  "provider": "python",
  "packages": {"python": "3.11"},
  "deploy": {"startCommand": "uvicorn app:main --host 0.0.0.0 --port $PORT"}
}

Key principle: Prefer auto-detection over custom steps. Only configure what needs to differ from defaults.

For detailed build configuration: See configuration_management.md

2. Multi-Environment Setup

Typical structure:

  • Production (main branch) - Customer-facing
  • Staging (develop branch) - Pre-production testing
  • PR Environments - Automatic ephemeral environments per PR

For complete multi-environment architecture: See multi_environment_architecture.md

3. Troubleshooting Deployments

Common issues:

  • Health check failures → Check railway logs --filter "@level:error"
  • Package not found → Verify build succeeded, check layering (see configuration_management.md)
  • Environment deleted → Re-link with railway link and railway environment

For deployment workflows and CI/CD: See deployment_workflows.md

Reference Documentation

Load these files as needed for detailed guidance:

Critical Guidelines

  1. Always filter logs when using Railway CLI for efficiency
  2. Prefer auto-detection for build configuration (Railpack)
  3. Verify environment link before CLI operations: railway status --json
  4. Check health checks are properly configured for all services
railway-service-management - 适用于 Claude Code 与 Cursor 的 AI 智能体 Skill | Agent Skills