Fly.io (flyctl) CLI
Operate Fly.io apps safely and repeatably with flyctl.
Defaults / safety
- - Prefer read-only commands first:
fly status, fly logs, fly config show, fly releases, fly secrets list. - Do not edit/modify Fly.io apps, machines, secrets, volumes, or databases without your human’s explicit approval.
- Read-only actions are OK without approval.
- Destructive actions (destroy/drop) always require explicit approval.
- - When debugging builds, capture the exact error output and determine whether it’s a:
- build/packaging issue (Dockerfile, Gemfile.lock platforms, assets precompile)
- runtime issue (secrets, DB, migrations)
- platform issue (regions, machines, health checks)
Quick start (typical deploy)
From the app repo directory:
1) Confirm which app you’re targeting
- - INLINECODE6
- INLINECODE7
- Check
fly.toml for INLINECODE9
2) Validate / inspect (read-only)
- - INLINECODE10
- INLINECODE11
- INLINECODE12
(Deploys are in High-risk operations below and require explicit user approval.)
Debugging deploy/build failures
Common checks
- -
fly deploy --verbose (more build logs) - If using Dockerfile builds: verify Dockerfile Ruby/version and Gemfile.lock platforms match your builder OS/arch.
Rails + Docker + native gems (nokogiri, pg, etc.)
Symptoms: Bundler can’t find a platform gem like
nokogiri-…-x86_64-linux during build.
Fix pattern:
- - Ensure
Gemfile.lock includes the Linux platform used by Fly’s builder (usually x86_64-linux).
- Example:
bundle lock --add-platform x86_64-linux
- - Ensure Dockerfile’s Ruby version matches
.ruby-version.
(See references/rails-docker-builds.md.)
Logs & config (read-only)
-
fly logs -a <app>
-
fly config show -a <app>
- - List secrets (names only):
- INLINECODE22
High-risk operations (ask first)
These commands can execute arbitrary code on servers or mutate production state.
Only run them when the user explicitly asks you to.
-
fly deploy /
fly deploy --remote-only
-
fly ssh console -a <app> -C "<command>"
- INLINECODE26
See references/safety.md.
Fly Postgres basics
Identify the Postgres app
Attach Postgres to an app
Create a database inside the cluster
- - INLINECODE30
- INLINECODE31
Connect (psql)
GitHub Actions deploys / previews
- - For production CD: use Fly’s GitHub Action (
superfly/flyctl-actions/setup-flyctl) and run flyctl deploy. - For PR previews:
- Prefer one
preview app per PR and one
database per PR inside a shared Fly Postgres cluster.
- Automate create/deploy/comment on PR; destroy on close.
(See references/github-actions.md.)
Bundled resources
- -
references/safety.md: safety rules (read-only by default; ask before mutating state). - INLINECODE37 : Rails/Docker/Fly build failure patterns + fixes.
- INLINECODE38 : Fly deploy + preview workflows.
- INLINECODE39 : tiny helper to print the Fly app name from fly.toml (shell-only; no ruby).
Fly.io (flyctl) CLI
使用 flyctl 安全且可重复地操作 Fly.io 应用。
默认行为 / 安全规范
- - 优先使用只读命令:fly status、fly logs、fly config show、fly releases、fly secrets list。
- 未经用户明确批准,不得编辑/修改 Fly.io 应用、机器、密钥、卷或数据库。
- 只读操作无需批准即可执行。
- 破坏性操作(销毁/删除)始终需要明确批准。
- 构建/打包问题(Dockerfile、Gemfile.lock 平台、资源预编译)
- 运行时问题(密钥、数据库、迁移)
- 平台问题(区域、机器、健康检查)
快速入门(典型部署)
从应用仓库目录开始:
1) 确认目标应用
- - fly app list
- fly status -a <应用名>
- 检查 fly.toml 中的 app = ...
2) 验证/检查(只读)
- - fly status -a <应用名>
- fly logs -a <应用名>
- fly config show -a <应用名>
(部署属于下方的高风险操作,需要用户明确批准。)
调试部署/构建失败
常见检查项
- - fly deploy --verbose(获取更多构建日志)
- 如果使用 Dockerfile 构建:验证 Dockerfile 中的 Ruby 版本和 Gemfile.lock 平台与构建器操作系统/架构匹配。
Rails + Docker + 原生 gem(nokogiri、pg 等)
症状:Bundler 在构建期间找不到类似 nokogiri-…-x86_64-linux 的平台 gem。
修复方案:
- - 确保 Gemfile.lock 包含 Fly 构建器使用的 Linux 平台(通常是 x86_64-linux)。
- 示例:bundle lock --add-platform x86_64-linux
- - 确保 Dockerfile 中的 Ruby 版本与 .ruby-version 匹配。
(参见 references/rails-docker-builds.md。)
日志与配置(只读)
- fly logs -a <应用名>
- fly config show -a <应用名>
- fly secrets list -a <应用名>
高风险操作(先询问)
这些命令可以在服务器上执行任意代码或修改生产状态。
仅在用户明确要求时运行。
- fly deploy / fly deploy --remote-only
- fly ssh console -a <应用名> -C <命令>
- fly secrets set -a <应用名> KEY=value
参见 references/safety.md。
Fly Postgres 基础
识别 Postgres 应用
将 Postgres 附加到应用
- - fly postgres attach -a <应用名>
在集群内创建数据库
- - fly postgres db create <数据库名> -a
- fly postgres db list -a
连接(psql)
- - fly postgres connect -a
GitHub Actions 部署/预览
- - 用于生产环境持续部署:使用 Fly 的 GitHub Action(superfly/flyctl-actions/setup-flyctl)并运行 flyctl deploy。
- 用于 PR 预览:
- 每个 PR 优先使用一个
预览应用,并在共享的 Fly Postgres 集群内每个 PR 使用一个
数据库。
- 自动化创建/部署/评论 PR;关闭时销毁。
(参见 references/github-actions.md。)
捆绑资源
- - references/safety.md:安全规则(默认只读;修改状态前先询问)。
- references/rails-docker-builds.md:Rails/Docker/Fly 构建失败模式及修复方案。
- references/github-actions.md:Fly 部署及预览工作流。
- scripts/flyappfrom_toml.sh:从 fly.toml 打印 Fly 应用名称的小型辅助工具(仅限 shell,无需 Ruby)。