Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions dbuild/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

# Constants for placeholder generation
CONFIG_ROOT_VAR = "@CONTAINER_CONFIG_ROOT@"
# The config root a sample path starts with: /containers, or the fleet's
# /path/to/containers -- all of it, or the page keeps /path/to in front.
CONFIG_ROOT_RE = r"(?<![\w.-])(?:/path/to)?/containers(?=/)"
SHARED_PATHS = ["/downloads", "/movies", "/tv", "/music", "/books", "/media"]

HEADER_TEMPLATE = """# --------------------------------------------------------------------------
Expand Down Expand Up @@ -307,7 +310,7 @@ def _site_placeholders(text: str, env_file: bool = False) -> str:
"""
if not text:
return ""
text = re.sub(r"/containers(?=/)", CONFIG_ROOT_VAR, text)
text = re.sub(CONFIG_ROOT_RE, CONFIG_ROOT_VAR, text)
text = re.sub(r"(?m)(\bPUID=)1000\b", r"\g<1>@PUID@", text)
text = re.sub(r"(?m)(\bPGID=)1000\b", r"\g<1>@PGID@", text)
if env_file:
Expand Down Expand Up @@ -514,7 +517,7 @@ def _choice_context(cfg: Config, context_env: list[dict[str, Any]]) -> dict[str,
k, _, v = ln.partition("=")
if k.endswith("_LOCATION") and v and v not in folders:
folders.append(v)
folders = [f.replace("/containers", "@CONTAINER_CONFIG_ROOT@") for f in folders]
folders = [_re.sub(CONFIG_ROOT_RE, CONFIG_ROOT_VAR, f) for f in folders]
director_text = director_env_text = ""
if authored is not None:
sliced = _director_for_option(authored, cfg, None if is_default else opts)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ def test_repo_compose_and_env_get_site_placeholders(self):
"CONFIG_LOCATION=@CONTAINER_CONFIG_ROOT@/app\nTZ=@TZ@\n")
assert _site_placeholders("") == ""

def test_the_whole_fleet_root_becomes_the_placeholder(self):
# 122 composes write /path/to/containers/<app>: only /containers was
# swapped, so the page showed /path/to@CONTAINER_CONFIG_ROOT@/<app>.
from dbuild.docs import _site_placeholders
compose = " - /path/to/containers/uptime-kuma:/config\n"
assert _site_placeholders(compose) == " - @CONTAINER_CONFIG_ROOT@/uptime-kuma:/config\n"
env = "DB_LOCATION=/path/to/containers/app/db\n"
assert _site_placeholders(env, env_file=True) == "DB_LOCATION=@CONTAINER_CONFIG_ROOT@/app/db\n"
assert _site_placeholders(" - /srv/containers/x:/x\n") == " - /srv/containers/x:/x\n", "only at a path's start"


# ── Stack choices ──────────────────────────────────────────────────────

Expand Down
Loading