Repository navigation
This release is mostly about correctness. dockerfmt could turn a working Dockerfile into one that no longer builds, or one that builds something different. Every known case is fixed, and a new safety check makes that class of bug fail safe.
Highlights
- dockerfmt no longer changes what your Dockerfile does. After formatting each instruction, dockerfmt parses the result with BuildKit (the parser
docker builduses) and checks that it means the same thing as the original. If it doesn't, the instruction is left exactly as written and a warning is printed (Dockerfile:12: left unformatted: ...). Please report these warnings. - The
RUNformatter was rewritten. Comments and\separator lines are placed using the shell syntax tree instead of regexes. Output for existing Dockerfiles is unchanged. - New
--diff/-dflag prints a unified diff of the changes needed and implies--check(#60, #63, thanks @mat813). - New Alpine image:
ghcr.io/reteps/dockerfmt:alpine(and:<version>-alpine) includes a shell, for CI systems like GitLab CI (#62, thanks @mat813).
Fixes
- Legacy
ENV key valuewith spaces in the value is now quoted. Before, it became an invalidkey=value(#69, #74, thanks @RyoKusnadi). - Converting
MAINTAINERtoLABELnow escapes quotes, backslashes and$(#70, #75, thanks @RyoKusnadi). COPY/ADDin JSON form keep it when a path contains whitespace (#71).- After a
SHELLinstruction that selects PowerShell orcmd, shell-form bodies are left as written. Before, they were formatted as POSIX shell (#72). - CRLF files keep consistent CRLF line endings (#73).
- Every heredoc in an instruction is kept, not just the first (#76).
- A blank line inside a
RUNcontinuation no longer splits it into a new instruction (#77). - Continuation lines inside quoted
ENV/LABEL/ARGvalues are no longer indented, since indenting them changed the value (#78). CMD/ENTRYPOINT/RUNarguments that aren't valid JSON stay in shell form (#79).- Heredocs fed to a non-shell program (
RUN <<EOF python3, or a body with a non-shell shebang) are left as written instead of crashing (#80). - Non-UTF-8 input (such as UTF-16 written by PowerShell's
>) is rejected with an error. Before, it produced an empty file with exit code 0 (#81). - Empty continuation lines (
\alone) and comments amongRUNflags are preserved (#59, #82). - Instructions dockerfmt doesn't recognize (e.g. a misspelled keyword) are kept. Before, they were deleted.
COPY/ADDwith a heredoc keep their flags. Before,COPY --chmod=755 <<EOFlost--chmod.CMDJSON form keeps its flags, andCOPYkeeps a--end-of-flags marker.dockerfmt -i <TAB>completes numbers instead of file names, and positional arguments complete file names (#64, #66).- The pre-commit hook no longer overrides
indent_sizefrom.editorconfig(#61, #67).
Other changes
- Dependencies were updated (buildkit v0.33.0, Go 1.26) to pick up CVE fixes (#58, thanks @gw0).
- The npm package now builds its wasm from the tagged source, so it includes every formatter change. Before, the published wasm was missing every formatter change since v0.5.1, including
# dockerfmt-ignore. - Library: the new
lib.Format(content, config) (string, error)returns errors instead of exiting.FormatFileLinesis unchanged. - JS: formatting invalid input now rejects with an
Error.