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

Let CMD <cmd> in the Dockerfile template be configurable #957

Closed
wants to merge 5 commits into from

Conversation

AliMirlou
Copy link

A configurable CMD might not be something this project wants but there are many use-cases for this, like starting the notebook in a different way or even using Repo2Docker as a library to build non-jupyter Docker images. It would be nice to have this feature.

By the way, this change is completely backward-compatible and does not affect anyone who does not want to change the CMD.

@welcome
Copy link

welcome bot commented Sep 12, 2020

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@AliMirlou
Copy link
Author

I haven't reflected the changes in the documentations and changelog yet. Waiting for someone's approval first.

@AliMirlou
Copy link
Author

Also can anyone explain why the "lint" check is failing? Is it because of too many characters in one line?

@manics
Copy link
Member

manics commented Sep 13, 2020

We use pre-commit and the black autoformatter.

If you install pre-commit (e.g. with pip) and run

pre-commit run --all-files

the code should pass the CI lint check.

@AliMirlou
Copy link
Author

@manics Can you review this PR yourself? It's not a major change.

@AliMirlou AliMirlou marked this pull request as draft October 12, 2020 01:34
@AliMirlou
Copy link
Author

@betatim I need some approval to continue this PR. Can you give a quick review?

@AliMirlou
Copy link
Author

Or @minrk perhaps?

@AliMirlou
Copy link
Author

@manics Can you review this PR now?

@consideRatio consideRatio changed the title [WIP] Configurable cmd Configurable cmd Oct 30, 2022
@consideRatio consideRatio marked this pull request as ready for review October 30, 2022 19:17
@consideRatio consideRatio changed the title Configurable cmd Let the CMD in the Dockerfile be configurable by overriding a function in base's buldpack Oct 30, 2022
@consideRatio consideRatio added the maintenance Under the hood fixes and improvements label Oct 30, 2022
@consideRatio consideRatio changed the title Let the CMD in the Dockerfile be configurable by overriding a function in base's buldpack Let the CMD in the Dockerfile be configurable by overriding function get_command in base's buldpack Oct 30, 2022
Copy link
Member

@consideRatio consideRatio left a comment

Choose a reason for hiding this comment

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

I think it could be acceptable to provide this, but I'm not sure.

I made a few suggestions towards making me feel comfortable with the implementation. I think a very strong case needs to be made for a string replacement still though, and it probably needs to be documented if a strong case for it is presented.

Comment on lines +485 to +489
def get_command(self):
"""
The default command to be run by docker.

This should return a list of strings to be used as Dockerfile `CMD`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_command(self):
"""
The default command to be run by docker.
This should return a list of strings to be used as Dockerfile `CMD`.
def get_cmd(self):
"""
A list of strings to be used for the Dockerfile's `CMD`.

Comment on lines +565 to +576
# If get_command returns a list or a tuple, it will be stringified (exec form).
# If it returns a string, it will be used as is (shell form).
cmd = self.get_command()
if isinstance(cmd, tuple):
cmd = list(cmd)
if isinstance(cmd, list):
cmd = str(cmd).replace("'", '"')
if not isinstance(cmd, str):
raise ValueError(
'Method "get_command" of buildpack "%s" must return a string, a list or a tuple.'
% self.__class__.__name__
)
Copy link
Member

Choose a reason for hiding this comment

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

  • Removed validation as this isn't user facing, just for those making custom buildpacks. My goal is to minimize complexity and ease the long term maintenance and code comprehension by doing that.
  • Removed tuples fixup for similar reasons.
Suggested change
# If get_command returns a list or a tuple, it will be stringified (exec form).
# If it returns a string, it will be used as is (shell form).
cmd = self.get_command()
if isinstance(cmd, tuple):
cmd = list(cmd)
if isinstance(cmd, list):
cmd = str(cmd).replace("'", '"')
if not isinstance(cmd, str):
raise ValueError(
'Method "get_command" of buildpack "%s" must return a string, a list or a tuple.'
% self.__class__.__name__
)
cmd = self.get_command()
if isinstance(cmd, list):
cmd = str(cmd).replace("'", '"')

I don't understand what is going on with regards to the replacement operation that remains, but I suspect its not reasonable to provide either.

@@ -568,6 +589,7 @@ def render(self):
base_packages=sorted(self.get_base_packages()),
post_build_scripts=self.get_post_build_scripts(),
start_script=self.get_start_script(),
command=cmd,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
command=cmd,
cmd=cmd,

@@ -191,7 +191,7 @@
ENTRYPOINT ["/usr/local/bin/repo2docker-entrypoint"]

# Specify the default command to run
CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]
CMD {{ command }}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CMD {{ command }}
CMD {{ cmd }}

@consideRatio consideRatio changed the title Let the CMD in the Dockerfile be configurable by overriding function get_command in base's buldpack Let CMD in the Dockerfile template be configurable by passed key/value Oct 30, 2022
@consideRatio
Copy link
Member

@consideRatio consideRatio added new and removed maintenance Under the hood fixes and improvements labels Oct 31, 2022
@consideRatio consideRatio changed the title Let CMD in the Dockerfile template be configurable by passed key/value Let CMD in the Dockerfile template be configurable Nov 1, 2022
@consideRatio consideRatio changed the title Let CMD in the Dockerfile template be configurable Let CMD <cmd> in the Dockerfile template be configurable Nov 1, 2022
@manics
Copy link
Member

manics commented Sep 15, 2024

Thanks for the PR. I'm closing since there's been no updates, and it's already possible to override CMD using appendix
https://repo2docker.readthedocs.io/en/latest/usage.html#cmdoption-jupyter-repo2docker-appendix

@manics manics closed this Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants