Community程式設計與開發github.com

edit-spec-file

編輯 Bottlerocket RPM spec 檔案,並遵循專案樣式慣例。

edit-spec-file 是什麼?

這個技能「edit-spec-file」旨在協助開發者修改 Bottlerocket 專案中的 RPM spec 檔案,同時嚴格遵守專案的樣式慣例。它確保所有套件中的 spec 檔案保持一致且易於維護。使用時機包括新增原始檔、修補檔、範本、systemd 服務、組態檔,或建立新的子套件(包含 FIPS 變體)。技能會引導使用者先閱讀樣式指南,並參考現有類似套件作為模式,然後依照嚴格的區段順序進行修改,並使用正確的巨集(如 `%{_cross_bindir}`)和原始檔編號規則。此外,它還會在提交前提供驗證檢查清單,確保沒有常見的反模式(如重新編號原始檔或使用硬編碼路徑)。此技能支援在 Bottlerocket 的 `kits/*/packages/` 目錄下工作,適用於以 AI 代理(如 Claude Code)為主的工作流程。

相容平台~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 檔案進行修改,同時嚴格遵守專案樣式慣例。此技能可確保所有套件中的 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 宣告相同的順序安裝:

# Sources declared as:
Source1: nvidia-k8s-device-plugin.service
Source2: nvidia-k8s-device-plugin-conf
Source3: nvidia-k8s-device-plugin-exec-start-conf

# Install in same order:
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(請使用出廠預設值模式)
  • 主要 %files 區段中包含 %{_cross_attribution_file}
  • 授權檔案使用 %license 指令
  • 套件擁有的目錄使用 %dir 指令
  • 沒有偵錯指令(ls -la 等)
  • 沒有不必要的註解
  • 格式一致(沒有尾端空白、縮排一致)
  • Release: 1%{?dist} 格式(% 前沒有點號)

提交變更

提交 spec 檔案變更時,請使用 -F 搭配檔案,以保留提交訊息中的換行符號:

# Write message to file, then commit with -F
msg = """package-name: summary of change

Detailed description of what changed and why.

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")

請勿使用 git commit -m 搭配 repr() 或跳脫字串——這會寫入字面 \n 而非真正的換行符號。

常見反模式

請勿:

  • 使用 Release: 1.%{?dist}(錯誤:有多餘的點號)
  • 在檔案路徑中包含 ./ 前綴
  • 新增會重複明顯操作的註解
  • 使用 %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

相關技能