diff --git a/dbuild/docs.py b/dbuild/docs.py index 5655f75..4c2a841 100644 --- a/dbuild/docs.py +++ b/dbuild/docs.py @@ -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, diff --git a/dbuild/templates/README.mkdocs.j2 b/dbuild/templates/README.mkdocs.j2 index 542a4f3..08c1a9c 100644 --- a/dbuild/templates/README.mkdocs.j2 +++ b/dbuild/templates/README.mkdocs.j2 @@ -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 %} diff --git a/tests/test_docs.py b/tests/test_docs.py index 56ec24e..d3773f9 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -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.