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

Deploy from git #505

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
67aa596
Resolved merge conflicts in index.js
Oct 1, 2024
011b265
Resolved merge conflicts in index.js
Oct 1, 2024
bcb941c
Resolved conflicts in index.js
Oct 1, 2024
5d54088
Resolved conflicts in index.js
Oct 1, 2024
27d9cd2
Merge branch 'main' into deploy-from-git
Oct 2, 2024
50fa624
Merge branch 'main' into deploy-from-git
Oct 15, 2024
03d16ac
Merge branch 'main' into deploy-from-git
Oct 21, 2024
7aeac1d
added git app to Deploy App form
Oct 21, 2024
8bd0230
added index.js
Oct 21, 2024
6a99881
Merge branch 'main' into deploy-from-git
Oct 31, 2024
3766f5f
Revert "Merge branch 'main' into deploy-from-git"
Oct 31, 2024
5eaaf61
updated code to have more inclusive git url, added url data to launch…
Oct 31, 2024
dee52f7
fixed app-form.test failing test removed comments
Oct 31, 2024
33f5e5a
removed asterisk in front of Name in test, asterisk is placed dynimca…
Oct 31, 2024
39350ef
Resolved merge conflicts in index.js
Oct 1, 2024
250a48b
Resolved merge conflicts in index.js
Oct 1, 2024
8021129
Resolved conflicts in index.js
Oct 1, 2024
6b8a774
Resolved conflicts in index.js
Oct 1, 2024
a168713
added git app to Deploy App form
Oct 21, 2024
d9f3191
added index.js
Oct 21, 2024
ee44f7d
Revert "Merge branch 'main' into deploy-from-git"
Oct 31, 2024
5cd7b42
updated code to have more inclusive git url, added url data to launch…
Oct 31, 2024
bb766fa
fixed app-form.test failing test removed comments
Oct 31, 2024
2e7b8f9
removed asterisk in front of Name in test, asterisk is placed dynimca…
Oct 31, 2024
07651d4
Merge branch 'deploy-from-git' of https://github.com/kildre/jhub-apps…
Oct 31, 2024
3c9fb37
removed corrupted index.js
Oct 31, 2024
a78781a
pushing index.js
Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions docs/docs/configuration.md

This file was deleted.

4 changes: 1 addition & 3 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ channels:
dependencies:
- uvicorn
- fastapi
# Later versions were yanked in PyPi, but unfortunately not on conda-forge
# https://pypi.org/project/python-multipart/0.0.14/
- python-multipart <= 0.0.12
- python-multipart
- jupyter
- plotlydash-tornado-cmd
- bokeh-root-cmd
Expand Down
2 changes: 1 addition & 1 deletion jhub_apps/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2024.10.1"
__version__ = "2024.10.1rc1"
12 changes: 1 addition & 11 deletions jhub_apps/config_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from traitlets import Unicode, Union, List, Callable, Integer, Bool
from traitlets import Unicode, Union, List, Callable, Integer
from traitlets.config import SingletonConfigurable, Enum


Expand Down Expand Up @@ -48,13 +48,3 @@ class JAppsConfig(SingletonConfigurable):
2,
help="The number of workers to create for the JHub Apps FastAPI service",
).tag(config=True)

allowed_frameworks = Bool(
None,
help="Allow only a specific set of frameworks to spun up apps.",
).tag(config=True)

