fusion-infra-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFusion Infra CLI
Fusion Infra CLI
When to use
适用场景
Use when a Fusion service database needs to be provisioned or migrated — locally during development or inside CI/CD pipelines.
Typical triggers:
- "Provision the database for the context service"
- "Run migrations on the QA database"
- "Set up a PR database for this pull request"
- "What does the database provision config look like?"
- "The pipeline is failing on the database provision step"
- "Create a PR database that copies from CI"
当需要为Fusion服务配置或迁移数据库时使用——无论是开发阶段的本地操作,还是CI/CD流水线内的操作。
典型触发场景:
- "为上下文服务配置数据库"
- "在QA数据库上运行迁移"
- "为本次拉取请求(PR)设置PR数据库"
- "数据库配置文件是什么样的?"
- "流水线在数据库配置步骤失败了"
- "创建一个从CI复制数据的PR数据库"
When not to use
不适用场景
- Application code or service changes — use the service repo
- Role or permission management — use
fusion-roles-cli - Infrastructure other than databases (networking, storage, etc.)
- Kubernetes or container management
- 应用代码或服务变更——请使用服务代码仓库
- 角色或权限管理——请使用
fusion-roles-cli - 数据库以外的基础设施(网络、存储等)
- Kubernetes或容器管理
Prerequisites
前置条件
Install as a .NET global tool:
finfbash
dotnet tool install --global \
--add-source "https://statoil-proview.pkgs.visualstudio.com/Fusion%20-%20Packages/_packaging/Fusion-Public/nuget/v3/index.json" \
Fusion.Infra.CliUpdate to latest:
bash
dotnet tool update --global \
--add-source "https://statoil-proview.pkgs.visualstudio.com/Fusion%20-%20Packages/_packaging/Fusion-Public/nuget/v3/index.json" \
Fusion.Infra.CliAuth uses automatically (picks up session). Pass to override.
DefaultAzureCredentialaz login-t <token>将安装为.NET全局工具:
finfbash
dotnet tool install --global \
--add-source "https://statoil-proview.pkgs.visualstudio.com/Fusion%20-%20Packages/_packaging/Fusion-Public/nuget/v3/index.json" \
Fusion.Infra.Cli更新至最新版本:
bash
dotnet tool update --global \
--add-source "https://statoil-proview.pkgs.visualstudio.com/Fusion%20-%20Packages/_packaging/Fusion-Public/nuget/v3/index.json" \
Fusion.Infra.Cli认证会自动使用(会读取会话)。可通过参数覆盖默认认证方式。
DefaultAzureCredentialaz login-t <token>Core workflow — provision a database
核心工作流——配置数据库
1. Create the provisioning config file
1. 创建配置文件
The config file defines the database resource. Minimal example ():
db-config.jsonjson
{
"name": "my-service",
"environment": "ci"
}Full config with SQL permissions:
json
{
"name": "my-service",
"environment": "fqa",
"sqlPermission": {
"owners": [
{ "clientId": "<app-registration-client-id>" }
],
"contributors": [
{ "clientId": "<app-registration-client-id>" }
]
}
}See references/db-config-schema.md for the full schema.
配置文件用于定义数据库资源。最简示例():
db-config.jsonjson
{
"name": "my-service",
"environment": "ci"
}包含SQL权限的完整配置:
json
{
"name": "my-service",
"environment": "fqa",
"sqlPermission": {
"owners": [
{ "clientId": "<app-registration-client-id>" }
],
"contributors": [
{ "clientId": "<app-registration-client-id>" }
]
}
}完整配置 schema 请参考references/db-config-schema.md。
2. Run provisioning
2. 执行配置
CI / non-production:
bash
finf database provision -f db-config.json -e ci \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verboseQA:
bash
finf database provision -f db-config.json -e fqa \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verboseProduction (add flag):
--productionbash
finf database provision -f db-config.json -e fprd \
--production \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verbosePull Request (ephemeral database, copies from CI):
bash
finf database provision -f db-config.json \
-e pr -pr <pr-number> -ghr "equinor/my-repo" -c ci \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
--timeout 500 -o response.json --verboseCI / 非生产环境:
bash
finf database provision -f db-config.json -e ci \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verboseQA环境:
bash
finf database provision -f db-config.json -e fqa \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verbose生产环境(需添加参数):
--productionbash
finf database provision -f db-config.json -e fprd \
--production \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
-o response.json --verbose拉取请求(PR)(临时数据库,从CI复制数据):
bash
finf database provision -f db-config.json \
-e pr -pr <pr-number> -ghr "equinor/my-repo" -c ci \
--sql-owner-client-id <client-id> \
--sql-contributor-client-id <client-id> \
--timeout 500 -o response.json --verbose3. Run migrations
3. 执行迁移
After provisioning, apply SQL migrations:
bash
undefined配置完成后,应用SQL迁移:
bash
undefinedNon-production
非生产环境
finf database migrate -d sql-myservice-fqa -m migrations/
-o migrations.json --verbose
-o migrations.json --verbose
finf database migrate -d sql-myservice-fqa -m migrations/
-o migrations.json --verbose
-o migrations.json --verbose
Production
生产环境
finf database migrate -d sql-myservice-fprd -m migrations/
--production -o migrations.json --verbose
--production -o migrations.json --verbose
The `-m` flag accepts a directory of `.sql` files or a single `.sql` file.finf database migrate -d sql-myservice-fprd -m migrations/
--production -o migrations.json --verbose
--production -o migrations.json --verbose
`-m`参数接受包含`.sql`文件的目录或单个`.sql`文件。Environments
环境说明
| Key | Purpose |
|---|---|
| Continuous integration |
| QA / pre-production |
| Production (requires |
| Pull request ephemeral (requires |
| 标识 | 用途 |
|---|---|
| 持续集成环境 |
| QA / 预生产环境 |
| 生产环境(需 |
| 拉取请求临时环境(需 |
Full reference
完整参考
For complete flag reference, run:
bash
finf database provision --help
finf database migrate --helpOr see the source documentation:
如需查看所有参数说明,执行以下命令:
bash
finf database provision --help
finf database migrate --help或查看源码文档:
Safety
安全注意事项
- Always use in pipelines to get diagnostic output
--verbose - Always save output with so pipeline steps can reference the result
-o response.json - The flag is an explicit guard — never omit it for
--productionprovisioningfprd - Never pass raw tokens in pipeline YAML — use secret variables and pass via
-t - is irreversible for non-PR databases — confirm with user before running
database delete
- 在流水线中始终使用参数以获取诊断输出
--verbose - 始终使用保存输出,以便流水线步骤可以引用结果
-o response.json - 参数是明确的防护机制——针对
--production环境配置时绝不能省略fprd - 绝不要在流水线YAML中直接传递明文令牌——使用保密变量并通过参数传递
-t - 非PR数据库的操作不可逆——执行前请与用户确认
database delete