Community编程与开发github.com

编辑spec文件

按照项目风格约定编辑Bottlerocket RPM spec文件,确保所有kit包的spec文件保持一致性和可维护性。

编辑spec文件 是什么?

该技能旨在帮助开发者高效、合规地编辑Bottlerocket RPM spec文件。它提供了一套标准化的流程,从阅读风格指南、查找参考包到逐步修改spec文件的各个部分(如全局定义、元数据、源文件、补丁等),并严格遵循项目规定的顺序和宏命名约定(如交叉编译宏、FIPS子包格式)。技能支持多种常见任务:添加systemd服务、模板文件、drop-in目录,以及创建包含FIPS变体的子包。通过内置的验证清单,开发者可以在提交前自动检查源文件编号、安装顺序、路径宏、权限设置等关键项,避免常见反模式(如硬编码路径、错误编号或遗漏attribution文件)。适用于Bottlerocket各kit目录下的所有.spec文件修改场景,尤其适合涉及多包维护的团队协作。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/cbgbt/bottlerocket-forest/tree/main/skills/edit-spec-file

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

技能:编辑 Spec 文件

目的

对 Bottlerocket RPM spec 文件进行修改,同时严格遵守项目风格约定。本技能确保所有 kit 包中的 spec 文件保持一致且可维护。

何时使用

  • 向包中添加新的源文件、补丁或模板
  • 添加 systemd 服务或配置文件
  • 创建新的子包(包括 FIPS 变体)
  • 修改构建或安装部分
  • 对 kits/*/packages/ 中的任何 .spec 文件进行修改

前提条件

  • 在进行任何更改之前,完整阅读 ./STYLE-GUIDE.md
  • 识别一个现有的类似包作为参考模式

流程

1. 阅读风格指南

强制要求:在进行任何更改之前阅读 ./STYLE-GUIDE.md。

风格指南包含:

  • [必须] 规则,是强制性的
  • [不得] 规则,是被禁止的
  • [应该] 规则,是强烈推荐的

2. 查找参考包

识别一个或多个现有的类似包作为模式:

# 对于 Go 包
ls kits/bottlerocket-core-kit/packages/*/nvidia-k8s-device-plugin.spec

# 对于带有 systemd 服务的 C 包
ls kits/bottlerocket-core-kit/packages/chrony/chrony.spec

# 对于带有 FIPS 变体的包
ls kits/bottlerocket-core-kit/packages/amazon-ssm-agent/amazon-ssm-agent.spec

3. 按照节顺序应用更改

Spec 文件具有严格的节顺序:

  1. %global 定义
  2. 包元数据(Name、Version、Release、Summary、License、URL)
  3. 源文件(按范围编号:<100 杂项,1xx systemd,2xx tmpfiles,3xx udev,4xx 许可证)
  4. 补丁(编号 1000+)
  5. BuildRequires / Requires
  6. %description
  7. 子包定义(%package、%description)
  8. %prep
  9. %build
  10. %install
  11. %files 部分

4. 源文件编号

如果需要,遵循已建立的范围,并使用上述示例包作为具体指南,范围示例如下:

  • Source0-Source99:主要源文件和杂项文件
  • Source100-Source199:Systemd 单元文件
  • Source200-Source299:Tmpfiles 配置
  • Source300-Source399:Udev 规则
  • Source400-Source499:许可证文件

关键:删除源文件时,请保留间隙——不要重新编号现有源文件,除非它们在同一个百位节中。

5. 按源顺序安装文件

%install 中的文件必须按照其 Source 声明的相同顺序安装:

# 源文件声明为:
Source1: nvidia-k8s-device-plugin.service
Source2: nvidia-k8s-device-plugin-conf
Source3: nvidia-k8s-device-plugin-exec-start-conf

# 按相同顺序安装:
install -p -m 0644 %{S:1} %{buildroot}%{_cross_unitdir}
install -D -m 0644 %{S:2} %{buildroot}%{_cross_templatedir}/nvidia-k8s-device-plugin-conf
install -D -m 0644 %{S:3} %{buildroot}%{_cross_templatedir}/nvidia-k8s-device-plugin-exec-start-conf

6. 使用正确的宏

始终使用交叉编译宏:

  • %{_cross_bindir} 而不是 /usr/bin
  • %{_cross_unitdir} 用于 systemd 单元
  • %{_cross_templatedir} 用于模板
  • %{_cross_factorydir}%{_cross_sysconfdir}/... 用于工厂默认值
  • %{_cross_fips_bindir} 用于 FIPS 二进制文件

7. FIPS 子包模式

当添加需要 FIPS 变体的二进制文件时:

