Live data from Hacker News

Dockerfmt: A Dockerfile Formatter

github.com

41–50 of 67 posts

Re: Dockerfmt: A Dockerfile Formatter

#41

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.

Hi there — I’ll try to distribute a docker release of the binary tomorrow!

I think they were asking for a sample Dockerfile in the repo to test it on.

Re: Dockerfmt: A Dockerfile Formatter

#43
post #17

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. 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 produ…

> 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.

Re: Dockerfmt: A Dockerfile Formatter

#44
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.

Re: Dockerfmt: A Dockerfile Formatter

#46

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.

The author doesn't know how to use AI.

Re: Dockerfmt: A Dockerfile Formatter

#48
post #37

Earlier quoted context omitted.

Is there any reason you prefer `set -e` over `&&`? I'm curious if this is a readability thing.

I'm firmly in that camp but I also always add `set -eux`, which makes it so much better at debugging as that gives you individual commands it runs before the output of them.

To be clear, the difference is something along this line:

    $ bash -ec 'echo hello && ls -la /tmp/ | grep systemd && false && echo testing'
    hello
    drwx------.   3 root   root      60 Mar 29 18:33 systemd-private-bluetooth.service-yuSMVM
    drwx------.   3 root   root      60 Mar 29 18:33 systemd-private-upower.service-YhHHP2
versus

    $ bash -euxc 'echo hello; ls -la /tmp/ | grep systemd; false; echo testing'
    + echo hello
    hello
    + ls -la /tmp/
    + grep systemd
    drwx------.   3 root   root      60 Mar 29 18:33 systemd-private-bluetooth.service-yuSMVM
    drwx------.   3 root   root      60 Mar 29 18:33 systemd-private-upower.service-YhHHP2
    + false
Docker also supports the `SHELL` syntax now, which is even better, because you can set it once at the top of the Dockerfile without having to do the whole `set -eux` on every line.

Re: Dockerfmt: A Dockerfile Formatter

#49
post #38

> The RUN parser currently doesn't support grouping or semicolons in commands But then example show that it does support `&&`? Why the difference? I pretty much always write RUN foo && \ bar && \ : but it seems syntactically identical to the also valid RUN set -e && \ foo ; \ bar ; \ :

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 function…

That's bad practice because it hides build steps from `docker inspect`. Per https://github.com/docker-library/official-images#clarity:

> Try to make the Dockerfile easy to understand/read. It may be tempting, for the sake of brevity, to put complicated initialization details into a standalone script and merely add a RUN command in the Dockerfile. However, this causes the resulting Dockerfile to be overly opaque, and such Dockerfiles are unlikely to pass review. Instead, it is recommended to put all the commands for initialization into the Dockerfile as appropriate RUN or ENV command combinations. To find good examples, look at the current official images.

Re: Dockerfmt: A Dockerfile Formatter

#50

Earlier quoted context omitted.

I prefer heredoc[1] syntax. I find it more readable and portable. [1] https://www.docker.com/blog/introduction-to-heredocs-in-dock...

Meta: In HN, prefix a line with 2 spaces to get code formatting, ex. # syntax=docker/dockerfile:1.3-labs FROM alpine RUN Non-meta: Do you happen to know how portable that is across old docker, podman/buildah, kaniko, etc.? I'd like to adopt it but I don't want it to bite me when I'm not running a recent version of literal docker.

It is new feature and not portable to old versions. But modern podman supports it. No idea about kaniko.
Post reply on HN