-
Notifications
You must be signed in to change notification settings - Fork 12
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
Draft: create some apps from traitlet on startup #516
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
jhub_apps/config_utils.py
Outdated
@@ -58,3 +60,9 @@ class JAppsConfig(SingletonConfigurable): | |||
None, | |||
help="Disallow a set of frameworks to avoid spinning up apps using those frameworks", | |||
).tag(config=True) | |||
|
|||
startup_apps = List( | |||
trait=Any, # TODO: Change this, use Instance() maybe or define a new type - https://traitlets.readthedocs.io/en/stable/defining_traits.html |
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.
I just put this dict here for testing. I want to re-use the JHubAppConfig pydantic model somehow ideally.
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.
We should accept git repos here alternatively
jhub_apps/service/app.py
Outdated
|
||
def instantiate_startup_apps(user_options_list: list[dict[str, Any]], username: str): | ||
# instantiate custom apps | ||
for user_options_dict in user_options_list: |
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.
I still need to add logic to only create the apps if they don't exist.
Thanks for the PR @Adam-D-Lewis, other than the gotchas to look for (as mentioned above), you're on the right path I believe. |
9a5a5d1
to
52381cc
Compare
A few questions:
|
I talked with Amit about this.
Create a service account to do this.
yes, currently only the person who created the app can edit it so using a service account should accomplish this.
The user_options is saved as an attribute of a user's server. You should be able to get access to it through the get_users method of the jhub_client. |
@@ -49,12 +109,25 @@ class JAppsConfig(SingletonConfigurable): | |||
help="The number of workers to create for the JHub Apps FastAPI service", | |||
).tag(config=True) | |||
|
|||
allowed_frameworks = Bool( | |||
allowed_frameworks = List( |
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.
Flyby: seems like these should be Lists not Bools, but I could be wrong.
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.
Yes correct. Thanks for spotting this.
@@ -102,7 +106,7 @@ async def get_spawner_profiles(config, auth_state=None): | |||
) | |||
|
|||
|
|||
def encode_file_to_data_url(filename, file_contents): | |||
def encode_file_to_data_url(filename, file_contents) -> str: |
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.
flyby: add return type annotation
jhub_config_file_path = os.environ["JHUB_JUPYTERHUB_CONFIG"] | ||
logger.info(f"Getting JHub config from file: {jhub_config_file_path}") | ||
hub.load_config_file(jhub_config_file_path) | ||
# hacky, but I couldn't figure out how to get validation of the config otherwise (In this case, validation converts the dict in the config to a Pydantic model) |
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.
I wasn't very familiar with traitlets before this. It seems strange that we don't have an JHubApp traitlets.Application that would get instantiated. The traitlets.config.loader.Config objects don't seem to get validated/coerced until instantiation. I needed c.JAppsConfig.startup_apps to be converted from list[dict] to list[BaseModel]. This was a hacky work around, but I'm open to better ways to do this if you can think of any.
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.
I wasn't very familiar with traitlets before this. It seems strange that we don't have an JHubApp traitlets.Application that would get instantiated
I am not sure how that would look like. That would make sense though, can you share an example?
I needed c.JAppsConfig.startup_apps to be converted from list[dict] to list[BaseModel]. This was a hacky work around, but I'm open to better ways to do this if you can think of any.
This should be done here:
jhub-apps/jhub_apps/configuration.py
Line 28 in a68df38
setattr(c.JAppsConfig, trait_name, defaults.get(trait_name)) |
You can instantiate the object there. I might not have followed traitlets best practices here.
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.
I am not sure how that would look like. That would make sense though, can you share an example?
I'm certainly not an expert in traitlets either, but the example I was thinking of was conda store where their fastapi server is a traitlets Application. See here
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.
Amit meant to post that the JHUBAppConfig should be instantiated in install_jhub_apps method.
Reference Issues or PRs
Contains some example code of how to pass in jhub apps to be run when Jhub apps starts up. You pass in the apps as a traitlet. They should be created if they don't exist.
Related to nebari-dev/nebari#2803
What does this implement/fix?
Put a
x
in the boxes that applyTesting
Documentation
Access-centered content checklist
Text styling
H1
or#
in markdown).Non-text content
Any other comments?