diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index d00ab45..7167387 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,8 +2,6 @@
- Use Gitea issues for work items and milestones for release planning.
- Start changes on a dedicated branch from the default branch, named main.
-- Keep related commits on the same branch and open one pull request when they
- form a coherent change that can be reviewed and verified together.
- Reference the relevant issue in the pull request and describe what changed and
how it was verified.
- Submit changes for review before merging into main.
diff --git a/docs/development.md b/docs/development.md
index c154fc9..38615bb 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -48,6 +48,25 @@ to RabbitMQ. After a broker outage, queued requests resume when the worker and
scheduler reconnect. Plans that remain incomplete five minutes after dispatch
are eligible for delivery again.
+## Render configuration on a web node
+
+Open a completed preview for the account's current domain and select **Download
+deployment manifest**. The versioned JSON file contains the account ID and
+primary domain. The web node command validates those values and derives the
+system user, document root, and PHP-FPM socket from the account ID.
+
+Install the panel package on the node at the same revision as the panel that
+created the manifest. The command renders configuration to standard output.
+Run it as a regular user in a directory for reviewing the generated files.
+
+```sh
+coulobre-web-node render coulobre-web-plan-1.json apache > apache.conf
+coulobre-web-node render coulobre-web-plan-1.json php-fpm > php-fpm.conf
+```
+
+The command reads the manifest and packaged templates locally. The isolated
+Ubuntu check below demonstrates loading the configuration.
+
## Run an isolated PHP test site
Open a completed preview for the account's current domain and select **Download
diff --git a/pyproject.toml b/pyproject.toml
index a7366e3..77c8fcc 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,6 +15,9 @@ dependencies = [
"idna>=3,<4",
]
+[project.scripts]
+coulobre-web-node = "coulobre.web_node:main"
+
[project.optional-dependencies]
dev = ["ruff>=0.11,<1"]
mariadb = ["mysqlclient>=2.2.1,<3"]
diff --git a/src/coulobre/domain_names.py b/src/coulobre/domain_names.py
new file mode 100644
index 0000000..3d122d8
--- /dev/null
+++ b/src/coulobre/domain_names.py
@@ -0,0 +1,16 @@
+import idna
+from django.core.exceptions import ValidationError
+from django.core.validators import DomainNameValidator
+
+validate_domain = DomainNameValidator(accept_idna=False)
+
+
+def canonical_domain(value):
+ try:
+ domain = (
+ idna.encode(value.strip(), uts46=True).decode("ascii").removesuffix(".")
+ )
+ validate_domain(domain)
+ except (idna.IDNAError, ValidationError) as error:
+ raise ValueError("Enter a valid domain name.") from error
+ return domain
diff --git a/src/coulobre/hosting/fields.py b/src/coulobre/hosting/fields.py
index 7b63e5f..7c144c8 100644
--- a/src/coulobre/hosting/fields.py
+++ b/src/coulobre/hosting/fields.py
@@ -1,9 +1,7 @@
-import idna
from django.core.exceptions import ValidationError
-from django.core.validators import DomainNameValidator
from django.db import models
-validate_domain = DomainNameValidator(accept_idna=False)
+from coulobre.domain_names import canonical_domain, validate_domain
class DomainNameField(models.CharField):
@@ -15,10 +13,6 @@ class DomainNameField(models.CharField):
return value
try:
- domain = idna.encode(value.strip(), uts46=True).decode("ascii")
- except idna.IDNAError as error:
+ return canonical_domain(value)
+ except ValueError as error:
raise ValidationError(validate_domain.message, code="invalid") from error
-
- domain = domain.removesuffix(".")
- validate_domain(domain)
- return domain
diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py
index a403f47..fd4cf6b 100644
--- a/src/coulobre/hosting/tasks.py
+++ b/src/coulobre/hosting/tasks.py
@@ -2,11 +2,11 @@ from datetime import timedelta
from celery import shared_task
from django.db.models import Q
-from django.template.loader import render_to_string
from django.utils import timezone
+from coulobre.web_node import WebSite
+
from .models import WebProvisioningPlan
-from .web_node import web_site_configuration
REDISPATCH_AFTER = timedelta(minutes=5)
@@ -37,7 +37,5 @@ def render_web_plan(plan_id):
if plan is None:
return
- apache_config = render_to_string(
- "hosting/apache-vhost.conf", web_site_configuration(plan)
- )
+ apache_config = WebSite(plan.account_id, plan.primary_domain).render("apache")
pending.update(apache_config=apache_config, completed_at=timezone.now())
diff --git a/src/coulobre/hosting/templates/hosting/apache-vhost.conf b/src/coulobre/hosting/templates/hosting/apache-vhost.conf
index adeef4c..3098aee 100644
--- a/src/coulobre/hosting/templates/hosting/apache-vhost.conf
+++ b/src/coulobre/hosting/templates/hosting/apache-vhost.conf
@@ -1,14 +1,14 @@
Virtual host configuration
{% if plan.can_export %}
- Download test bundle
+
{% endif %}
{{ plan.apache_config }}
diff --git a/src/coulobre/hosting/test_web_node.py b/src/coulobre/hosting/test_web_node.py
index fbeb175..825c133 100644
--- a/src/coulobre/hosting/test_web_node.py
+++ b/src/coulobre/hosting/test_web_node.py
@@ -6,6 +6,8 @@ from django.contrib.auth import get_user_model
from django.test import TestCase
from django.urls import reverse
+from coulobre.web_node import WebSite
+
from .models import HostingAccount, WebProvisioningPlan
from .tasks import render_web_plan
@@ -25,6 +27,9 @@ class WebSmokeBundleTests(TestCase):
def setUp(self):
self.client.force_login(self.operator)
self.download = reverse("panel:download_smoke_bundle", args=[self.plan.pk])
+ self.manifest = reverse(
+ "panel:download_deployment_manifest", args=[self.plan.pk]
+ )
def test_export_uses_the_reviewed_preview_and_matching_php_fpm_settings(self):
render_web_plan.run(self.plan.pk)
@@ -57,17 +62,44 @@ class WebSmokeBundleTests(TestCase):
def test_pending_and_stale_previews_cannot_be_exported(self):
self.assertEqual(self.client.get(self.download).status_code, 409)
+ self.assertEqual(self.client.get(self.manifest).status_code, 409)
render_web_plan.run(self.plan.pk)
HostingAccount.objects.filter(pk=self.account.pk).update(
primary_domain="updated.example"
)
self.assertEqual(self.client.get(self.download).status_code, 409)
+ self.assertEqual(self.client.get(self.manifest).status_code, 409)
detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
self.assertNotContains(detail, "Download test bundle")
+ self.assertNotContains(detail, "Download deployment manifest")
def test_download_requires_plan_view_permission(self):
render_web_plan.run(self.plan.pk)
self.client.force_login(self.viewer)
self.assertEqual(self.client.get(self.download).status_code, 403)
+ self.assertEqual(self.client.get(self.manifest).status_code, 403)
+
+ def test_manifest_reproduces_preview_and_pool_on_the_node(self):
+ render_web_plan.run(self.plan.pk)
+
+ detail = self.client.get(reverse("panel:plan", args=[self.plan.pk]))
+ self.assertContains(detail, "Download deployment manifest")
+ response = self.client.get(self.manifest)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn(".json", response["Content-Disposition"])
+ self.assertEqual(
+ response.json(),
+ {"version": 1, "account_id": self.account.pk, "domain": "example.org"},
+ )
+
+ self.plan.refresh_from_db()
+ site = WebSite.from_manifest(response.json())
+ self.assertEqual(site.render("apache"), self.plan.apache_config)
+ bundle = self.client.get(self.download)
+ with tarfile.open(fileobj=BytesIO(bundle.content)) as archive:
+ self.assertEqual(
+ site.render("php-fpm"),
+ archive.extractfile("php-fpm.conf").read().decode(),
+ )
diff --git a/src/coulobre/hosting/test_web_node_manifest.py b/src/coulobre/hosting/test_web_node_manifest.py
new file mode 100644
index 0000000..8722d75
--- /dev/null
+++ b/src/coulobre/hosting/test_web_node_manifest.py
@@ -0,0 +1,34 @@
+from django.test import SimpleTestCase
+
+from coulobre.web_node import WebSite
+
+
+class WebSiteManifestTests(SimpleTestCase):
+ def test_manifest_derives_paths_and_canonicalizes_the_domain(self):
+ site = WebSite.from_manifest(
+ {"version": 1, "account_id": 42, "domain": "BÜCHER.example."}
+ )
+
+ self.assertEqual(site.manifest()["domain"], "xn--bcher-kva.example")
+ self.assertIn(
+ 'DocumentRoot "/srv/coulobre/web/42/public"', site.render("apache")
+ )
+ self.assertIn('FilesMatch "\\.php$"', site.render("apache"))
+ self.assertIn("listen = /run/php/coulobre-42.sock", site.render("php-fpm"))
+
+ def test_manifest_rejects_wrong_versions_and_untrusted_configuration(self):
+ manifest = {"version": 1, "account_id": 42, "domain": "example.org"}
+ invalid = (
+ {"version": 2},
+ {"version": True},
+ {"account_id": True},
+ {"account_id": -1},
+ {"account_id": 2**63},
+ {"account_id": "../../etc"},
+ {"domain": "example.org\nServerAlias *"},
+ {"domain": "localhost"},
+ {"document_root": "/tmp"},
+ )
+ for change in invalid:
+ with self.subTest(change=change), self.assertRaises(ValueError):
+ WebSite.from_manifest(manifest | change)
diff --git a/src/coulobre/hosting/urls.py b/src/coulobre/hosting/urls.py
index f4a313a..71f798b 100644
--- a/src/coulobre/hosting/urls.py
+++ b/src/coulobre/hosting/urls.py
@@ -26,7 +26,12 @@ urlpatterns = [
path("plans/