Skip to content
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

Add support for entrypoint attribute #1088

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

davidkopp
Copy link
Contributor

@davidkopp davidkopp commented Mar 6, 2025

Closes #1085

Only the short form of the entrypoint attribute is implemented (see Docker Compose specification).
This is also the case for the `command' attribute, where only the short form is currently implemented.

Greptile Summary

Added support for Docker entrypoint attribute in service configurations, allowing overriding of predefined container ENTRYPOINTs to enable execution of runtime commands in test flows.

  • Added entrypoint validation in lib/schema_checker.py as an optional string field in service definitions
  • Added test_entrypoint_ran() in tests/test_usage_scenario.py to verify entrypoint command execution
  • Modified runner.py to support entrypoint attribute using secure command parsing via shlex.split()
  • Added test scenario entrypoint_stress.yml demonstrating entrypoint usage with stress testing commands

The implementation enables use of common API/load testing tools like JMeter, k6, Artillery and grpcurl that have predefined ENTRYPOINTs.

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

@ArneTR
Copy link
Member

ArneTR commented Mar 6, 2025

Uh, this looks juicy, ty!

  1. I will let our GreptileAI check it ... so beware for maybe incoming comments.
  2. On first view I believe using shlex.split on the entrypoint may introduce an argument injection. The idea is to have whatever is supplied as entrypoint to be supplied as one contigous string.
    => I will give it a more thorough look tomorrow morning

First and foremost: Big thx!

@ArneTR
Copy link
Member

ArneTR commented Mar 6, 2025

@greptileai

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile

runner.py Outdated
Comment on lines 1025 to 1026
if 'entrypoint' in service:
docker_run_string.extend(shlex.split(service['entrypoint']))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: entrypoint should be added before any docker-run-args to match Docker's behavior where entrypoint is processed before additional arguments

runner.py Outdated
Comment on lines 1025 to 1026
if 'entrypoint' in service:
docker_run_string.extend(shlex.split(service['entrypoint']))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: verify that entrypoint is not empty or None before extending docker_run_string

Suggested change
if 'entrypoint' in service:
docker_run_string.extend(shlex.split(service['entrypoint']))
if 'entrypoint' in service and service['entrypoint']:
docker_run_string.extend(shlex.split(service['entrypoint']))

runner.py Outdated
Comment on lines 1025 to 1026
if 'entrypoint' in service:
docker_run_string.extend(shlex.split(service['entrypoint']))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: check that entrypoint is a string type before calling shlex.split()

Suggested change
if 'entrypoint' in service:
docker_run_string.extend(shlex.split(service['entrypoint']))
if 'entrypoint' in service and isinstance(service['entrypoint'], str):
docker_run_string.extend(shlex.split(service['entrypoint']))

@@ -121,6 +121,7 @@ def check_usage_scenario(self, usage_scenario):
Optional("setup-commands"): [And(str, Use(self.not_empty))],
Optional("volumes"): self.single_or_list(str),
Optional("folder-destination"):And(str, Use(self.not_empty)),
Optional("entrypoint"): And(str, Use(self.not_empty)),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding validation to ensure entrypoint doesn't contain shell syntax that could be unsafe (similar to contains_no_invalid_chars check)

Suggested change
Optional("entrypoint"): And(str, Use(self.not_empty)),
Optional("entrypoint"): And(str, Use(self.not_empty), Use(self.contains_no_invalid_chars)),

@davidkopp
Copy link
Contributor Author

My initial implementation was completely wrong. Sorry for that.
Before marking the PR as ready I would like to do some more tests. For example I would like to set the entrypoint to entrypoint.sh to be able to execute arbitrary commands instead of just one word.

@davidkopp davidkopp marked this pull request as ready for review March 8, 2025 16:02
@davidkopp
Copy link
Contributor Author

davidkopp commented Mar 8, 2025

I think the PR is now ready for review. I added now 3 unit tests in total to have a good understanding of how the entrypoint can be used, also in conjunction with command.
Let me know, if 3 tests are too much because of the time the tests are taking.

I didn't do the changes greptile proposed, because then it would not be consistent with the rest of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support entrypoint in docker compose
2 participants