Live data from Hacker News

Dockerfmt: A Dockerfile Formatter

github.com

31–40 of 67 posts

Re: Dockerfmt: A Dockerfile Formatter

#31
post #20

waaaat? https://github.com/reteps/dockerfmt#:~:text=The%20RUN%20pars... I am firmly in the camp of RUN set -e ;\ export DEBIAN_FRONTEND=noninteractive ;\ etc etc so I guess this tool isn't for me

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.

Re: Dockerfmt: A Dockerfile Formatter

#32

> 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 ; \ :

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. [1] http…

Between that and the difficulty with comments, it feels like maybe not an ideal tool for the job? Although, I can't throw stones; I'd do almost anything to avoid having to write my own parser. (And not meant as an attack regardless, just trying to constructively question this particular design point)

Re: Dockerfmt: A Dockerfile Formatter

#33

Earlier quoted context omitted.

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. [1] http…

Between that and the difficulty with comments, it feels like maybe not an ideal tool for the job? Although, I can't throw stones; I'd do almost anything to avoid having to write my own parser. (And not meant as an attack regardless, just trying to constructively question this particular design point)

I am certainly not in the business of writing my own shell parser ;) Though this is a fair point -- I think I could get a more rich level of control over the output by hooking into their parser, albeit with a higher level of complexity.

Re: Dockerfmt: A Dockerfile Formatter

#34

Earlier quoted context omitted.

Between that and the difficulty with comments, it feels like maybe not an ideal tool for the job? Although, I can't throw stones; I'd do almost anything to avoid having to write my own parser. (And not meant as an attack regardless, just trying to constructively question this particular design point)

I am certainly not in the business of writing my own shell parser ;) Though this is a fair point -- I think I could get a more rich level of control over the output by hooking into their parser, albeit with a higher level of complexity.

/shrug Something to think about. Usually I'd say not to worry about it, but this particular point seems to be actively causing actual problems, so it might be worth looking at. Alternatively, if the pain points you've discovered really are all there are to find, then it might well be less trouble to just patch over them specifically and not worry about it. Ugly solutions that work well and don't take extra work are good solutions in my book;)

Re: Dockerfmt: A Dockerfile Formatter

#35

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 suggest you build it with https://github.com/ko-build/ko

so you can still have no dockerfile and the irony is not ruined

Re: Dockerfmt: A Dockerfile Formatter

#36

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 easiest way would be to run it as a Docker container

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:

    docker run --rm --name dockerfmt \
    -v /path/to/Dockerfile:/tmp/Dockerfile \
    golang:1.24-alpine sh -c \
    "apk add git && go run github.com/reteps/dockerfmt@latest /tmp/Dockerfile"
> against an existing file

For this part yes, you'd still need one, but it can be any of your own.

Re: Dockerfmt: A Dockerfile Formatter

#37
post #20

waaaat? https://github.com/reteps/dockerfmt#:~:text=The%20RUN%20pars... I am firmly in the camp of RUN set -e ;\ export DEBIAN_FRONTEND=noninteractive ;\ etc etc so I guess this tool isn't for me

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.

Re: Dockerfmt: A Dockerfile Formatter

#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 functions, running shell linters directly, or using higher-level languages like Python if you really need it for some reason
Post reply on HN