%package bin
Summary: 包二进制文件
Provides: %{name}(binaries)
Requires: (%{_cross_os}image-feature(no-fips) and %{name})
Conflicts: (%{_cross_os}image-feature(fips) or %{name}-fips-bin)

%description bin
%{summary}.

%package fips-bin
Summary: 包二进制文件,FIPS 版本
Provides: %{name}(binaries)
Requires: (%{_cross_os}image-feature(fips) and %{name})
Conflicts: (%{_cross_os}image-feature(no-fips) or %{name}-bin)

%description fips-bin
%{summary}.

8. 文件权限

使用一致的权限:

  • 0755 用于可执行文件
  • 0644 用于配置文件、模板、服务文件
  • 使用 install -p 保留时间戳
  • 当需要创建父目录时使用 install -D

验证清单

在提交之前,生成一个子代理独立验证,参考本文档和“验证清单”:

  • 源文件编号在正确的范围内
  • 安装顺序与 Source 声明顺序匹配
  • 所有路径使用 %{_cross_*} 宏
  • 没有文件安装到 /etc 或 /var(使用工厂默认模式)
  • %{_cross_attribution_file} 在主要 %files 部分
  • 许可证文件的 %license 指令
  • 包拥有的目录的 %dir 指令
  • 没有调试命令(ls -la 等)
  • 没有不必要的注释
  • 格式一致(无尾随空格,缩进一致)
  • Release: 1%{?dist} 格式(% 前无点)

提交更改

当提交 spec 文件更改时,使用 -F 加文件来保留提交消息中的换行符:

# 将消息写入文件,然后使用 -F 提交
msg = """package-name: 更改摘要

更改内容及原因的详细描述。

Signed-off-by: Name <email>"""
write("create", "/tmp/commit-msg.txt", file_text=msg)
bash("git -c commit.gpgsign=false commit -F /tmp/commit-msg.txt")

不要使用带有 repr() 或转义字符串的 git commit -m——这会将字面 \n 写入而不是换行符。

常见反模式

不要:

  • 使用 Release: 1.%{?dist}(错误:有 dots)
  • 在文件路径中包含 ./ 前缀
  • 添加重复明显操作的注释
  • 使用 %exclude 替代正确的构建配置
  • 删除项目时重新编号源文件
  • 未按源顺序安装文件
  • 使用硬编码路径而不是宏
  • 创建跨包符号链接

快速参考

添加 Systemd 服务

  1. 添加 100 范围源文件:Source101: myservice.service
  2. 安装到 unitdir:install -p -m 0644 %{S:101} %{buildroot}%{_cross_unitdir}
  3. 添加到 %files:%{_cross_unitdir}/myservice.service

添加模板

  1. 添加源文件:Source5: mytemplate-conf
  2. 安装:install -D -m 0644 %{S:5} %{buildroot}%{_cross_templatedir}/mytemplate-conf
  3. 添加到 %files:%{_cross_templatedir}/mytemplate-conf

添加 Drop-in 目录

  1. 创建目录:install -d %{buildroot}%{_cross_unitdir}/myservice.service.d
  2. 添加到 %files:%dir %{_cross_unitdir}/myservice.service.d

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

ad-hoc-implementation-plan

Transform a rough plan into implement-commit ready artifacts. Allows rigorous review while implementing.

build-kit-locally

Build a kit and publish it to a locally hosted registry for development testing

build-variant-from-local-kits

Build a variant using locally published kits for development validation

deep-research

Create educational documents that build understanding progressively with citations

fact-find

Quick lookup of specific facts about Bottlerocket with citations

idea-honing

Clarify feature ideas through iterative Q&A, recording insights to guide concept development

implement-commit

Implement commits from an implementation plan using a TDD pipeline

local-registry

Start and manage a local OCI registry for Bottlerocket kit development

prepare-core-kit-release

Prepare bottlerocket-core-kit for release by bumping version and updating changelog

propose-feature-concept

Create a new feature concept document to pitch the idea and explain the problem/solution

propose-feature-design

Create or update feature technical design document with architecture and implementation guidance

propose-feature-requirements

Create or update feature requirements specification using EARS notation with examples and appendices

propose-feature-test-plan

Create a test plan mapping EARS requirements and Critical Constraints to specific tests

propose-implementation-plan

Create an implementation plan with atomic commits that build toward a complete feature

review-code

Deep code review generating PR comments via principled question-driven analysis

review-scope

Verify code changes match intended scope and requirements without exceeding boundaries

review-style

Verify code follows project style guides without providing improvement suggestions

test-local-twoliter

Build and test local changes to twoliter before releasing

update-twoliter

Update all Bottlerocket repositories to a new Twoliter version

相关技能