I had a chuckle when I looked at the source code and could not find a Dockerfile in there. I want to kick the tires on it and the easiest way would be to run it as a Docker container against an existing file and alas, I cannot.
I don't want to vouch for the flagged and dead comment https://news.ycombinator.com/item?id=43630653 because I suspect it was killed for its tone but wow it is really illustrative of the QA that didn't go into this product
What I can do for you is fix the bugs promptly! I resolved the bugs in the `0.2.7` release. I haven't graduated college yet and don't have a full time job, so my QA skills are still improving.
As far as I can tell from https://github.com/moby/moby/issues/4032, as of Debian 12 "bookworm" and Ubuntu 23.04 "Lunar", explicitly setting DEBIAN_FRONTEND is no longer necessary.
Or, you can write an actual shell script file (i.e. with a .sh extension) to be stored in your repository, ADD it in a throwaway context (i.e. multi-stage builds), then RUN --mount=type=bind to put it into a temporary directory in the build container so that you can execute it. This way, the script doesn't pollute the container, and you have proper separation of concerns, including the ability to use library functions, running shell linters directly, or using higher-level languages like Python if you really need it for some reason
I use `mvdan/sh` [1] under the hood for processing the commands. So it will reformat
if [ foo ] ; then
bar
fi
to
if [ foo ]
then
bar
fi
And also format your example to
foo
bar
In this type of situation, it becomes a little trickier to disambiguate when I need to add semicolons and a backslash, and when I need to add only backslashes. If you use `&&` -- you have disambiguated the two cases so I can format it.
This reminds me of SQL indentation “best practices” discussion [1]
I personally don’t find this particularly helpful but can see it helping some folks. You write enough dockerfiles, the formatting becomes irrelevant.
What pisses me off though is _inconsistency_. One code base uses "formatting practices 1b", then another code base uses "formatting practices 2x". Then the worst offender: a service owners that can’t make up their mind and each developer makes up their own "best practices".
How does it handle multi-stage Dockerfiles? I always indent the steps following FROM to make the stages more obvious. I don't get why that isn't a norm because not doing it seems like not indenting function bodies in other languages.
I just use a yaml LSP which will probably try to lookup the schema.org Containerfile format for this. I first noticed this recently when working on a Github Actions yaml file. Pretty nifty.
It's great to see auto-formatting continuing to become universal across all languages. As LLMs write more code, full auto-formatting helps keep diffs clean.
Full disclosure: I'm the founder of Qlty, which produces a universal code linter and formatter, Qlty CLI (https://github.com/qltysh/qlty). It is completely free and published under a Fair Source license.
> As LLMs write more code, full auto-formatting helps keep diffs clean.
Clean diffs matter irrespective of the author being a person or a program. But sure, I guess with the current hype a certain ratio of comments need to plug reminders that we are currently living in a code generation wasteland.
[+] [-] jensenbox|11 months ago|reply
[+] [-] PhilippGille|11 months ago|reply
Regarding this part, you can always just run a base image and add the app yourself. I'm on mobile so can't test, but should be along these lines:
> against an existing fileFor this part yes, you'd still need one, but it can be any of your own.
[+] [-] spicypete|11 months ago|reply
[+] [-] klysm|11 months ago|reply
[+] [-] revskill|11 months ago|reply
[+] [-] krick|11 months ago|reply
[+] [-] mdaniel|11 months ago|reply
[+] [-] spicypete|11 months ago|reply
[+] [-] grandempire|11 months ago|reply
Who formats the formatter configs?
[+] [-] zufallsheld|11 months ago|reply
Other formatters of course since the configs are often yaml, toml, ini or json.
[+] [-] mdaniel|11 months ago|reply
I am firmly in the camp of
so I guess this tool isn't for me[+] [-] rgovostes|11 months ago|reply
[+] [-] spicypete|11 months ago|reply
[+] [-] yjftsjthsd-h|11 months ago|reply
But then example show that it does support `&&`? Why the difference? I pretty much always write
but it seems syntactically identical to the also valid[+] [-] mcstafford|11 months ago|reply
I find it more readable and portable.
[1] https://www.docker.com/blog/introduction-to-heredocs-in-dock...
[+] [-] solatic|11 months ago|reply
[+] [-] spicypete|11 months ago|reply
[1] https://github.com/mvdan/sh
[+] [-] unknown|11 months ago|reply
[deleted]
[+] [-] urxvtcd|11 months ago|reply
[+] [-] xyst|11 months ago|reply
I personally don’t find this particularly helpful but can see it helping some folks. You write enough dockerfiles, the formatting becomes irrelevant.
What pisses me off though is _inconsistency_. One code base uses "formatting practices 1b", then another code base uses "formatting practices 2x". Then the worst offender: a service owners that can’t make up their mind and each developer makes up their own "best practices".
[1] https://stackoverflow.com/questions/272210/sql-statement-ind...
[+] [-] xyst|11 months ago|reply
I wish projects would adopt/create their own formatters like go and rust.
The amount of time I have wasted discussing "best practices" with "senior" engineers is way too damn high.
In code bases such as go or rust, the discussion ends with the "the built in formatter and preferences is preferred"
[+] [-] nikeee|11 months ago|reply
[+] [-] QuarterDuplex|11 months ago|reply
[+] [-] brigandish|11 months ago|reply
[+] [-] QuarterDuplex|11 months ago|reply
[+] [-] righthand|11 months ago|reply
[+] [-] whalesalad|11 months ago|reply
[+] [-] travisgriggs|11 months ago|reply
Then we’ll need a formatter formatter.
Software is like onions said Shrek to Donkey.
[+] [-] sandeepgogarla|11 months ago|reply
[deleted]
[+] [-] ltbarcly3|11 months ago|reply
[deleted]
[+] [-] spicypete|11 months ago|reply
I fixed this in the 0.2.8 release https://github.com/reteps/dockerfmt/releases/tag/0.2.8.
Relevant reading about the `&&` normalization. https://pkg.go.dev/encoding/json#Marshal
[+] [-] dddw|11 months ago|reply
[+] [-] PantaloonFlames|11 months ago|reply
[+] [-] dharmab|11 months ago|reply
[+] [-] DazWilkin|11 months ago|reply
Dockerfiles is the language for specifying a set of instructions for building container images.
[+] [-] jahsome|11 months ago|reply
[+] [-] brynary|11 months ago|reply
For anyone looking to try dockerfmt, I just added a plugin to Qlty CLI, which is available in v0.508.0. The plugin took about ten minutes to add: https://github.com/qltysh/qlty/blob/main/qlty-plugins/plugin...
Full disclosure: I'm the founder of Qlty, which produces a universal code linter and formatter, Qlty CLI (https://github.com/qltysh/qlty). It is completely free and published under a Fair Source license.
[+] [-] keybored|11 months ago|reply
Clean diffs matter irrespective of the author being a person or a program. But sure, I guess with the current hype a certain ratio of comments need to plug reminders that we are currently living in a code generation wasteland.