blocked_frameworks = Bool(
None,
help="Disallow a set of frameworks to avoid spinning up apps using those frameworks",
).tag(config=True)
12 changes: 4 additions & 8 deletions jhub_apps/service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
get_spawner_profiles,
get_thumbnail_data_url,
get_shared_servers,
_check_if_framework_allowed,
_get_allowed_frameworks,
)
from jhub_apps.service.app_from_git import _get_app_configuration_from_git
from jhub_apps.spawner.types import FRAMEWORKS
Expand Down Expand Up @@ -149,7 +147,6 @@ async def create_server(
user: User = Depends(get_current_user),
):
# server.servername is not necessary to supply for create server
_check_if_framework_allowed(server.user_options)
server_name = server.user_options.display_name
logger.info("Creating server", server_name=server_name, user=user.name)
server.user_options.thumbnail = await get_thumbnail_data_url(
Expand Down Expand Up @@ -205,7 +202,6 @@ async def update_server(
user: User = Depends(get_current_user),
server_name=None,
):
_check_if_framework_allowed(server.user_options)
if thumbnail_data_url:
server.user_options.thumbnail = thumbnail_data_url
else:
Expand Down Expand Up @@ -249,10 +245,10 @@ async def me(user: User = Depends(get_current_user)):
@router.get("/frameworks/", description="Get all frameworks")
async def get_frameworks(user: User = Depends(get_current_user)):
logger.info("Getting all the frameworks")
config = get_jupyterhub_config()
return [
framework for framework in FRAMEWORKS if framework.name in _get_allowed_frameworks(config)
]
frameworks = []
for framework in FRAMEWORKS:
frameworks.append(framework.json())
return frameworks


@router.get("/conda-environments/", description="Get all conda environments")
Expand Down
30 changes: 1 addition & 29 deletions jhub_apps/service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from cachetools import cached, TTLCache
from unittest.mock import Mock

from fastapi import HTTPException, status
from jupyterhub.app import JupyterHub
from traitlets.config import LazyConfigValue

from jhub_apps.hub_client.hub_client import HubClient
from jhub_apps.service.models import UserOptions
from jhub_apps.spawner.types import FrameworkConf, FRAMEWORKS_MAPPING, FRAMEWORKS
from jhub_apps.spawner.types import FrameworkConf, FRAMEWORKS_MAPPING
from slugify import slugify


Expand Down Expand Up @@ -170,29 +168,3 @@ def get_shared_servers(current_hub_user):
if server["name"] in shared_server_names
]
return shared_servers_rich


def _check_if_framework_allowed(user_options: UserOptions):
"""Checks if spinning up apps via the provided framework is allowed.
"""
config = get_jupyterhub_config()
allowed_frameworks = _get_allowed_frameworks(config)
if user_options.framework not in allowed_frameworks:
raise HTTPException(
detail=f"Given framework {user_options.framework} is not allowed on this deployment, "
f"please contact admin.",
status_code=status.HTTP_403_FORBIDDEN,
)


def _get_allowed_frameworks(config):
"""Given the JupyterHub config, find out allowed frameworks."""
all_frameworks = {framework.name for framework in FRAMEWORKS}
allowed_frameworks = all_frameworks
if config.JAppsConfig.allowed_frameworks is not None:
allowed_frameworks_by_admin = set(config.JAppsConfig.allowed_frameworks)
allowed_frameworks = all_frameworks.intersection(allowed_frameworks_by_admin)
if config.JAppsConfig.blocked_frameworks is not None:
blocked_frameworks_by_admin = set(config.JAppsConfig.blocked_frameworks)
allowed_frameworks -= blocked_frameworks_by_admin
return allowed_frameworks
13 changes: 7 additions & 6 deletions jhub_apps/spawner/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,18 @@ def values(cls):
logo_path=STATIC_PATH.joinpath("gradio.png"),
logo=f"{LOGO_BASE_PATH}/gradio.png"
),
FrameworkConf(
name=Framework.custom.value,
display_name="Custom Command",
logo_path=STATIC_PATH.joinpath("custom.png"),
logo=f"{LOGO_BASE_PATH}/custom.png"
),
FrameworkConf(
name=Framework.jupyterlab.value,
display_name="JupyterLab",
logo_path=STATIC_PATH.joinpath("jupyter.png"),
logo=f"{LOGO_BASE_PATH}/jupyter.png",
),
FrameworkConf(
name=Framework.custom.value,
display_name="Custom Command",
logo_path=STATIC_PATH.joinpath("custom.png"),
logo=f"{LOGO_BASE_PATH}/custom.png"
),
]

FRAMEWORKS_MAPPING = {framework.name: framework for framework in FRAMEWORKS}
195 changes: 195 additions & 0 deletions jhub_apps/static/js

Large diffs are not rendered by default.

