@ e2b/ dockerfile- utils
Dockerfile 解析器和 shell 借记器移植自 构建 Kit (单位:千美元) .dockerignore 匹配器从 暴徒/骑兵,没有运行时间依赖。 用于 E2B SDK 软件 执行 Template.fromDockerfile 并过滤构建上下文.
import { parseDockerfileAst, ShellLex } from '@e2b/dockerfile-utils'
const ast = parseDockerfileAst(`
FROM node:24 AS build
ENV KEY="a b" OTHER=c
RUN <<EOF
npm ci
npm run build
EOF
`)
for (const instruction of ast.instructions) {
console.log(instruction.name, instruction.flags, instruction.args)
}
const lex = new ShellLex(ast.escapeToken)
lex.processWords('KEY="a b" OTHER=c') // ['KEY=a b', 'OTHER=c']
parseDockerfileAst 处理解析指令( o)# escape=, (中文(简体) ), # syntax=),注释(包括行内续作),构建者旗帜,JSON/exec表格和这里的docs,以及报告行号和警告. ShellLex 与 BuildKit 一样, 分割和未引用单词 $VAR 编号 : ${VAR:-default} 以后的扩展参考.
import { PatternMatcher } from '@e2b/dockerfile-utils'
const matcher = new PatternMatcher(['node_modules', '*.log', '!keep.log'])
matcher.matches('node_modules/pkg/index.js') // true
matcher.matches('keep.log') // false
PatternMatcher 应用 .dockerignore 与上下文根相对的斜线分隔路径的语义: 匹配目录的图案排除其下的所有内容,以及 ! 模式重新包含路径(最后匹配模式获胜)。 无效模式抛出平原 Error。 。 。 .