moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.2k stars 1.16k forks source link

proposal: Dockerfile check for correct filename formatting #5133

Open tonistiigi opened 4 months ago

tonistiigi commented 4 months ago

Dockerfiles should be named in a way users can recognize them when checking out a new project.

Expected name is Dockerfile or something.Dockerfile . Lowercase variants are also allowed (although I've not seen much of them in the wild).

Some people write it in opposite order Dockerfile.something what isn't correct and leads to incorrect syntax highlighting and type detection in Github and editors, eg. https://github.com/xamma/KubeS3/blob/d7246618bb72fe5e3fd264490c311914d2fa3afb/Dockerfile.backend#L4 . Github check is based on https://github.com/github-linguist/linguist/blob/master/lib/linguist/languages.yml#L1591 afaik.

I'd suggest a warning on the Dockerfile.something pattern and probably also if there is no Dockerfile component in the filename at all. I think allowing case-insensitivity is fine.

Note that this does not affect non-Dockerfile BuildKit frontends. As the validation is in frontend itself, anything, but Dockerfile can continue to use whatever filename they like in docker build -f.

AkihiroSuda commented 4 months ago

Some people write it in opposite order Dockerfile.something what isn't correct and leads to incorrect syntax highlighting and type detection in Github and editors, eg.

What about rather fixing up github-linguist?

The Dockerfile.something pattern is quite popular and even used by moby/moby: https://github.com/moby/moby/blob/master/Dockerfile.windows

tonistiigi commented 4 months ago

The Dockerfile.something pattern is quite popular and even used by moby/moby:

And at the same time it also uses the something.Dockerfile pattern as well. I think better for users if we recommend being consistent. Yes, this was fairly popular in the old Dockerfiles, but I think there is a good consensus that filename extension is something that happens at the end of the file instead of the front.

What's weird though is that your link is highlighted in Github case while mine was not. Do you know what the difference is? If you look at the Dockerfiles for a project https://github.com/search?q=repo%3Amoby%2Fmoby++language%3ADockerfile&type=code then the file you listed is undetected.

There isn't anything inherently bad about a popular project having checks that show up. We had some issues in our own Dockerfiles that we didn't notice before the checks were introduced.

tianon commented 4 months ago

I use the Dockerfile.xxx format a lot because capitalized file extensions give me the ick -- I use .gitattributes to help GitHub highlight them correctly, but I've noticed it's really buggy sometimes depending on how/where you're viewing the code.

(see https://github.com/moby/moby/blob/2cfc2a57a84900db112bd911143de7aed719d739/.gitattributes#L1 for the relevant attribute on moby/moby)

tianon commented 4 months ago

(I also prefer Dockerfile.xxx in a repository with lots of other content because then they all sort together lexicographically.)