jpskill.com
🛠️ 開発・MCP コミュニティ

railway-automation

RailwayのCI/CD統合や自動デプロイ、データベース移行スクリプト実行などを、GitHub ActionsやGitLab CIを使って効率化し、Railwayのワークフローを自動化するSkill。

📜 元の英語説明(参考)

Railway CI/CD integration and automation. Use when setting up GitHub Actions, GitLab CI, automated deployments, migration scripts, or programmatic Railway workflows.

🇯🇵 日本人クリエイター向け解説

一言でいうと

RailwayのCI/CD統合や自動デプロイ、データベース移行スクリプト実行などを、GitHub ActionsやGitLab CIを使って効率化し、Railwayのワークフローを自動化するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o railway-automation.zip https://jpskill.com/download/9472.zip && unzip -o railway-automation.zip && rm railway-automation.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9472.zip -OutFile "$d\railway-automation.zip"; Expand-Archive "$d\railway-automation.zip" -DestinationPath $d -Force; ri "$d\railway-automation.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して railway-automation.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → railway-automation フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Railway CI/CD 自動化

CI/CD パイプライン、マイグレーションスクリプト、およびイベント駆動型ワークフローを使用して、Railway のデプロイメントを自動化します。

クイックスタート

GitHub Actions (5 分)

# .github/workflows/railway.yml
- uses: railway/deploy@v1
  with:
    railway_token: ${{ secrets.RAILWAY_TOKEN }}
    service: api

GitLab CI (5 分)

# .gitlab-ci.yml
deploy:
  script:
    - railway up --service api
  only: [main]

マイグレーション (10 分)

./scripts/migrate.sh --from heroku --project myapp

ワークフロー概要

1. GitHub Actions 連携

セットアップ手順

  1. Railway トークンを生成します (railway login && railway token)
  2. GitHub シークレットにトークンを追加します (RAILWAY_TOKEN)
  3. ワークフローファイルを作成します (.github/workflows/railway.yml)
  4. デプロイメントトリガーを設定します
  5. PR または push でテストします

ユースケース

  • main/staging への push でデプロイ
  • PR プレビュー環境
  • マルチ環境プロモーション
  • スケジュールされたデプロイメント
  • 手動承認ゲート

テンプレート: templates/github-workflow.yml を参照してください

リファレンス: 5 つ以上のワークフロー例を含む完全なガイドについては、references/github-actions.md を参照してください


2. GitLab CI 連携

セットアップ手順

  1. Railway トークンを生成します
  2. GitLab CI/CD 変数に追加します (RAILWAY_TOKEN)
  3. .gitlab-ci.yml を作成します
  4. ステージを定義します (test → staging → production)
  5. 手動ゲートを設定します

ユースケース

  • マルチステージパイプライン
  • 環境固有のデプロイメント
  • マージリクエストのレビューアプリ
  • 並列サービスデプロイメント
  • アーティファクトベースのデプロイメント

テンプレート: templates/gitlab-ci.yml を参照してください

リファレンス: パイプラインの例を含む完全なガイドについては、references/gitlab-ci.md を参照してください


3. カスタム CI/CD 連携

一般的なパターン (任意のプラットフォーム)

# Railway CLI をインストール
npm i -g @railway/cli

# トークンでログイン
export RAILWAY_TOKEN=$YOUR_TOKEN

# プロジェクトをリンク
railway link $PROJECT_ID

# デプロイ
railway up --service $SERVICE_NAME --environment $ENVIRONMENT

環境変数

  • RAILWAY_TOKEN: 認証トークン
  • RAILWAY_PROJECT_ID: プロジェクト識別子 (リンクされている場合はオプション)
  • RAILWAY_SERVICE: サービス名 (オプション)
  • RAILWAY_ENVIRONMENT: 環境名 (オプション)

ヘルスチェックパターン

# デプロイしてヘルスチェックを待機
railway up --service api
sleep 30

# デプロイメントを検証
DEPLOY_URL=$(railway status --json | jq -r '.url')
curl -f $DEPLOY_URL/health || exit 1

サポートされているプラットフォーム

  • CircleCI
  • Travis CI
  • Jenkins
  • Bitbucket Pipelines
  • Azure DevOps
  • シェルアクセスが可能な任意のプラットフォーム

4. マイグレーション自動化

インタラクティブなマイグレーションスクリプト

