Devops best practices
容器化与部署的工程规范。涵盖 Dockerfile 多阶段与非 root、K8s/Kustomize/Helm 的探针与安全上下文、凭据不入库、docker compose 的 profile 与健康检查、CI 流水线的事件作用域与 tag 策略、process-compose 的进程生命周期。在编写或审查 Dockerfile、docker-compose.yml、process-compose.yml、CI 流水线配置、K8s 清单、Helm chart、部署脚本时使用——尤其是新增服务、调整探针、处理镜像 tag 与环境差异、或往仓库里加任何含凭据的配置时。From its SKILL.md
npx -y skills add JinsYin/skills --skill devops-best-practicesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its file declares
Copied from the file, not written here
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
6.5 KB, as published. Nobody here has run it
DevOps Best Practices
容器化与部署的规范集,26 条规则分 6 类,按违反后果排序。
如何使用本 skill
不要一次读完所有规则。 先在下面的索引里定位与当前任务相关的条目,再按需 Read 对应文件:
rules/image-nonroot-explicit-uid.md
rules/deploy-three-probes.md
每条规则含:为什么、错误示例、正确示例。
选取原则——按你正在改的文件定位,不按分类通读:
| 你在改什么 | 先读 |
|---|---|
Dockerfile | image-* |
docker-compose.yml | compose-* |
process-compose.yml | proc-* |
| CI 流水线配置 | ci-*、secret-ci-from-store-only |
| K8s 清单 / Kustomize overlay / Helm chart | deploy-*、secret-* |
| 新增一个服务(端到端) | image-* + deploy-* + ci-tag-strategy-single-source |
| 任何含凭据的文件 | secret-*(全部,只有 3 条) |
| 排查"构建成功但部署跑的是旧版本" | ci-tag-strategy-single-source、deploy-no-latest-in-prod |
| 排查"本地好的、产线不对" | image-tz-explicit、image-entrypoint-exec-form-env、image-nonroot-explicit-uid |
这类规范的共性
运维配置有一个区别于业务代码的失效模式:改动在本地看不出问题,只在另一个环境炸。而且症状与根因往往相距很远——UID 配错报的是"权限拒绝",ENTRYPOINT 用 exec 形态报的是"参数没生效"(其实什么都不报)。
所以本 skill 的定级不完全按"严重程度",而按多久之后、在离根因多远的地方暴露。一条规则若违反后本地完全正常、到产线才咬人,即便看起来只是风格问题,也按 HIGH 起步。
分类与影响级别
影响级别按违反后果划分:CRITICAL = 产线故障/安全问题/构建部署直接失败;HIGH = 能跑但会在环境切换、扩容或排障时咬人;MEDIUM = 不一致或效率损失;LOW = 风格偏好。
| 优先级 | 分类 | 影响 | 前缀 | 条数 |
|---|---|---|---|---|
| 1 | 镜像构建 | CRITICAL | image- | 7 |
| 2 | 部署清单 | CRITICAL | deploy- | 5 |
| 3 | 凭据与配置 | CRITICAL | secret- | 3 |
| 4 | 本地依赖编排 | HIGH | compose- | 4 |
| 5 | CI 流水线 | HIGH | ci- | 4 |
| 6 | 本地进程编排 | MEDIUM | proc- | 3 |
规则索引
1. 镜像构建(CRITICAL)
image-base-registry-arg— 基础镜像前缀用 global ARG 参数化,否则本地或 CI 必有一方拉不到image-copy-artifact-exact-name— COPY 产物用确定文件名,通配匹配不到时在构建最后一步才失败image-entrypoint-exec-form-env— exec 形态 ENTRYPOINT 不展开$JAVA_OPTS,注入的参数静默失效image-layer-cache-manifest-first— 先 COPY 依赖清单再装依赖,顺序反了每次改源码都重装image-multistage-split— 构建与运行分阶段,单阶段会把编译器与私库凭据带进产线image-nonroot-explicit-uid— 非 root 且 UID 显式指定;useradd -r的系统 UID 与 K8srunAsUser:1000不匹配image-tz-explicit— 显式ENV TZ;alpine 需补装 tzdata,否则设了也不生效
2. 部署清单(CRITICAL)
deploy-base-overlay-diff-only— overlay 只放差量,复制整份清单会让 base 的修复不再传播deploy-config-secret-split— 敏感值进 Secret;ConfigMap 明文出现在kubectl describe里deploy-no-latest-in-prod— 生产用确定 tag,否则回滚回退了清单却拉到同一个镜像deploy-securitycontext-match-image—runAsUser必须等于镜像内创建的 UID,否则挂载卷写不进去deploy-three-probes— 慢启动用startupProbe,调大 liveness 的initialDelay会让故障期同样延迟发现
3. 凭据与配置(CRITICAL)
secret-ci-from-store-only— CI 凭据只能from_secret;commands:步骤不走插件的 secret 解析secret-never-commit-real— 真凭据永不入库,提交过就必须按泄漏处理并轮换secret-placeholder-explicit— 占位用CHANGE_ME;像真值的占位会被带上生产且不报错
4. 本地依赖编排(HIGH)
compose-healthcheck-start-period— 必配 healthcheck 且探真实可服务性;start_period按首次初始化给compose-optional-behind-profile— 备用服务挂profiles,默认不起compose-parameterize-env— 宿主端口/tag/镜像源参数化并带默认值,配.env.examplecompose-platform-only-when-no-native—platform只在镜像确无原生架构时加,多余声明强制走模拟层
5. CI 流水线(HIGH)
ci-anchor-repeated-values— registry/tag 用 YAML anchor 收敛;漏改一处不报错,只是推到旧仓库ci-build-inside-container— 构建步骤显式指定镜像并钉版本,不依赖节点自带工具链ci-explicit-event-scope— 每个步骤写when.event;扩 trigger 时未限定的步骤会被意外触发ci-tag-strategy-single-source— CI 与部署清单的 tag 策略同源,否则"构建成功、部署成功、跑的是旧版本"
6. 本地进程编排(MEDIUM)
proc-guard-before-start— 易错前提写成守护进程而非文档;违反后的症状通常远离根因proc-no-hardcoded-host-paths— 不写死JAVA_HOME等本机路径,该文件是入库的proc-oneshot-restart-no— 一次性进程必须restart:"no",否则成功退出后被无限拉起
与项目规范的关系
本 skill 是跨项目通用基线。具体的仓库地址、secret 名称、模块名、镜像仓库主机名属于项目事实,应写在项目的 CLAUDE.md 或 AGENTS.md,不要写进这里。
冲突时以项目自身的约定为准。
维护
改动 rules/ 后必须重新生成全量版:
bash scripts/build.sh
AGENTS.md 供不支持渐进披露的工具直接通读,不重建就会与规则源不一致,而它不会自己报错。