-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker-lock tries to read directories with matching names as dockerfiles #91
Comments
@andoks I merged a change to be more strict about checking directories and files that exist. Could you give it a try and let me know if those more strict changes give you any unforeseen headaches before I cut a new release? |
@michaelperel: thanks! I tested a bit, and I noticed that when there is a directory called "Dockerfile" with a docker-file inside it, I get the following error
|
@andoks I have fixed this issue. Would you be able to run it once more on your codebase and make sure there are no other headaches? Thanks :) |
@michaelperel: Still get the error "'dockerfile' is a directory rather than a file" when doing the following:
|
@andoks In your specific case, your glob pattern does not pick up the file you think it does, but instead only matches the directory. Instead, your command should be:
This goes back to the discussion in #90 - I think the case you want is "recursively search all folders, which match the filename with the regex *dockerfile". Currently, recursively searching matches a bunch of default names mentioned in the README, but a flag could be added to match a regex. |
@andoks It is unfortunate that there are differences between specific language implementation's of regexes and globs, and since docker-lock is written in go, it follows go's conventions. Does the glob pattern provided cover your use case? |
Oh, yeah, I though that the flag was used to pass essentially what would be a filter regex (which is why I also passed --dockerfile-recursive, which I then though would trigger recursive walking through all files). That's my bad sorry!
This was indeed what I thought I did with the command yeah. But I think the glob flag is okay, but I misunderstood how it is working. If it is an easy mistake to do for others I would not know. On my part I do not think I need the regex support per se, since I now think I understand how I am supposed to use the globs flags.
Yes, I think so. However I still get the following error when testing: 'some_dir/dockerfile' is a directory rather than a file. Would it be Ok to unchoke these errors when using globs too? Test
|
@andoks In your last command, the glob pattern
means match all paths that are 1 directory down with the pattern If you want to go 2 directories down like in your example, you would have to use the pattern
Unfortunately, If I wish that go's glob patterns had a way to recursively match all directories with In projects that I have worked on, typically I know where the Dockerfiles are, so I just specify multiple glob patterns to the correct directories. For example:
In your project, is it the case that you don't know where all the Dockerfiles are/they are not organized in a way? I think the recursive regex solution would solve cases like that. |
did not know that:
|
@michaelperel you are indeed right. I thought the globs worked similar to shell globs. Looking at the docs for filepath glob syntax, Would it be possible to replace the implementation used for globbing with something that support more powerful globs (e.g https://pkg.go.dev/github.com/gobwas/glob) or would that be considered a too much of a breaking change? If the only blocker is the amount of work, I could take a look at doing a PR.
I agree it is good it chokes on this the way globbing currently works. 👍
From the docs it does not look like it exist in go's path/filepath at all to me.
Right now it is yes, so I can make do with listing all subdirs that have dockerfiles and compose files in them. But I wanted to also ensure that any new recipes created also were picked up without having to remember (or know of) a top-level CI config that needs to be updated. I know from experience there is a chance I will forget it myself, and if not me, then someone else on the team. But I am usually consistent in naming these files, so IMO there is a relative greater chance for that approach to work on my team. That was my motivation anyhow.
It probably would, as long as 1) the regex filter is applied to all possible subpaths from CWD and 2) matching directories are ignored but recursed into. An alternative would be to use a more powerful glob library, showing an example in the help text for the glob flags increasing the chances for making the user understand that it is a glob not a regex, and stop erroring on matching directories (perhaps logging matching dirs to stdout, or add a -v flag to increase the log level to show these dirs) |
@andoks I am open to using a 3rd party package, but I was thinking that it could complicate things if people expect things to work as go does. Given our recent discussion, since people can use the In light of this, I actually think it is not worth implementing the regex approach or a more powerful glob approach. Do you agree, and is that ok for your use case? |
@michaelperel I see your point re globs and regex. I suspect however that how the current globs works breaks the principle of least surprise for more users though. I am a go developer myself (arguably relatively fresh), but since I never have needed glob functionality in my programs so far, I was not aware of Gos particularities re glob syntax and support. And seeing as docker-lock is not particularly catering to go-developers, but docker users in general, even more so. Regarding using find, and passing the result to --dockerfiles / --composefiles, this is a good approach, but IMO this too surprised me, that it used commmas' separation of files instead of spaces or newlines, and when I passed the raw output of find, it happily chugged along, but only parsed the first entry in the list. This however could be remedied quite effectively by mentioning in the flags --help text that the paths are comma-separated, possibly showing an example using find (although the example might be overfitting to unix platforms, maybe there is something equivalent for windows that can be switched for using an architecture or os build tag). These are just my two cents, grain of salt and so forth... For me in particular though, I have my usecases covered with the --dockerfiles/--composefiles + find + paste and the changes you have implemented so far 👍. Thank you so much 😃 |
@andoks As of the previous pull request, Hopefully, you will not have to use As for the comma syntax for lists, I will add better documentation for all of the commands in the README, and re-evaluate the help text. Thanks! |
@michaelperel Thank you. Now I have two options that will probably both work for my use-case: the CSV and globs. I tested latest master, and it seems to work flawlessly 😄
I passed the recursive options to make sure that the dockerfiles called the default 'Dockerfile' name also is picked up (and compose-files too, although that should not be necessary for my repo) since the globs (as expected) are case sensitive. |
docker lock generate
seems to want to try to parse directories as if they are dockerfiles (this does not seems to happen for docker-compose entries).E.g
This is particularly a problem when using --dockerfile-globs, as it is not possible to specify that the glob should only match files (AFAIK)
The text was updated successfully, but these errors were encountered: