
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
本项目展示了如何将 https://infracost.io 与 Atlantis 结合使用。它会自动在 Atlantis 输出的底部添加一条显示成本估算差异的评论。查看 https://github.com/infracost/atlantis-demo/pulls#issuecomment-795889174%EF%BC%8C%E5%B1%95%E5%BC%80%E2%80%9C%E6%98%BE%E7%A4%BA%E8%BE%93%E5%87%BA%E2%80%9D%E9%83%A8%E5%88%86%E5%B9%B6%E5%90%91%E4%B8%8B%E6%BB%9A%E5%8A%A8%E5%8D%B3%E5%8F%AF%E7%9C%8B%E5%88%B0 Infracost 输出。
此集成默认使用最新版本的 Infracost,因为我们会定期添加对更多云资源的支持。如果遇到任何问题,请加入我们的 https://www.infracost.io/community-chat%EF%BC%8C%E6%88%91%E4%BB%AC%E5%BE%88%E4%B9%90%E6%84%8F%E4%B8%BA%E6%82%A8%E6%8F%90%E4%BE%9B%E6%8C%87%E5%AF%BC%E3%80%82
如 https://www.infracost.io/docs/faq 中所述,不会向 Cloud Pricing API 发送任何云凭证或机密信息。Infracost 不会对您的 Terraform 状态或云资源进行任何修改。
!示例截图(宽度557,alt="示例截图")
有两种将 Infracost 与 Atlantis 集成的方法:
使用自定义 Docker 镜像,该镜像通过 扩展 Atlantis 的 latest 镜像来添加 Infracost。这是推荐方法。
通过 curl 将 Atlantis 的 $PLANFILE 发送到 https://www.infracost.io/docs/integrations/infracost_api%E3%80%82%E5%B0%BD%E7%AE%A1%E6%AD%A4 API 会在处理文件后从服务器删除文件,但在将文件发送到 API 之前删除其中的机密信息是良好的安全实践。例如,AWS 提供了 https://gist.github.com/alikhajeh1/f2c3f607c44dabc70c73e04d47bb1307 可用于此目的。
此方法使用 Atlantis 生成的 $PLANFILE 运行 infracost diff。以下步骤说明如何使用此方法:
https://hub.docker.com/repository/docker/infracost/infracost-atlantis/ 通过添加 Infracost 来扩展 Atlantis 镜像。如果您已为 Atlantis 使用自定义 Docker 镜像,可将 https://github.com/infracost/infracost-atlantis/blob/master/Dockerfile 中的 RUN 命令复制到您的 Dockerfile 中。
更新 Atlantis 配置,添加 自定义命令 以使用所需环境变量(如 INFRACOST_API_KEY)运行 Infracost。下一节将描述可用的环境变量。以下示例展示了如何实现此操作,也可通过 Server Config 文件或 Server Side Repo Config 文件中的 Atlantis YAML 配置实现类似功能。
bashdocker run docker.xuanyuan.run/infracost/infracost-atlantis:latest server \ --gh-user=MY_GITHUB_USERNAME \ --gh-token=MY_GITHUB_TOKEN \ --gh-webhook-secret=MY_GITHUB_WEBHOOK_SECRET \ --repo-allowlist='github.com/myorg/*' \ --repo-config-json=' { "repos": [ { "id": "/.*/", "workflow": "terraform-infracost" } ], "workflows": { "terraform-infracost": { "plan": { "steps": [ "init", "plan", { "env": { "name": "INFRACOST_API_KEY", "value": "MY_API_KEY" } }, { "env": { "name": "INFRACOST_TERRAFORM_BINARY", "command": "echo \"terraform${ATLANTIS_TERRAFORM_VERSION}\"" } }, { "run": "/home/atlantis/infracost_atlantis_diff.sh" } ] } } } } '
Infracost 会从 Atlantis 的 $PLANFILE(Terraform 二进制文件格式)生成 Terraform 计划 JSON。如果您希望在 Infracost 运行前执行此操作,可使用以下步骤替代上述步骤。infracost_atlantis_diff.sh 脚本会先检查 $PLANFILE.json 文件,再检查 $PLANFILE。
bash- run: terraform show -no-color -json $PLANFILE > $PLANFILE.json - run: /home/atlantis/infracost_atlantis_diff.sh - run: rm -rf $PLANFILE.json
提交新的拉取请求以更改 Terraform 中涉及成本的内容;Atlantis 会在拉取请求上发布评论,展开“显示输出”部分,在底部即可看到 Infracost 输出。若遇到问题,可设置 atlantis_debug=true 环境变量并查看 https://www.infracost.io/docs/integrations/cicd#cicd-troubleshooting%E3%80%82
本节描述必填环境变量。其他支持的环境变量详见 https://www.infracost.io/docs/integrations/environment_variables%E3%80%82
Terragrunt 用户还应阅读 https://www.infracost.io/docs/iac_tools/terragrunt%E3%80%82Terraform Cloud/Enterprise 用户还应阅读 https://www.infracost.io/docs/iac_tools/terraform_cloud_enterprise%E3%80%82
INFRACOST_API_KEY
必填 需获取 API 密钥,请 https://www.infracost.io/docs/#quick-start 并运行 infracost register。
INFRACOST_TERRAFORM_BINARY
必填 用于指定当前版本的 terraform 二进制文件路径,应设置为 Atlantis 中使用的 Terraform 或 Terragrunt 二进制文件路径(Infracost 支持 Terraform v0.12 及以上版本)。如果使用 infracost/infracost-atlantis 镜像(基于 https://github.com/runatlantis/atlantis/blob/master/Dockerfile 镜像),可设置为:
/usr/local/bin/terraform0.12.30。<data-dir>/bin/terraform<version>。Terragrunt 用户可使用 'echo "/atlantis-data/bin/terraform${ATLANTIS_TERRAFORM_VERSION}"'。usage_file
可选 Infracost https://www.infracost.io/docs/usage_based_resources#infracost-usage-file 的路径,用于指定基于使用量的资源的值,详见 https://github.com/infracost/infracost/blob/master/infracost-usage-example.yml 中的可用选项。
config_file
可选 如需按仓库设置 Terraform 版本,可在 https://www.infracost.io/docs/config_file/ 中定义,并将此参数设置为文件路径。在此情况下,usage_file 参数不可用,必须在配置文件中定义。
post_condition
可选 描述触发拉取请求评论条件的 JSON 字符串,可选值:
'{"has_diff": true}':仅当存在差异时发布评论(默认行为)。'{"always": true}':始终发布评论。'{"percentage_threshold": 0}':触发评论的绝对百分比阈值,例如设为 1 表示当成本估算变化超过 ±1% 时发布评论。show_skipped
可选 显示不支持的资源(其中部分可能免费),默认值为 false。
SLACK_WEBHOOK_URL
可选 设置此参数可同时将拉取请求评论发布到 Slack Webhook,从而发送到相应的 Slack 频道。
atlantis_debug
可选 在 https://github.com/infracost/infracost/blob/master/scripts/ci/atlantis_diff.sh 中启用调试模式,在 Atlantis 拉取请求评论中显示运行步骤,默认值为 false。
MY_API_KEY 更新为您的 Infracost API 密钥。也可通过 Server Config 文件或 Server Side Repo Config 文件中的 Atlantis YAML 配置实现类似功能。可选步骤:在将计划 JSON 文件发送到 API 前,添加步骤移除其中的机密信息。bashdocker run docker.xuanyuan.run/infracost/infracost-atlantis:latest server \ --gh-user=MY_GITHUB_USERNAME \ --gh-token=MY_GITHUB_TOKEN \ --gh-webhook-secret=MY_GITHUB_WEBHOOK_SECRET \ --repo-allowlist='github.com/myorg/*' \ --repo-config-json=' { "repos": [ { "id": "/.*/", "workflow": "terraform-infracost" } ], "workflows": { "terraform-infracost": { "plan": { "steps": [ "init", "plan", { "run": "terraform show -json $PLANFILE > $PLANFILE.json" }, { "run": "echo \"#####\" && echo && echo Infracost output:" }, { "run": "curl -s -X POST -H \"x-api-key: MY_API_KEY\" -F \"ci-platform=atlantis\" -F \"terraform-json-file=@$PLANFILE.json\" -F \"no-color=true\" https://pricing.api.infracost.io/terraform-json-file" }, { "run": "rm -rf $PLANFILE.json" } ] } } } } '
欢迎提交拉取请求。对于重大变更,请先打开 issue 讨论您想要修改的内容。
https://choosealicense.com/licenses/apache-2.0/
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务