diff --git a/DOCKER.md b/DOCKER.md index ebf3324e..1299c9ce 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -85,6 +85,8 @@ See [K8S.md](K8S.md) for the Kubernetes deployment. - `.env.docker`: committed dev defaults. `.env`: your overrides (git-ignored). - Add a site: add it to `UNGLEICH_SITE_CONFIGS` (a `Site` row is created on start). +- Show an existing site on another host (a demo domain): `UNGLEICH_SITE_ALIASES={"demo.example.org":"datacenterlight.ch"}`. + `migrate` creates the alias and the host is added to `ALLOWED_HOSTS`. Unknown hosts are redirected to datacenterlight.ch. - Web server tuning: `GUNICORN_WORKERS` (3), `GUNICORN_TIMEOUT` (120). - Sample data off: `SEED_DUMMY_DATA=False`. Remove it later: `docker compose exec web python manage.py seed_dummy_data --purge`. diff --git a/dynamicweb/management/commands/migrate.py b/dynamicweb/management/commands/migrate.py index af884bed..97eacbcc 100644 --- a/dynamicweb/management/commands/migrate.py +++ b/dynamicweb/management/commands/migrate.py @@ -5,7 +5,8 @@ It replaces Django's own "migrate", so "python manage.py migrate" is all that ha - skips the migration-history consistency check when it fails, as it does on old databases that record some migrations as applied before the (newer) migrations they now depend on - gives pages that have no tree node one (see give_orphan_pages_a_node) before cms 0020 -- makes sure every site in UNGLEICH_SITE_CONFIGS exists +- makes sure every site in UNGLEICH_SITE_CONFIGS exists, and every host in + UNGLEICH_SITE_ALIASES ({"alias host": "site domain"}) shows that site """ import json import os @@ -17,6 +18,7 @@ from django.db.migrations.executor import MigrationExecutor from django.db.migrations.exceptions import InconsistentMigrationHistory from django.db.migrations.loader import MigrationLoader from django.db.migrations.recorder import MigrationRecorder +from multisite.models import Alias REVERSION_SQUASH = '0001_squashed_0004_auto_20160611_1202' REVERSION_FIXES = ( @@ -52,6 +54,8 @@ class Command(migrate.Command): if not dry_run and not options["app_label"]: for domain in json.loads(os.environ.get('UNGLEICH_SITE_CONFIGS') or '{}'): Site.objects.get_or_create(domain=domain, defaults={'name': domain}) + for alias, domain in json.loads(os.environ.get('UNGLEICH_SITE_ALIASES') or '{}').items(): + Alias.objects.get_or_create(domain=alias, defaults={'site': Site.objects.get(domain=domain)}) @staticmethod def cms_tree_done(): diff --git a/dynamicweb/settings/prod.py b/dynamicweb/settings/prod.py index e67467ff..fee1fd93 100644 --- a/dynamicweb/settings/prod.py +++ b/dynamicweb/settings/prod.py @@ -26,3 +26,6 @@ ALLOWED_HOSTS = [ ".hack4glarus.ch", ".xn--nglarus-n2a.ch" ] + +# hosts that UNGLEICH_SITE_ALIASES maps onto a site are allowed as well +ALLOWED_HOSTS += list(json.loads(env('UNGLEICH_SITE_ALIASES', '{}')))