本目录包含 Dockerfile 注入机制使用的代码片段,每个文件定义一个注入类型。
{inject-type}.snippetnode.snippet, claude.snippet, python-tools.snippet安装 Node.js 环境(通过 nvm)
使用方法:
# @inject-start # @inject: node # @inject-end
安装和配置 Claude Code CLI
使用方法:
# @inject-start # @inject: claude # @inject-end
包含:
# 创建新片段
vim dev/inject-snippets/python-tools.snippet
# ============================================ # Python 开发工具(自动注入) # ============================================ COPY setup/python-tools.sh /tmp/python-tools.sh RUN chmod +x /tmp/python-tools.sh && /tmp/python-tools.sh && rm /tmp/python-tools.sh
FROM python:3.11 # @inject-start # @inject: python-tools # @inject-end WORKDIR /workspace
# 处理注入
bash dev/inject-dockerfile.sh python-3.11
# 查看结果
cat envs/python-3.11/Dockerfile.injected
# ============================================ # 功能描述(自动注入) # ============================================ # 1. 复制必要的脚本 COPY setup/xxx.sh /tmp/xxx.sh # 2. 执行安装或配置 RUN chmod +x /tmp/xxx.sh && \ /tmp/xxx.sh && \ rm /tmp/xxx.sh # 3. 如需保留文件到镜像 COPY image-scripts/xxx.sh /opt/cnb/scripts/xxx.sh RUN chmod +x /opt/cnb/scripts/xxx.sh
setup/ - 安装脚本(构建时运行后删除)
node-install.shsetup-claude.shpython-tools.shimage-scripts/ - 镜像内脚本(保留到镜像)
claude-restore.sh如果注入类型不存在:
# Error: Unknown inject type 'xxx' # Available snippets: node claude
检查可用的片段:
ls dev/inject-snippets/*.snippet | xargs -n1 basename | sed 's/.snippet$//'
dev/inject-snippets/ ├── README.md # 本文档 ├── node.snippet # Node.js 安装 ├── claude.snippet # Claude Code 安装配置 └── ... # 其他自定义片段