# Heroku から
./scripts/migrate.sh --from heroku --project myapp

# Vercel から
./scripts/migrate.sh --from vercel --project myapp --env production

# ドライラン (変更のプレビュー)
./scripts/migrate.sh --from render --project myapp --dry-run

スクリプトの機能

  • プラットフォームの検出
  • 環境変数のエクスポート/インポート
  • Railway プロジェクトの作成
  • サービス構成
  • データベースのマイグレーション
  • DNS 切り替え計画
  • 検証チェック

サポートされているマイグレーション

  • Heroku → Railway
  • Vercel → Railway
  • Render → Railway
  • Docker Compose → Railway
  • Kubernetes → Railway

リファレンス: プラットフォームごとの詳細なガイドについては、references/migration-patterns.md を参照してください


5. スケジュールされたタスク

Cron ベースのデプロイメント

# GitHub Actions - 毎晩午前 2 時にデプロイ
on:
  schedule:
    - cron: '0 2 * * *'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}

データベースのバックアップ

# スケジュールされたバックアップワークフロー
on:
  schedule:
    - cron: '0 0 * * *'  # 毎日午前 0 時

jobs:
  backup:
    steps:
      - name: データベースのバックアップ
        run: |
          railway run pg_dump > backup.sql
          aws s3 cp backup.sql s3://backups/$(date +%Y%m%d).sql

ヘルスチェックの監視

# 毎時ヘルスチェック
on:
  schedule:
    - cron: '0 * * * *'

jobs:
  health:
    steps:
      - name: サービスヘルスチェック
        run: |
          curl -f ${{ secrets.SERVICE_URL }}/health || \
          curl -X POST ${{ secrets.SLACK_WEBHOOK }} \
            -d '{"text":"Service down!"}'

6. Webhook 連携

GitHub Webhook → Railway デプロイ

// Webhook ハンドラー
app.post('/webhook/github', async (req, res) => {
  const { ref, repository } = req.body;

  if (ref === 'refs/heads/main') {
    const { exec } = require('child_process');
    exec('railway up --service api', (error, stdout) => {
      console.log(stdout);
    });
  }

  res.json({ status: 'ok' });
});

Railway Webhook イベント Railway は、以下の Webhook をサポートしています。

  • デプロイメント開始
  • デプロイメント完了
  • デプロイメント失敗
  • サービスクラッシュ
  • ビルドログ

Webhook の設定

# Railway CLI 経由
railway webhooks add \
  --url https://yourapp.com/webhook \
  --events deployment.success,deployment.failure

# API 経由
curl -X POST https://backboard.railway.app/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "query": "mutation { webhookCreate(input: {...}) }"
  }'

通知連携

# デプロイ時の Slack 通知
railway webhooks add \
  --url $SLACK_WEBHOOK_URL \
  --events deployment.success \
  --transform '{
    "text": "Deployed {{service}} to {{environment}}"
  }'

一般的なパターン

マルチ環境デプロイメント

# まず staging にデプロイし、次に production にデプロイ
jobs:
  staging:
    environment: staging
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}
          environment: staging

  production:
    needs: staging
    environment: production
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}
          environment: production

PR プレビュー環境


# 各 PR に対してプレビューを作成
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  preview:
    steps:
      - uses: railwa
