-
Notifications
You must be signed in to change notification settings - Fork 600
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: Add proper entrypoint #531
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||||||||||||||||||||||||||||||||
#!/bin/sh | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
set -eu | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
bin='docker-gen' | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
# run command if it is not starting with a "-" and is an executable in PATH | ||||||||||||||||||||||||||||||||||||
if [ "${#}" -le 0 ] || \ | ||||||||||||||||||||||||||||||||||||
[ "${1#-}" != "${1}" ] || \ | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you pass |
||||||||||||||||||||||||||||||||||||
[ -d "${1}" ] || \ | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this implied by the |
||||||||||||||||||||||||||||||||||||
! command -v "${1}" > '/dev/null' 2>&1; then | ||||||||||||||||||||||||||||||||||||
entrypoint='true' | ||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
exec ${entrypoint:+${bin:?}} "${@}" | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @buchdag that this should use |
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
exit 0 | ||||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed;
Suggested change
Comment on lines
+5
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting it all together, I would do something like this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this. I've gone over this a lot in my mind over the year. Could you be right on all cases. Could my approach have been improved? I think the answer is yes, and you showed me that. I've adapted it for my general purpose needs as such:
I think it's shorter and more concise. I did use an 'if/else' structure instead of an 'or' structure as I find it's easier to read for passers by. I use 'bin' instead of just pasting the command, as I reuse this snippet in multiple entry-point scripts, and having it re-usable is valuable :) Also I'm keeping the exit 0 at the end; it's a security thing and should be done consistently. Not 'oh maybe I don't need it here', also, again re-usability. Also, style-wise I follow the common best practice to always use curly-braces around variables. And yes, I feel the comment is really needed here, this was a bit magical for me, or maybe that But even so, thank you very much for this improvement! You helped me quite a bit to make my standard entrypoint even more ultimate :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
command
will return 1 if the command name is the empty string, so this check isn't necessary.