deploy-railway
暂无简介
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 490
03 SKILL.md 正文
Railway 部署
适用场景
- 后端 API 服务:Node.js、Python、Go、Java、Ruby、PHP、Rust
- 全栈应用:后端 + 托管数据库
- Docker 化应用:通过 Dockerfile 部署
- 需要托管数据库:PostgreSQL、MySQL、Redis、MongoDB
- 多服务项目:一个 project 下管理多个服务 + 数据库
前置条件
- 安装 Railway CLI:
npm i -g @railway/cli - 登录 Railway:
railway login(需要用户交互完成授权) - 验证登录:
railway whoami
部署流程
1. 初始化 Railway 项目
# 在项目根目录初始化(交互式,选择创建新项目或链接已有项目)
railway init
2. 自动构建检测
Railway 使用 Nixpacks 自动检测项目类型并构建,无需手动配置:
| 项目类型 | 检测依据 | 构建命令 | 启动命令 |
|---|---|---|---|
| Node.js | package.json |
npm install + npm run build |
npm start |
| Python | requirements.txt / pyproject.toml |
pip install -r requirements.txt |
python main.py 或 gunicorn |
| Go | go.mod |
go build |
编译产物 |
| Java | pom.xml / build.gradle |
mvn package |
java -jar target/*.jar |
| Ruby | Gemfile |
bundle install |
rails s 或 ruby app.rb |
| Docker | Dockerfile |
Docker build | Docker CMD |
3. 配置启动命令(如自动检测失败)
创建 railway.json 或 railway.toml:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "node dist/server.js",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
[build]
builder = "NIXPACKS"
[deploy]
startCommand = "python main.py"
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 10
4. 部署
# 部署到 Railway
railway up
# 部署并指定环境
railway up --environment production
# 查看部署日志
railway logs
部署输出示例:
✔ Connected to project my-api
✔ Deploying...
✔ Build completed
✔ Deployed to production
? https://my-api-production.up.railway.app
5. 添加托管数据库
# 添加 PostgreSQL
railway add --plugin postgresql
# 添加 MySQL
railway add --plugin mysql
# 添加 Redis
railway add --plugin redis
# 添加 MongoDB
railway add --plugin mongodb
数据库连接串会自动注入为环境变量(如 DATABASE_URL、REDIS_URL)。
6. 环境变量管理
# 设置环境变量
railway variables set DATABASE_URL "postgres://..."
# 批量设置(从 .env 文件)
railway variables import .env
# 列出环境变量
railway variables
# 删除环境变量
railway variables unset DATABASE_URL
7. 自定义域名
# 添加自定义域名
railway domain add api.example.com
Docker 部署
如果项目有 Dockerfile,Railway 会自动使用 Docker 构建:
# 多阶段构建示例
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package*.json ./
RUN npm ci --omit=dev
EXPOSE 3000
CMD ["node", "dist/server.js"]
指定 Docker 构建:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "Dockerfile"
}
}
多服务项目
一个 Railway project 可以包含多个服务:
# 后端服务
cd backend && railway init --name my-backend
# 前端服务
cd ../frontend && railway init --name my-frontend
# 数据库(共享给所有服务)
railway add --plugin postgresql
CI/CD 集成
GitHub 自动部署
Railway 原生支持 Git 集成,连接仓库后 push 自动部署。
GitHub Actions 手动触发
name: Deploy to Railway
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm test
- name: Deploy to Railway
run: railway up --environment production
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
需要的 Secrets:
RAILWAY_TOKEN:Railway API Token(Account Settings → API Tokens)
项目类型适配
| 项目类型 | builder | startCommand 示例 |
|---|---|---|
| Express/Koa (Node) | NIXPACKS | npm start |
| FastAPI/Flask (Python) | NIXPACKS | uvicorn main:app 或 gunicorn app:app |
| Gin/Fiber (Go) | NIXPACKS | ./server |
| Spring Boot (Java) | NIXPACKS | java -jar target/app.jar |
| Rails (Ruby) | NIXPACKS | rails s -b 0.0.0.0 |
| Docker 应用 | DOCKERFILE | (Dockerfile CMD) |
检查清单
- [ ]
railway.json或railway.toml配置正确(如需要) - [ ] 启动命令正确(
startCommand或 Nixpacks 自动检测) - [ ] 数据库已添加(如需要)
- [ ] 环境变量已配置(
railway variables set) - [ ] 健康检查端点可访问
- [ ] 部署 URL 可访问(
*.up.railway.app或自定义域名) - [ ] CI/CD Secrets 已配置
04 同仓库更多 Skills
migrate-to-e2e
Moves an existing Playwright, Cypress, Selenium, Appium, Detox, Maestro, or TesterArmy suite to e2e one slice at a time, with the old suite running beside the new one until each ported test is proven. Keeps a MIGRATION.md progress file so any later session resumes where the last stopped. Optionally plants a defect to show both suites catch it. Use for /migrate-to-e2e, "migrate our tests to e2e", "port these Maestro flows", "move our TesterArmy tests", or when a project has an e2e config and an older suite still running.
e2e
Writes, runs, and debugs end-to-end tests for web and mobile apps with e2e, the agentic test runner, which mixes agent.act goals with exact locator assertions on a Playwright browser or an iOS or Android device. Also drives a project's running app live over the e2e MCP server to look at a screen, check a UI change, take a screenshot or record a video, and try a locator; and runs bug bashes, parallel e2e explore runs with each bug proven by a repro test. Use when a project depends on e2e or has an e2e.config.ts, when asked for end-to-end, browser, mobile, or agentic UI tests, to check a change in the running app, to QA or bug bash an app or branch, or when an e2e run fails.
create-verification-skill
Generate a project-local verify-<app> skill on top of e2e, so any coding agent can launch the app, check it is worth driving, exercise a feature the way a user does, keep evidence, and bug bash it. Writes the skill, a feature map with one explore charter per feature, and proves it once. Use for /create-verification-skill, "make a verification skill for this repo", or when a project has no scripted way to prove UI behavior.
deja-search
deja-vu memory — search the user's past AI coding sessions with the deja CLI. Holds what they already settled and never wrote into the repo (naming rules, banned or already-tried tools, required checks before merge, preferred values, who owns what). Use before your first edit in a task, before you call a change done or ready to merge, before you recommend a tool, library, design or reviewer, before re-debugging an error that may already be solved, when they say 'didn't we fix this before', 'what did we decide about X' or 'I already have that', and before telling them something on this machine does not exist.
deja-reflect
End-of-session reflection and memory curation with deja-vu. Review what was decided, what commands broke and what repaired them, and record durable project rules or decisions with deja remember so the next session starts with them.
revid
Make, edit, export and post AI videos with Revid (revid.ai) through the Revid MCP server. Use whenever the user wants a short-form or long-form video made (from an idea, a script, a URL, an article, a PDF, a tweet, a product page, their own clips, or a song), wants to find what is going viral on TikTok, YouTube, Instagram or X before making something, wants to edit or re-export an existing Revid project, generate a standalone AI image or clip, make a series episode, or publish and schedule a finished video to connected social accounts. Covers setup (hosted MCP with OAuth, or an API key), the 36 tools, credits, polling and the rules for publishing. Routes to the more specific revid-* skills when one fits.