(原文がここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Railway CI/CD Automation

Automate Railway deployments with CI/CD pipelines, migration scripts, and event-driven workflows.

Quick Start

GitHub Actions (5 minutes)

# .github/workflows/railway.yml
- uses: railway/deploy@v1
  with:
    railway_token: ${{ secrets.RAILWAY_TOKEN }}
    service: api

GitLab CI (5 minutes)

# .gitlab-ci.yml
deploy:
  script:
    - railway up --service api
  only: [main]

Migration (10 minutes)

./scripts/migrate.sh --from heroku --project myapp

Workflow Overview

1. GitHub Actions Integration

Setup Process

  1. Generate Railway token (railway login && railway token)
  2. Add token to GitHub secrets (RAILWAY_TOKEN)
  3. Create workflow file (.github/workflows/railway.yml)
  4. Configure deployment triggers
  5. Test with PR or push

Use Cases

  • Deploy on push to main/staging
  • PR preview environments
  • Multi-environment promotion
  • Scheduled deployments
  • Manual approval gates

Template: See templates/github-workflow.yml

Reference: references/github-actions.md for complete guide with 5+ workflow examples


2. GitLab CI Integration

Setup Process

  1. Generate Railway token
  2. Add to GitLab CI/CD variables (RAILWAY_TOKEN)
  3. Create .gitlab-ci.yml
  4. Define stages (test → staging → production)
  5. Configure manual gates

Use Cases

  • Multi-stage pipelines
  • Environment-specific deployments
  • Review apps for merge requests
  • Parallel service deployments
  • Artifact-based deployments

Template: See templates/gitlab-ci.yml

Reference: references/gitlab-ci.md for complete guide with pipeline examples


3. Custom CI/CD Integration

Generic Pattern (Any Platform)

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

# Login with token
export RAILWAY_TOKEN=$YOUR_TOKEN

# Link project
railway link $PROJECT_ID

# Deploy
railway up --service $SERVICE_NAME --environment $ENVIRONMENT

Environment Variables

  • RAILWAY_TOKEN: Authentication token
  • RAILWAY_PROJECT_ID: Project identifier (optional if linked)
  • RAILWAY_SERVICE: Service name (optional)
  • RAILWAY_ENVIRONMENT: Environment name (optional)

Health Check Pattern

# Deploy and wait for health
railway up --service api
sleep 30

# Verify deployment
DEPLOY_URL=$(railway status --json | jq -r '.url')
curl -f $DEPLOY_URL/health || exit 1

Supported Platforms

  • CircleCI
  • Travis CI
  • Jenkins
  • Bitbucket Pipelines
  • Azure DevOps
  • Any platform with shell access

4. Migration Automation

Interactive Migration Script

# From Heroku
./scripts/migrate.sh --from heroku --project myapp

# From Vercel
./scripts/migrate.sh --from vercel --project myapp --env production

# Dry run (preview changes)
./scripts/migrate.sh --from render --project myapp --dry-run

Script Features

  • Platform detection
  • Environment variable export/import
  • Railway project creation
  • Service configuration
  • Database migration
  • DNS cutover planning
  • Verification checks

Supported Migrations

  • Heroku → Railway
  • Vercel → Railway
  • Render → Railway
  • Docker Compose → Railway
  • Kubernetes → Railway

Reference: references/migration-patterns.md for detailed guides per platform


5. Scheduled Tasks

Cron-Based Deployments

# GitHub Actions - Deploy every night at 2 AM
on:
  schedule:
    - cron: '0 2 * * *'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}

Database Backups

# Scheduled backup workflow
on:
  schedule:
    - cron: '0 0 * * *'  # Daily at midnight

jobs:
  backup:
    steps:
      - name: Backup database
        run: |
          railway run pg_dump > backup.sql
          aws s3 cp backup.sql s3://backups/$(date +%Y%m%d).sql

Health Check Monitoring

# Hourly health checks
on:
  schedule:
    - cron: '0 * * * *'

jobs:
  health:
    steps:
      - name: Check service health
        run: |
          curl -f ${{ secrets.SERVICE_URL }}/health || \
          curl -X POST ${{ secrets.SLACK_WEBHOOK }} \
            -d '{"text":"Service down!"}'

6. Webhook Integration

GitHub Webhook → Railway Deploy

// Webhook handler
app.post('/webhook/github', async (req, res) => {
  const { ref, repository } = req.body;

  if (ref === 'refs/heads/main') {
    const { exec } = require('child_process');
    exec('railway up --service api', (error, stdout) => {
      console.log(stdout);
    });
  }

  res.json({ status: 'ok' });
});

Railway Webhook Events Railway supports webhooks for:

  • Deployment started
  • Deployment completed
  • Deployment failed
  • Service crashed
  • Build logs

Configure Webhooks

# Via Railway CLI
railway webhooks add \
  --url https://yourapp.com/webhook \
  --events deployment.success,deployment.failure

# Via API
curl -X POST https://backboard.railway.app/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
    "query": "mutation { webhookCreate(input: {...}) }"
  }'

Notification Integration

# Slack notification on deploy
railway webhooks add \
  --url $SLACK_WEBHOOK_URL \
  --events deployment.success \
  --transform '{
    "text": "Deployed {{service}} to {{environment}}"
  }'

Common Patterns

Multi-Environment Deployment

# Deploy to staging first, then production
jobs:
  staging:
    environment: staging
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}
          environment: staging

  production:
    needs: staging
    environment: production
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}
          environment: production

PR Preview Environments