195 changes: 0 additions & 195 deletions jhub_apps/static/js/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion jhub_apps/tests/tests_e2e/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def create_app(
expect(deploy_button).to_be_visible()
deploy_button.click()
logger.info("Fill App display Name")
display_name_field = page.get_by_label("*Name")
display_name_field = page.get_by_label("Name")
expect(display_name_field).to_be_visible()
display_name_field.click()
display_name_field.fill(app_name)
Expand Down
49 changes: 9 additions & 40 deletions jhub_apps/tests/tests_unit/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@
from jhub_apps.hub_client.hub_client import HubClient
from jhub_apps.service.models import UserOptions, ServerCreation, Repository
from jhub_apps.service.utils import get_shared_servers
from jhub_apps.spawner.types import FRAMEWORKS, Framework
from jhub_apps.spawner.types import FRAMEWORKS
from jhub_apps.tests.common.constants import MOCK_USER

MOCK_ALLOW_ALL_FRAMEWORKS_CONFIG = Mock(
JAppsConfig=Mock(
allowed_frameworks=[f.name for f in FRAMEWORKS],
blocked_frameworks=[]
)
)


def mock_user_options():
user_options = {
Expand Down Expand Up @@ -67,11 +60,9 @@ def test_api_get_server_not_found(get_user, client):
}


@patch("jhub_apps.service.utils.get_jupyterhub_config")
@patch.object(HubClient, "create_server")
def test_api_create_server(create_server, get_jupyterhub_config, client):
def test_api_create_server(create_server, client):
from jhub_apps.service.models import UserOptions
get_jupyterhub_config.return_value = MOCK_ALLOW_ALL_FRAMEWORKS_CONFIG
create_server_response = {"user": "jovyan"}
create_server.return_value = create_server_response
user_options = mock_user_options()
Expand Down Expand Up @@ -141,11 +132,10 @@ def test_api_delete_server(delete_server, name, remove, client):
assert response.json() == create_server_response


@patch("jhub_apps.service.utils.get_jupyterhub_config")
@patch.object(HubClient, "edit_server")
def test_api_update_server(edit_server, get_jupyterhub_config, client):
def test_api_update_server(edit_server, client):
from jhub_apps.service.models import UserOptions
get_jupyterhub_config.return_value = MOCK_ALLOW_ALL_FRAMEWORKS_CONFIG

create_server_response = {"user": "jovyan"}
edit_server.return_value = create_server_response
user_options = mock_user_options()
Expand Down Expand Up @@ -206,27 +196,14 @@ def test_shared_server_filtering(hub_get_shared_servers, get_users):
get_users.assert_called_once_with()


@pytest.mark.parametrize("allowed_frameworks, blocked_frameworks,", [
([f.name for f in FRAMEWORKS if f.name != Framework.jupyterlab.name], []),
([f.name for f in FRAMEWORKS], []),
([], [Framework.jupyterlab.name]),
([Framework.panel.name], [Framework.bokeh.name]),
])
@patch("jhub_apps.service.routes.get_jupyterhub_config")
def test_api_frameworks(get_jupyterhub_config, client, allowed_frameworks, blocked_frameworks):
get_jupyterhub_config.return_value = Mock(
JAppsConfig=Mock(
allowed_frameworks=allowed_frameworks,
blocked_frameworks=blocked_frameworks
)
)

def test_api_frameworks(client):
response = client.get(
"/frameworks",
)
response_json = response.json()
returned_frameworks = {f["name"] for f in response_json}
assert returned_frameworks == set(allowed_frameworks) - set(blocked_frameworks)
frameworks = []
for framework in FRAMEWORKS:
frameworks.append(framework.json())
assert response.json() == frameworks


def test_api_status(client):
Expand All @@ -248,19 +225,11 @@ def test_open_api_docs(client):
assert rjson['info']['version']


@patch("jhub_apps.service.utils.get_jupyterhub_config")
@patch.object(HubClient, "create_server")
def test_create_server_with_git_repository(
hub_create_server,
get_jupyterhub_config,
client,
):
get_jupyterhub_config.return_value = Mock(
JAppsConfig=Mock(
allowed_frameworks=[f.name for f in FRAMEWORKS],
blocked_frameworks=[]
)
)
user_options = UserOptions(
jhub_app=True,
display_name="Test Application",
Expand Down
Loading
Loading