Dockerfile 代码格式化工具:Dockerfmt
`dockerfmt` 是一个基于 `buildkit` 解析器的 `Dockerfile` 格式化和解析工具,是 `dockfmt` 的现代版。它提供格式化 `Dockerfile` 的功能,并支持 `RUN` 步骤的格式化,包括基本的 heredocs 和内联注释。用户可以通过下载二进制文件进行安装和使用,支持检查格式、指定缩进和添加换行等选项。目前存在一些局限性,例如不支持 `RUN` 命令分组和 `# escape=X` 指令。 提供了 JS 绑定。
dockerfmt
dockerfmt
是一个 Dockerfile
格式化和解析器,是 dockfmt 的一个现代版本。它构建于内部的 buildkit 解析器之上。
安装
二进制文件可从 releases 页面获取。
用法
A updated version of the dockfmt. Uses the dockerfile parser from moby/buildkit and the shell formatter from mvdan/sh.
Usage:
dockerfmt [Dockerfile] [flags]
dockerfmt [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version Print the version number of dockerfmt
Flags:
-c, --check Check if the file(s) are formatted
-h, --help help for dockerfmt
-i, --indent uint Number of spaces to use for indentation (default 4)
-n, --newline End the file with a trailing newline
-w, --write Write the formatted output back to the file(s)
Use "dockerfmt [command] --help" for more information about a command.
局限性
RUN
解析器目前不支持命令中的分组或分号- 不执行长 JSON 命令的换行
- 不支持
# escape=X
指令
欢迎贡献代码!
特性
- 使用 https://github.com/mvdan/sh 格式化
RUN
步骤 - 支持基本的 heredocs:
RUN <<EOF
echo "hello"
echo "world"
EOF
- 支持 run 步骤中的基本内联注释:
RUN echo "hello" \
# this is a comment
&& echo "world"
RUN echo "hello" \
# this is a comment
# that spans multiple lines
&& echo "world"
这令人惊讶地 non-trivial,因为我们希望将注释附加到格式化输出中的位置,但它们事先被解析器剥离了。
JS Bindings
JS bindings 在 js
目录中可用。 有关如何使用它们的更多信息,请参见 README 文件。
关于
Dockerfile format and parser. a modern dockfmt.