# Create preview for each PR
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  preview:
    steps:
      - uses: railway/deploy@v1
        with:
          railway_token: ${{ secrets.RAILWAY_TOKEN }}
          service: api-pr-${{ github.event.pull_request.number }}

Rollback on Failure

# Automatic rollback if health check fails
jobs:
  deploy:
    steps:
      - name: Deploy
        id: deploy
        run: railway up --service api

      - name: Health check
        run: curl -f $SERVICE_URL/health

      - name: Rollback on failure
        if: failure()
        run: railway rollback --service api

Matrix Deployments

# Deploy multiple services in parallel
strategy:
  matrix:
    service: [api, worker, cron]

steps:
  - uses: railway/deploy@v1
    with:
      railway_token: ${{ secrets.RAILWAY_TOKEN }}
      service: ${{ matrix.service }}

Token Management

Generate Token

# CLI method
railway login
railway token

# Copy token to clipboard
railway token | pbcopy  # macOS
railway token | xclip   # Linux

Add to CI Platform

GitHub

Settings → Secrets and variables → Actions → New repository secret
Name: RAILWAY_TOKEN
Value: [paste token]

GitLab

Settings → CI/CD → Variables → Add variable
Key: RAILWAY_TOKEN
Value: [paste token]
Protected: Yes
Masked: Yes

CircleCI

Project Settings → Environment Variables → Add Variable
Name: RAILWAY_TOKEN
Value: [paste token]

Token Rotation

# Generate new token
NEW_TOKEN=$(railway token)

# Update in CI (platform-specific)
# Then invalidate old token via dashboard

Environment-Specific Configuration

Detect Environment in Code

const env = process.env.RAILWAY_ENVIRONMENT || 'development';

const config = {
  development: { db: 'localhost:5432' },
  staging: { db: process.env.DATABASE_URL },
  production: { db: process.env.DATABASE_URL }
};

export default config[env];

Conditional Deployment

# Only deploy staging on feature branches
jobs:
  deploy-staging:
    if: github.ref != 'refs/heads/main'
    steps:
      - uses: railway/deploy@v1
        with:
          environment: staging

  deploy-production:
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: railway/deploy@v1
        with:
          environment: production

Environment Variable Management

# Export from staging
railway env --environment staging > .env.staging

# Import to production (selective)
cat .env.staging | grep -v SECRET | railway env --environment production

Best Practices

Security

  • Use masked/protected CI variables
  • Rotate tokens quarterly
  • Use service tokens (not personal) for production
  • Never commit tokens to git
  • Limit token scope to specific projects

Performance

  • Cache dependencies in CI
  • Use Railway's built-in caching
  • Deploy only changed services
  • Run tests before deploy
  • Use health checks before traffic

Reliability

  • Always include rollback mechanism
  • Monitor deployment notifications
  • Set deployment timeouts
  • Use staging before production
  • Test migrations in preview environments

Monitoring

  • Log all deployments
  • Track deployment duration
  • Alert on failures
  • Monitor health checks
  • Track rollback frequency

Troubleshooting

Deployment Fails in CI

# Check token validity
railway whoami

# Verify project link
railway status

# Check service exists
railway list

# View deployment logs
railway logs --service api

Token Authentication Errors

# Regenerate token
railway logout
railway login
railway token

# Update in CI secrets
# Test locally first
RAILWAY_TOKEN=$NEW_TOKEN railway status

Environment Not Found

# List available environments
railway environment list

# Verify environment name matches
railway status --environment production

Service Not Deploying

# Check service name
railway list

# Verify service configuration
railway status --service api

# Check for build errors
railway logs --service api --deployment latest

Related Skills

  • railway-auth: Token management and authentication setup
  • railway-api: Programmatic Railway API automation
  • railway-deployment: Deployment patterns and strategies
  • railway-database: Database automation and backups
  • railway-monitoring: Health checks and alerting

References

  • references/github-actions.md: Complete GitHub Actions guide with 5+ workflow examples
  • references/gitlab-ci.md: Complete GitLab CI guide with pipeline examples
  • references/migration-patterns.md: Platform migration guides (Heroku, Vercel, Render, etc.)

Templates

  • templates/github-workflow.yml: Production-ready GitHub Actions template
  • templates/gitlab-ci.yml: Production-ready GitLab CI template

Scripts

  • scripts/migrate.sh: Interactive migration script supporting multiple platforms