ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(templates): the deploy drawer's domain promise now sticks
Juan Denisfb8d6bfbf832
diff --git a/backend/app/api/templates.py b/backend/app/api/templates.pyindex 47c3ea6e..5ade2059 100644--- a/backend/app/api/templates.py+++ b/backend/app/api/templates.py@@ -333,6 +333,10 @@ def install_template(template_id):user_variables = data.get('variables', {})server_id = data.get('server_id') or data.get('target_server_id')wait = bool(data.get('wait', False))+ # The deploy drawer sends true when it showed the operator a+ # <name>.<base> hostname — that promise must not depend on the+ # template YAML having opted in. Absent means the template decides.+ auto_domain = data.get('auto_domain')result = DeploymentJobService.install_template(template_id=template_id,@@ -341,6 +345,7 @@ def install_template(template_id):user_id=current_user_id,server_id=server_id,wait=wait,+ auto_domain=None if auto_domain is None else bool(auto_domain),)if not result.get('success'):diff --git a/backend/app/services/deployment_job_service.py b/backend/app/services/deployment_job_service.pyindex 3585894f..a4cc6d0f 100644--- a/backend/app/services/deployment_job_service.py+++ b/backend/app/services/deployment_job_service.py@@ -38,6 +38,7 @@ class DeploymentJobService:user_id: int = None,server_id: Optional[str] = None,wait: bool = False,+ auto_domain: Optional[bool] = None,) -> Dict:"""Create a template installation job and optionally run it synchronously."""normalized_server_id = cls._normalize_server_id(server_id)@@ -62,6 +63,7 @@ class DeploymentJobService:user_variables=user_variables or {},user_id=user_id,server_id=normalized_server_id,+ auto_domain=auto_domain,)if not plan_result.get('success'):return plan_resultdiff --git a/backend/app/services/template_service.py b/backend/app/services/template_service.pyindex 6b0f58c6..87f22a69 100644--- a/backend/app/services/template_service.py+++ b/backend/app/services/template_service.py@@ -1587,16 +1587,30 @@ class TemplateService:@classmethoddef build_install_plan(cls, template_id: str, app_name: str,user_variables: Dict = None, user_id: int = None,- server_id: str = None) -> Dict:+ server_id: str = None,+ auto_domain: bool = None) -> Dict:"""Build a reusable deployment plan for installing a template.The returned plan can be executed locally or by a connected agent.++ ``auto_domain=True`` opts this install into subdomain publishing even+ when the template YAML doesn't — the deploy drawer shows the operator+ the exact <name>.<base> hostname before they click Deploy, and a+ promise shown on screen must not silently depend on a per-template+ flag they can't see (the install landed on host:port instead, which a+ default firewall doesn't even expose). ``None`` keeps the template's+ own say."""result = cls.get_template(template_id)if not result.get('success'):return resulttemplate = result['template']+ if auto_domain and not template.get('auto_domain'):+ # Copy, not mutate — get_template may serve this dict to others.+ # Downstream (FQDN magic context, plan flag, finalizer) all read+ # the template flag, so opting in here opts in everywhere.+ template = {**template, 'auto_domain': True}variables_result = cls._prepare_install_variables(template_id,template,@@ -1700,6 +1714,7 @@ class TemplateService:'variables': variables,'port': app_port,'server_id': server_id,+ 'auto_domain': bool(template.get('auto_domain')),'steps': steps,},'template': template,diff --git a/backend/tests/test_template_auto_domain.py b/backend/tests/test_template_auto_domain.pynew file mode 100644index 00000000..7f057f0a--- /dev/null+++ b/backend/tests/test_template_auto_domain.py@@ -0,0 +1,90 @@+"""The deploy drawer's domain promise must be the install's contract.++The drawer shows the operator the exact ``<name>.<base>`` hostname before they+click Deploy ("Published automatically once the deploy finishes"). Publishing,+however, was gated on a per-template ``auto_domain: true`` flag the operator+cannot see — so for most of the catalog the install silently landed on+``host:port`` instead (which a default firewall doesn't even expose), and the+domain had to be redone by hand in the service's settings.++These tests pin the fix: the install request can opt in explicitly, the flag+rides the plan to the finalizer, and an absent flag still lets the template+YAML decide.+"""++import pytest++from app.services.template_service import TemplateService++# A real bundled catalog template that does NOT declare auto_domain — the+# common case the drawer was over-promising for.+TEMPLATE_ID = 'actualbudget'+++def plain_template(app):+ result = TemplateService.get_template(TEMPLATE_ID)+ assert result.get('success'), 'bundled template missing'+ assert not result['template'].get('auto_domain'), (+ 'test premise broken: template now opts in by itself')+ return result['template']+++class TestPlanFlag:+ def test_request_opt_in_reaches_the_plan(self, app, plain_template):+ result = TemplateService.build_install_plan(+ TEMPLATE_ID, 'promised-app', auto_domain=True)+ assert result['success'] is True+ assert result['plan']['auto_domain'] is True++ def test_without_a_request_flag_the_template_decides(self, app, plain_template):+ result = TemplateService.build_install_plan(+ TEMPLATE_ID, 'quiet-app')+ assert result['success'] is True+ assert result['plan']['auto_domain'] is False++ def test_the_cached_template_is_not_mutated(self, app, plain_template):+ TemplateService.build_install_plan(+ TEMPLATE_ID, 'copy-check-app', auto_domain=True)+ again = TemplateService.get_template(TEMPLATE_ID)['template']+ assert not again.get('auto_domain')+++class TestApiPassThrough:+ def test_install_endpoint_forwards_the_flag(self, app, client, auth_headers,+ monkeypatch):+ from app.services.deployment_job_service import DeploymentJobService+ seen = {}++ def fake_install(**kwargs):+ seen.update(kwargs)+ return {'success': True, 'job_id': 'j1',+ 'job': {'id': 'j1', 'status': 'pending'}}++ monkeypatch.setattr(DeploymentJobService, 'install_template',+ staticmethod(fake_install))+ res = client.post(f'/api/v1/templates/{TEMPLATE_ID}/install',+ headers=auth_headers,+ json={'app_name': 'promised-app',+ 'server_id': 'local', 'auto_domain': True})+ assert res.status_code in (201, 202), res.get_json()+ assert seen['auto_domain'] is True++ def test_absent_flag_stays_absent(self, app, client, auth_headers, monkeypatch):+ # None, not False: the service must be able to tell "the drawer said+ # nothing" apart from an explicit opt-out.+ from app.services.deployment_job_service import DeploymentJobService+ seen = {}++ def fake_install(**kwargs):+ seen.update(kwargs)+ return {'success': True, 'job_id': 'j2',+ 'job': {'id': 'j2', 'status': 'pending'}}++ monkeypatch.setattr(DeploymentJobService, 'install_template',+ staticmethod(fake_install))+ res = client.post(f'/api/v1/templates/{TEMPLATE_ID}/install',+ headers=auth_headers,+ json={'app_name': 'quiet-app', 'server_id': 'local'})+ assert res.status_code in (201, 202), res.get_json()+ assert seen['auto_domain'] is Nonediff --git a/frontend/src/pages/Templates.jsx b/frontend/src/pages/Templates.jsxindex ccacacac..53ffba95 100644--- a/frontend/src/pages/Templates.jsx+++ b/frontend/src/pages/Templates.jsx@@ -823,7 +823,15 @@ const InstallModal = ({ template, onClose, onSuccess, renderIcon }) => {return () => { cancelled = true; };}, [template.id, selectedServerId]);- const domainPreview = baseDomain && appName ? `${appName}.${baseDomain}` : null;+ // The promise is only shown when it can actually be kept: the finalizer+ // publishes <name>.<base> via the panel's own nginx, which can't proxy a+ // container on a remote server — and the repo pipeline has no auto-publish+ // step at all. Showing it and then landing on host:port is worse than not+ // offering it (the operator had to redo the domain in service settings).+ const selectedServer = servers.find((s) => s.id === selectedServerId);+ const isLocalTarget = selectedServerId === 'local' || !!selectedServer?.is_local;+ const domainPreview = baseDomain && appName && isLocalTarget && !isRepo+ ? `${appName}.${baseDomain}` : null;async function handleInstall(e) {e.preventDefault();@@ -871,9 +879,12 @@ const InstallModal = ({ template, onClose, onSuccess, renderIcon }) => {return;}- // Install+ // Install. When the drawer displayed a domain, the deploy must+ // deliver it — the backend honors this over the template's own+ // auto_domain flag, so the promise on screen is the contract.const result = await api.installTemplate(template.id, appName, variables, {- serverId: selectedServerId+ serverId: selectedServerId,+ autoDomain: domainPreview ? true : undefined,});if (result.success && result.job_id) {// Job started — hand off to the full-page Deploy Console.diff --git a/frontend/src/services/api/apps.js b/frontend/src/services/api/apps.jsindex e2386097..1de36f94 100644--- a/frontend/src/services/api/apps.js+++ b/frontend/src/services/api/apps.js@@ -317,15 +317,18 @@ export async function inspectTemplateManifest(templateId, branch = null) {}export async function installTemplate(templateId, appName, variables = {}, options = {}) {- return this.request(`/templates/${templateId}/install`, {- method: 'POST',- body: {- app_name: appName,- variables,- server_id: options.serverId || 'local',- wait: options.wait || false,- }- });+ const body = {+ app_name: appName,+ variables,+ server_id: options.serverId || 'local',+ wait: options.wait || false,+ };+ // Only sent when the drawer actually promised a <name>.<base> hostname;+ // omitted otherwise so the template's own auto_domain setting decides.+ if (options.autoDomain != null) {+ body.auto_domain = !!options.autoDomain;+ }+ return this.request(`/templates/${templateId}/install`, { method: 'POST', body });}export async function validateTemplateInstall(templateId, appName, variables = {}, serverId = null) {