Skip to content

Commit

Permalink
SS-1260 extend the custom start url functionality to dash apps (#270)
Browse files Browse the repository at this point in the history
Extend the advanced setting option to the Dash apps as in SS-1176
Source: https://scilifelab.atlassian.net/browse/SS-1260
  • Loading branch information
anondo1969 authored Jan 22, 2025
1 parent 19f42c1 commit 1a7f941
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN apk add --update --no-cache \
curl

# Install Poetry, change configs and install packages.
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python3 - \
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=2.0.0 python3 - \
&& /root/.local/bin/poetry self add poetry-plugin-export \
&& /root/.local/bin/poetry config virtualenvs.create false \
&& /root/.local/bin/poetry config installer.max-workers 10 \
Expand Down
27 changes: 27 additions & 0 deletions apps/forms/dash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from crispy_forms.bootstrap import Accordion, AccordionGroup, PrependedText
from crispy_forms.layout import HTML, Div, Field, Layout
from django import forms
from django.core.exceptions import ValidationError
from django.urls import reverse
from django.utils.safestring import mark_safe

from apps.forms.base import AppBaseForm
from apps.forms.field.common import SRVCommonDivField
Expand All @@ -13,11 +17,22 @@ class DashForm(AppBaseForm):
flavor = forms.ModelChoiceField(queryset=Flavor.objects.none(), required=False, empty_label=None)
port = forms.IntegerField(min_value=3000, max_value=9999, required=True)
image = forms.CharField(max_length=255, required=True)
default_url_subpath = forms.CharField(max_length=255, required=False, label="Custom URL subpath")

def _setup_form_fields(self):
# Handle Volume field
super()._setup_form_fields()

self.fields["default_url_subpath"].widget.attrs.update({"class": "textinput form-control"})
self.fields["default_url_subpath"].help_text = "Specify a non-default start URL if your app requires that."
apps_url = reverse("portal:apps")
self.fields["default_url_subpath"].bottom_help_text = mark_safe(
(
f"<span class='fw-bold'>Note:</span> This changes the URL connected to the Open button for an app"
f" on the Serve <a href='{apps_url}'>Apps & Models</a> page."
)
)

def _setup_form_helper(self):
super()._setup_form_helper()
body = Div(
Expand All @@ -36,6 +51,17 @@ def _setup_form_helper(self):
SRVCommonDivField("source_code_url", placeholder="Provide a link to the public source code"),
SRVCommonDivField("port", placeholder="8000"),
SRVCommonDivField("image", placeholder="e.g. docker.io/username/image-name:image-tag"),
Accordion(
AccordionGroup(
"Advanced settings",
PrependedText(
"default_url_subpath",
mark_safe("<span id='id_custom_default_url_prepend'>Subdomain/</span>"),
template="apps/partials/srv_prepend_append_input_group.html",
),
active=False,
),
),
css_class="card-body",
)

Expand All @@ -53,6 +79,7 @@ class Meta:
"port",
"image",
"tags",
"default_url_subpath",
]
labels = {
"tags": "Keywords",
Expand Down
23 changes: 23 additions & 0 deletions apps/migrations/0021_dashinstance_default_url_subpath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2025-01-19 19:45

import apps.models.app_types.custom.custom
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("apps", "0020_alter_jupyterinstance_environment_and_more"),
]

operations = [
migrations.AddField(
model_name="dashinstance",
name="default_url_subpath",
field=models.CharField(
blank=True,
default="",
max_length=255,
validators=[apps.models.app_types.custom.custom.validate_default_url_subpath],
),
),
]
4 changes: 4 additions & 0 deletions apps/models/app_types/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
LogsEnabledMixin,
SocialMixin,
)
from apps.models.app_types.custom.custom import validate_default_url_subpath


class DashInstanceManager(AppInstanceManager):
model_type = "dashinstance"


class DashInstance(BaseAppInstance, SocialMixin, LogsEnabledMixin):
default_url_subpath = models.CharField(
validators=[validate_default_url_subpath], max_length=255, default="", blank=True
)
objects = DashInstanceManager()
ACCESS_TYPES = (
("project", "Project"),
Expand Down
8 changes: 7 additions & 1 deletion cypress/e2e/ui-tests/test-deploy-app.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ describe("Test deploying app", () => {
const image_port = "8000"
const createResources = Cypress.env('create_resources');
const app_type = "Dash App"
const default_url_subpath = "default/url/subpath/"


if (createResources === true) {
// Create Dash app
Expand All @@ -374,6 +376,9 @@ describe("Test deploying app", () => {
cy.get('#id_source_code_url').type(source_code_url)
cy.get('#id_image').clear().type(image_name)
cy.get('#id_port').clear().type(image_port)
cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').clear().type(default_url_subpath) // provide default_url_subpath

cy.get('#submit-id-submit').contains('Submit').click()
// Back on project page
cy.url().should("not.include", "/apps/settings")
Expand All @@ -392,7 +397,8 @@ describe("Test deploying app", () => {
cy.get('#id_access').find(':selected').should('contain', 'Public')
cy.get('#id_image').should('have.value', image_name)
cy.get('#id_port').should('have.value', image_port)

cy.get('button.accordion-button.collapsed[data-bs-target="#advanced-settings"]').click(); // Go to Advanced settings
cy.get('#id_default_url_subpath').should('have.value', default_url_subpath)
// Delete the Dash app
cy.logf("Deleting the dash app", Cypress.currentTest)
cy.visit("/projects/")
Expand Down

0 comments on commit 1a7f941

Please sign in to comment.