docs_site¶
Builds the mkdocs documentation site from a private GitHub repository and
serves the static output via nginx. Structurally mirrors react_frontend
(clone at a ref, build, symlink output, hand ownership to www-data), but
the build toolchain is uv/uvx (matching fastapi_backend), not
Node/npm — there's no nvm/package-manager step here, and no SPA
fallback in the nginx vhost, since a mkdocs site is a plain static
multi-page site, not a client-side-routed app.
What it does¶
Everything runs as root (the play's default become user) so that
redeploys stay idempotent even though the last step hands ownership to
www-data — see react_frontend/tasks/main.yml's comment for why the
same pattern is used here.
- Ensures
/home/<username>/projects/<docs_site_server_name>exists (the site root). - Resolves which ref to deploy — same rule as
fastapi_backend/react_frontend:docs_site_use_release_tag: true(production convention) deploysdocs_site_release_tagif pinned, else the repo's latest GitHub release tag (fails if none exists);false(default, staging convention) deploysdocs_site_git_branch. - Clones/pulls
docs_site_repoover HTTPS using a GitHub token embedded in the URL (no_log: true, token never logged) at the ref resolved above. - Installs
uvto~/.local/binif not already present (idempotent —creates:skips it iffastapi_backendalready installed it on this host). - Runs
uvx --with mkdocs-material mkdocs build --strict -f mkdocs.ymlfromdocs_site_repo_subdirwithin the clone (defaultdocs, this monorepo's actual docs directory). - Symlinks
<site_root>/site -> <build_root>/<docs_site_build_dir>whenever that doesn't already resolve to<site_root>/siteon its own — the nginx template always serves<site_root>/site. - Recursively chowns the site root to
www-dataso nginx can read it — this is the last task withtags: deploy, done every deploy run. - Templates the HTTPS vhost (plain static-file serving,
try_files $uri $uri/ =404;— mkdocs' "pretty URL" pages are already real<page>/index.htmlfiles on disk, no rewrite needed) and reloads nginx.
Variables¶
| Variable | Required | Default | Description |
|---|---|---|---|
docs_site_repo |
yes | — | GitHub repo, org/name form (private, HTTPS). |
docs_site_repo_subdir |
no | docs |
Path within the cloned repo where the mkdocs project lives. The build command and the site symlink both resolve against <site_root>/<repo_subdir>. |
docs_site_server_name |
yes | — | Public domain; also used for the site root path. Certificate must already exist (run register_ssl first). |
docs_site_app_name |
no | docs_site_server_name |
Currently informational only (no systemd unit — this role has no long-running process). |
docs_site_use_release_tag |
no | false |
true deploys a GitHub release tag instead of a branch — the production convention. |
docs_site_release_tag |
no | unset (auto-resolve latest) | Pins a specific tag instead of "whatever's latest" — how you roll back. Only used when docs_site_use_release_tag: true. |
docs_site_git_branch |
no | main |
Branch/ref to check out. Only used when docs_site_use_release_tag: false. |
docs_site_build_dir |
no | site |
Where mkdocs build writes its output, relative to the mkdocs project root — must match mkdocs.yml's own site_dir. |
docs_site_github_token |
no | the play's github_token |
Overrides the GitHub PAT used to clone this specific app, for when it lives in a different org/repo than the shared token covers. |
Requirements¶
- A GitHub Personal Access Token (repo read scope) available as the
play-level
github_tokenvar or passed per-invocation viadocs_site_github_token. Ifdocs_site_use_release_tag: true, that token also needs read access to the repo's Releases (the samereposcope covers this). - If
docs_site_use_release_tag: true, the repo needs at least one GitHub Release published — the role fails with a clear message otherwise. register_sslmust have run fordocs_site_server_namefirst.
Example¶
- role: register_ssl
tags: [docs, certs]
register_ssl_server_name: docs.barrins-codex.org
register_ssl_contact_name: admin@example.com
- role: docs_site
tags: [docs, deploy]
docs_site_repo: my-org/my-monorepo
docs_site_server_name: docs.barrins-codex.org