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
5 changes: 4 additions & 1 deletion dbuild/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,12 @@ def _enrich_metadata(cfg: Config, community_override: str | None = None) -> dict
}
for v in cfg.variants
],
# The tag fjord installs: latest when a variant is tagged latest or
# the default carries it, else the default variant, not the first.
"default_tag": next(
(a for v in cfg.variants if v.default for a in ["latest"] if a in v.aliases),
cfg.variants[0].tag if cfg.variants else "latest",
"latest" if any(v.tag == "latest" for v in cfg.variants)
else next((v.tag for v in cfg.variants if v.default), cfg.variants[0].tag if cfg.variants else "latest"),
),
"architectures": cfg.architectures,
"appjail": appjail_meta,
Expand Down
2 changes: 1 addition & 1 deletion dbuild/templates/README.mkdocs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Save the files above, then run `appjail-director up`.
{% block frontmatter -%}
---
title: "Run {{ title }} on FreeBSD — Native OCI Container"
description: "{{ description }} Built natively for FreeBSD with s6 supervision, PUID/PGID support, and CI-tested on every release."
description: "{{ description }} Built natively for FreeBSD with PUID/PGID support and CI-tested on every release."
---
{% endblock %}

Expand Down
45 changes: 45 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,51 @@ def test_service_image_gets_one_way_per_runtime(self):
self.assertNotIn(gone, readme)


class TestReadmeDefaultTag(unittest.TestCase):
"""The README's image tag is the default variant's when no latest is published."""

def _readme(self, variants: str) -> str:
with tempfile.TemporaryDirectory() as d:
repo = Path(d)
(repo / ".daemonless").mkdir()
(repo / "compose.yaml").write_text(COMPOSE_YAML.format(name="testapp").replace(" docs: manual\n", ""))
(repo / "Containerfile.j2").write_text(CONTAINERFILE_J2)
(repo / ".daemonless" / "config.yaml").write_text("build:\n variants:\n" + variants)
with _chdir(repo):
cfg = dbuild_config.load(repo)
self.assertEqual(docs.run(cfg, argparse.Namespace(community=None)), 0)
return (repo / "README.md").read_text()

def test_default_variant_without_latest(self):
readme = self._readme(
" - tag: \"15\"\n"
" - tag: 15-latest\n"
" default: true\n"
)
self.assertIn(':15-latest"', readme)
self.assertNotIn(':15"', readme)

def test_latest_alias_on_the_default_wins(self):
readme = self._readme(
" - tag: pkg\n"
" default: true\n"
" aliases: [\"latest\"]\n"
)
self.assertIn(':latest"', readme)

def test_a_latest_variant_wins_over_the_default(self):
readme = self._readme(
" - tag: latest\n"
" - tag: pkg\n"
" default: true\n"
)
self.assertIn(':latest"', readme)

def test_no_default_falls_back_to_the_first(self):
readme = self._readme(" - tag: \"15\"\n - tag: \"16\"\n")
self.assertIn(':15"', readme)


class TestReadmeWithSidecar(unittest.TestCase):
"""An app shipped with its database is documented as its real compose.

Expand Down
Loading