mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-04 00:38:10 +00:00
chore(merge): merge upstream main into feature/web-app-openpost
This commit is contained in:
17 files changed
+268
-46
No files matched your search
@@ -164,7 +164,7 @@ Every invokable role in the tested lifecycle envelope, with its upstream homepag
|
||||
| [Redirector](roles/web-opt-rdr-domains/) | beta | NGINX glue role for 301 redirects from source to target domains with automatic SSL for the source hosts | [🛠️](roles/web-opt-rdr-domains/README.md#quick-setup) | |
|
||||
| [Redis](roles/svc-db-redis/) | beta | In-memory key-value cache and store, shared centrally with per-consumer ACL isolation or embedded as a sidecar | [🌐](https://redis.io/) [🛠️](roles/svc-db-redis/README.md#quick-setup) | [Tor Onion Service](roles/svc-net-tor/) |
|
||||
| [Roulette Wheel](roles/web-app-roulette-wheel/) | alpha | Browser-based spinning wheel app for decision making, random selection, and gamification | [🌐](https://github.com/p-wojt/roulette-wheel) [🛠️](roles/web-app-roulette-wheel/README.md#quick-setup) | [Corporate Design](roles/web-svc-css/), [Dashboard](roles/web-app-dashboard/), [Matomo](roles/web-app-matomo/), [Prometheus](roles/web-app-prometheus/), [Tor Onion Service](roles/svc-net-tor/) |
|
||||
| [SeaweedFS](roles/web-app-seaweedfs/) | beta | Distributed S3-compatible object store for shared, per-consumer bucket provisioning across web-app roles | [🌐](https://seaweedfs.org/) [🛠️](roles/web-app-seaweedfs/README.md#quick-setup) | [Backup Docker Volumes](roles/svc-bkp-volume-2-local/), [Dashboard](roles/web-app-dashboard/), [Keycloak](roles/web-app-keycloak/), [Prometheus](roles/web-app-prometheus/), [Universal Logout](roles/web-svc-logout/) |
|
||||
| [SeaweedFS](roles/web-app-seaweedfs/) | beta | Distributed S3-compatible object store for shared, per-consumer bucket provisioning across web-app roles | [🌐](https://seaweedfs.com/) [🛠️](roles/web-app-seaweedfs/README.md#quick-setup) | [Backup Docker Volumes](roles/svc-bkp-volume-2-local/), [Dashboard](roles/web-app-dashboard/), [Keycloak](roles/web-app-keycloak/), [Prometheus](roles/web-app-prometheus/), [Universal Logout](roles/web-svc-logout/) |
|
||||
| [Self-Hosted Runner](roles/svc-runner/) | beta | Self-hosted CI runner infrastructure for executing GitHub Actions workflow jobs in ephemeral Docker containers | [🌐](https://github.com/actions/runner) [🛠️](roles/svc-runner/README.md#quick-setup) | |
|
||||
| [Semaphore UI](roles/web-app-semaphore/) | beta | Web UI and API for running Ansible, Terraform/OpenTofu, and shell automation on a schedule or on demand | [🌐](https://semaphoreui.com/) [🎬](https://www.youtube.com/watch?v=nzR4yDuZQMU) [🛠️](roles/web-app-semaphore/README.md#quick-setup) | [Backup Docker Volumes](roles/svc-bkp-volume-2-local/), [Corporate Design](roles/web-svc-css/), [Dashboard](roles/web-app-dashboard/), [Keycloak](roles/web-app-keycloak/), [Matomo](roles/web-app-matomo/), [OpenLDAP](roles/svc-db-openldap/), [PostgreSQL](roles/svc-db-postgres/), [Prometheus](roles/web-app-prometheus/), [Stalwart Mail Server](roles/web-app-stalwart/), [Tor Onion Service](roles/svc-net-tor/), [Universal Logout](roles/web-svc-logout/) |
|
||||
| [Shopware](roles/web-app-shopware/) | beta | Open-source ecommerce platform built on Symfony and Vue.js for building and scaling online storefronts | [🌐](https://www.shopware.com/en/) [🎬](https://www.youtube.com/watch?v=bG57TZPYsyw) [🛠️](roles/web-app-shopware/README.md#quick-setup) | [Backup Docker Volumes](roles/svc-bkp-volume-2-local/), [Corporate Design](roles/web-svc-css/), [Dashboard](roles/web-app-dashboard/), [Keycloak](roles/web-app-keycloak/), [MariaDB](roles/svc-db-mariadb/), [Matomo](roles/web-app-matomo/), [OpenLDAP](roles/svc-db-openldap/), [Prometheus](roles/web-app-prometheus/), [Redis](roles/svc-db-redis/), [SeaweedFS](roles/web-app-seaweedfs/), [Stalwart Mail Server](roles/web-app-stalwart/), [Tor Onion Service](roles/svc-net-tor/), [Universal Logout](roles/web-svc-logout/) |
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from utils.domains.unserved import served_domains
|
||||
|
||||
|
||||
class FilterModule:
|
||||
def filters(self):
|
||||
return {"served_domains": served_domains}
|
||||
@@ -2,6 +2,7 @@ import sys
|
||||
from collections.abc import Mapping
|
||||
from pathlib import Path
|
||||
|
||||
from utils.domains.unserved import unserved_canonical_keys
|
||||
from utils.roles.applications.config import get
|
||||
from utils.roles.applications.status_codes import DEFAULT_OK, codes_by_key
|
||||
|
||||
@@ -164,17 +165,9 @@ def web_health_expectations(
|
||||
get(applications, app_id, "server.status_codes", strict=False, default={})
|
||||
)
|
||||
|
||||
suppressed = set()
|
||||
services_raw = get(applications, app_id, "services", strict=False, default={})
|
||||
if isinstance(services_raw, Mapping):
|
||||
for svc in services_raw.values():
|
||||
if not isinstance(svc, Mapping) or "domains" not in svc:
|
||||
continue
|
||||
if svc.get("enabled") and not svc.get("shared"):
|
||||
continue
|
||||
for key in _to_list(svc.get("domains"), allow_mapping=False):
|
||||
if key:
|
||||
suppressed.add(str(key))
|
||||
suppressed = unserved_canonical_keys(
|
||||
get(applications, app_id, "services", strict=False, default={})
|
||||
)
|
||||
|
||||
app_exp = {}
|
||||
if isinstance(canonical_raw, Mapping) and canonical_raw:
|
||||
|
||||
@@ -152,7 +152,7 @@ MDAD knobs are rendered from `templates/flavor/ansible/vars.yml.j2`. Central-ser
|
||||
|
||||
A `mount --make-rshared /` runs once in the deploy container before the runner starts, because MDAD's systemd units bind-mount `/matrix/synapse/storage` with `bind-propagation=slave`, which requires shared/slave propagation on the source.
|
||||
|
||||
**Federation.** Synapse serves the `client` and `federation` resources on one listener. OpenResty serves the Synapse domain on 443 and, as `default_server`, on `services.synapse.ports.public.federation`, and the role writes `/.well-known/matrix/server` as the compose flavor does. A server-name lookup that falls back to `<server_name>:8448` therefore lands on Synapse as well.
|
||||
**Federation.** Synapse serves the `client` and `federation` resources on one listener. OpenResty serves the Synapse domain on 443 and, as `default_server`, on `services.synapse.ports.public.federation`, and the role writes `/.well-known/matrix/server` into the well-known directory of its server name, which the redirect vhost of that domain (`web-opt-rdr-domains`) serves, so server discovery delegates to the Synapse domain on 443. The `<server_name>:8448` fallback only answers where OpenResty runs in the host network (compose); in swarm OpenResty publishes 80 and 443 only.
|
||||
|
||||
**Registry proxy.** When the stack's docker daemon pulls through a registry proxy (the local registry cache), the runner's nested daemon uses the same proxy via a `docker.service` drop-in and, when the outer daemon trusts the cache's CA, fetches that CA from the proxy before it starts.
|
||||
|
||||
|
||||
@@ -153,16 +153,8 @@
|
||||
proxy_internal_port: "{{ MATRIX_SYNAPSE_CONTAINER_PORT }}"
|
||||
notify: restart-openresty
|
||||
|
||||
- name: "📁 front-proxy: create {{ MATRIX_WELL_KNOWN_DIRECTORY }}"
|
||||
ansible.builtin.file:
|
||||
path: "{{ MATRIX_WELL_KNOWN_DIRECTORY }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: "📁 front-proxy: create {{ MATRIX_WELL_KNOWN_FILE }}"
|
||||
stack_host_template:
|
||||
src: "well-known.j2"
|
||||
dest: "{{ MATRIX_WELL_KNOWN_FILE }}"
|
||||
- name: "🔀 front-proxy: federation delegation"
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/well_known.yml"
|
||||
|
||||
- name: "🔀 front-proxy: Jitsi web"
|
||||
ansible.builtin.include_role:
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
---
|
||||
# include-gated: when: DEPLOYMENT_MODE == "compose"
|
||||
- name: 📁 create {{ MATRIX_WELL_KNOWN_DIRECTORY }}
|
||||
ansible.builtin.file:
|
||||
path: "{{ MATRIX_WELL_KNOWN_DIRECTORY }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: 📁 create {{ MATRIX_WELL_KNOWN_FILE }}
|
||||
stack_host_template:
|
||||
src: "well-known.j2"
|
||||
dest: "{{ MATRIX_WELL_KNOWN_FILE }}"
|
||||
- name: "🔀 federation delegation"
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/utils/well_known.yml"
|
||||
|
||||
- name: "📂 include role sys-stk-front-proxy for {{ MATRIX_ELEMENT_DOMAIN }}"
|
||||
ansible.builtin.include_role:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
- name: "📁 create {{ MATRIX_WELL_KNOWN_DIRECTORY }}"
|
||||
ansible.builtin.file:
|
||||
path: "{{ MATRIX_WELL_KNOWN_DIRECTORY }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: "📁 create {{ MATRIX_WELL_KNOWN_FILE }}"
|
||||
stack_host_template:
|
||||
src: "well-known.j2"
|
||||
dest: "{{ MATRIX_WELL_KNOWN_FILE }}"
|
||||
@@ -10,8 +10,8 @@ MATRIX_SERVER_NAME: "{{ MATRIX_ONION_NODE if (MATRIX_ONION_NODE and lookup('doma
|
||||
'services.matrix.server_name') }}"
|
||||
MATRIX_ADMINISTRATOR_USERNAME: "{{ lookup('users', 'administrator').username }}"
|
||||
MATRIX_ADMINISTRATOR_PASSWORD: "{{ lookup('users', 'administrator').password }}"
|
||||
MATRIX_WELL_KNOWN_DIRECTORY: "{{ [ lookup('nginx','directories.data.well_known'), 'matrix' ] | path_join }}"
|
||||
MATRIX_WELL_KNOWN_FILE: "{{ MATRIX_WELL_KNOWN_DIRECTORY }}server"
|
||||
MATRIX_WELL_KNOWN_DIRECTORY: "{{ [ lookup('nginx','directories.data.well_known'), MATRIX_SERVER_NAME, 'matrix' ] | path_join }}"
|
||||
MATRIX_WELL_KNOWN_FILE: "{{ [ MATRIX_WELL_KNOWN_DIRECTORY, 'server' ] | path_join }}"
|
||||
MATRIX_REGISTRATION_FILE_FOLDER: "/registrations/"
|
||||
MATRIX_BRIDGE_SOURCE_DIR: "{{ [ lookup('container', application_id, 'directories.config'), 'mautrix' ] | path_join }}"
|
||||
MATRIX_BRIDGE_CONFIG_TARGET: "/config/config.yaml"
|
||||
|
||||
@@ -51,8 +51,7 @@ scrape_configs:
|
||||
static_configs:
|
||||
{% for _application_id in CURRENT_PLAY_APPLICATIONS | list | sort %}
|
||||
{% if _application_id in probed_roles %}
|
||||
{% set domains_raw = canonical_map.get(_application_id, []) %}
|
||||
{% set canonical_probe_domains = (domains_raw.values() | list) if (domains_raw is mapping) else domains_raw %}
|
||||
{% set canonical_probe_domains = canonical_map.get(_application_id, []) | served_domains(lookup('config', _application_id, 'services')) %}
|
||||
{% if canonical_probe_domains | length > 0 %}
|
||||
- targets:
|
||||
{% for domain in canonical_probe_domains %}
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
# nocheck: info-media no official demo video
|
||||
logo:
|
||||
class: fa-solid fa-hard-drive
|
||||
homepage: https://seaweedfs.org/
|
||||
homepage: https://seaweedfs.com/
|
||||
@@ -13,7 +13,7 @@ socialhome:
|
||||
# nocheck: default-placement-manager embedded sqlite in a node-local volume; no clustered storage
|
||||
placement: manager
|
||||
image: ghcr.io/social-home-io/socialhome
|
||||
version: "2026.10.22"
|
||||
version: "2026.10.24"
|
||||
ports:
|
||||
local:
|
||||
http: 8089
|
||||
|
||||
@@ -24,6 +24,7 @@ Solid `1:1` edges are fixed relationships; dashed `0..1` edges are conditional (
|
||||
## Features
|
||||
|
||||
- **Automated provisioning:** Configured by Ansible without manual steps.
|
||||
- **Well-known passthrough:** every source domain serves the files of its own subdirectory `<domain>/` of the shared well-known directory (`lookup('nginx', 'directories.data.well_known')`) under `/.well-known/`; any other request, a missing well-known file included, gets the 301.
|
||||
|
||||
## Quick Setup
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ server {
|
||||
{% if web_opt_rdr_domains_logout_enabled | bool %}
|
||||
{% include 'roles/web-svc-logout/templates/logout-proxy.conf.j2' %}
|
||||
{% endif %}
|
||||
location ^~ /.well-known/ {
|
||||
alias {{ [ lookup('nginx', 'directories.data.well_known'), domain ] | path_join }}/;
|
||||
default_type application/json;
|
||||
error_page 403 404 = /;
|
||||
}
|
||||
location / {
|
||||
return 301 {{ lookup('tls', application_id, 'protocols.web') }}://{{ target }}$request_uri;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ from jinja2 import Environment, FileSystemLoader, StrictUndefined, select_autoes
|
||||
|
||||
from utils.cache.files import PROJECT_ROOT
|
||||
from utils.cache.yaml import load_yaml_str
|
||||
from utils.domains.unserved import served_domains
|
||||
|
||||
TEMPLATE_DIR = PROJECT_ROOT / "roles/web-app-prometheus/templates/configuration"
|
||||
ONION = "a" * 56 + ".onion"
|
||||
@@ -14,7 +15,11 @@ DOMAINS = {
|
||||
"web-app-prometheus": [f"prometheus.{ONION}"],
|
||||
"web-app-nextcloud": {"nextcloud": f"next.cloud.{ONION}"},
|
||||
"web-app-gitea": ["git.infinito.test"],
|
||||
"web-app-matrix": ["matrix.infinito.test"],
|
||||
"web-app-matrix": {
|
||||
"synapse": "matrix.infinito.test",
|
||||
"jitsi": "jitsi.matrix.infinito.test",
|
||||
"jitsi_onion": f"jitsi.matrix.{ONION}",
|
||||
},
|
||||
"web-svc-cdn": ["cdn.infinito.test"],
|
||||
"svc-db-postgres": ["postgres.infinito.test"],
|
||||
}
|
||||
@@ -28,12 +33,23 @@ ROLES_WITH_THE_PROMETHEUS_SERVICE = [
|
||||
"web-app-gitea",
|
||||
"web-app-matrix",
|
||||
]
|
||||
SHARED_JITSI = {"jitsi": {"enabled": True, "shared": True, "domains": ["jitsi"]}}
|
||||
|
||||
|
||||
def probed_groups(*, ca_injected: bool) -> dict[str, dict]:
|
||||
def probed_groups(
|
||||
*, ca_injected: bool, matrix_services: dict | None = None
|
||||
) -> dict[str, dict]:
|
||||
services = {
|
||||
"web-app-matrix": SHARED_JITSI if matrix_services is None else matrix_services
|
||||
}
|
||||
|
||||
def lookup(name, *terms, **_kwargs):
|
||||
if name == "domains":
|
||||
return DOMAINS
|
||||
if name == "config":
|
||||
app, key = terms
|
||||
assert key == "services"
|
||||
return services.get(app, {})
|
||||
if name == "roles_with_service":
|
||||
return [{"id": role} for role in ROLES_WITH_THE_PROMETHEUS_SERVICE]
|
||||
if name == "ca_injected":
|
||||
@@ -62,6 +78,7 @@ def probed_groups(*, ca_injected: bool) -> dict[str, dict]:
|
||||
autoescape=select_autoescape(),
|
||||
)
|
||||
env.filters["bool"] = bool
|
||||
env.filters["served_domains"] = served_domains
|
||||
rendered = env.get_template("prometheus.yml.j2").render(
|
||||
lookup=lookup,
|
||||
application_id="web-app-prometheus",
|
||||
@@ -76,9 +93,12 @@ def probed_groups(*, ca_injected: bool) -> dict[str, dict]:
|
||||
}
|
||||
|
||||
|
||||
def probed_targets() -> dict[str, list[str]]:
|
||||
def probed_targets(matrix_services: dict | None = None) -> dict[str, list[str]]:
|
||||
return {
|
||||
app: group["targets"] for app, group in probed_groups(ca_injected=True).items()
|
||||
app: group["targets"]
|
||||
for app, group in probed_groups(
|
||||
ca_injected=True, matrix_services=matrix_services
|
||||
).items()
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +115,30 @@ class TestBlackboxTargets(unittest.TestCase):
|
||||
["https://git.infinito.test/healthz/ready"],
|
||||
)
|
||||
|
||||
def test_a_shared_service_domain_and_its_onion_mirror_are_not_probed(self):
|
||||
self.assertEqual(
|
||||
probed_targets()["web-app-matrix"],
|
||||
["https://matrix.infinito.test/healthz/ready"],
|
||||
)
|
||||
|
||||
def test_a_disabled_service_domain_is_not_probed(self):
|
||||
disabled = {"jitsi": {"enabled": False, "shared": False, "domains": ["jitsi"]}}
|
||||
self.assertEqual(
|
||||
probed_targets(disabled)["web-app-matrix"],
|
||||
["https://matrix.infinito.test/healthz/ready"],
|
||||
)
|
||||
|
||||
def test_an_own_service_domain_is_probed(self):
|
||||
own = {"jitsi": {"enabled": True, "shared": False, "domains": ["jitsi"]}}
|
||||
self.assertEqual(
|
||||
probed_targets(own)["web-app-matrix"],
|
||||
[
|
||||
"https://matrix.infinito.test/healthz/ready",
|
||||
"https://jitsi.matrix.infinito.test/healthz/ready",
|
||||
f"http://jitsi.matrix.{ONION}/healthz/ready",
|
||||
],
|
||||
)
|
||||
|
||||
def test_only_the_roles_the_service_lookup_names_are_probed(self):
|
||||
self.assertEqual(set(probed_targets()), set(ROLES_WITH_THE_PROMETHEUS_SERVICE))
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ def _environment(
|
||||
mock.patch.object(mermaid_cli, "which", return_value=True),
|
||||
mock.patch.object(mermaid_cli.shutil, "which", return_value=str(mmdc)),
|
||||
mock.patch.object(mermaid_cli, "missing_libraries", return_value=[]),
|
||||
mock.patch.object(mermaid_cli, "fonts_installed", return_value=True),
|
||||
):
|
||||
yield Path(prefix), Path(cache)
|
||||
|
||||
@@ -348,7 +349,84 @@ class TestBrowserLibraries(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestBrowserFonts(unittest.TestCase):
|
||||
def ensure_fonts(self, *, manager: str, present: list[bool]) -> mock.Mock:
|
||||
"""Run the font step with a stubbed font check and package manager.
|
||||
|
||||
Args:
|
||||
manager: the package manager the host reports.
|
||||
present: successive ``fonts_installed`` results.
|
||||
|
||||
Returns:
|
||||
The stubbed ``run_privileged``.
|
||||
"""
|
||||
with (
|
||||
mock.patch.object(mermaid_cli, "fonts_installed", side_effect=present),
|
||||
mock.patch.object(
|
||||
mermaid_cli, "detect_package_manager", return_value=manager
|
||||
),
|
||||
mock.patch.object(mermaid_cli, "run_privileged") as privileged,
|
||||
):
|
||||
mermaid_cli._ensure_fonts()
|
||||
return privileged
|
||||
|
||||
def test_a_host_with_a_font_installs_nothing(self) -> None:
|
||||
privileged = self.ensure_fonts(manager="dnf", present=[True])
|
||||
privileged.assert_not_called()
|
||||
|
||||
def test_the_redhat_family_installs_the_english_font_provide(self) -> None:
|
||||
for manager in ("dnf", "yum"):
|
||||
with self.subTest(manager=manager):
|
||||
privileged = self.ensure_fonts(manager=manager, present=[False, True])
|
||||
privileged.assert_called_once_with(
|
||||
[manager, "-y", "install", "font(:lang=en)"]
|
||||
)
|
||||
|
||||
def test_arch_installs_the_ttf_font_provide(self) -> None:
|
||||
privileged = self.ensure_fonts(manager="pacman", present=[False, True])
|
||||
privileged.assert_called_once_with(
|
||||
["pacman", "-Syu", "--noconfirm", "--needed", "ttf-font"]
|
||||
)
|
||||
|
||||
def test_apt_without_a_font_fails_without_installing(self) -> None:
|
||||
with (
|
||||
mock.patch.object(mermaid_cli, "fonts_installed", return_value=False),
|
||||
mock.patch.object(
|
||||
mermaid_cli, "detect_package_manager", return_value="apt-get"
|
||||
),
|
||||
mock.patch.object(mermaid_cli, "run_privileged") as privileged,
|
||||
self.assertRaisesRegex(RuntimeError, "--install-deps"),
|
||||
):
|
||||
mermaid_cli._ensure_fonts()
|
||||
privileged.assert_not_called()
|
||||
|
||||
def test_no_font_after_the_install_raises(self) -> None:
|
||||
with self.assertRaisesRegex(RuntimeError, "still finds no font"):
|
||||
self.ensure_fonts(manager="dnf", present=[False, False])
|
||||
|
||||
def test_only_a_file_under_the_font_directory_counts(self) -> None:
|
||||
with TemporaryDirectory() as fonts:
|
||||
directory = Path(fonts)
|
||||
with mock.patch.object(mermaid_cli, "FONT_DIRECTORY", directory):
|
||||
(directory / "google-noto-vf").mkdir()
|
||||
self.assertFalse(mermaid_cli.fonts_installed())
|
||||
(directory / "google-noto-vf" / "NotoSans[wght].ttf").write_bytes(b"")
|
||||
self.assertTrue(mermaid_cli.fonts_installed())
|
||||
|
||||
def test_a_missing_font_directory_counts_as_no_font(self) -> None:
|
||||
with mock.patch.object(
|
||||
mermaid_cli, "FONT_DIRECTORY", Path("/nonexistent/fonts")
|
||||
):
|
||||
self.assertFalse(mermaid_cli.fonts_installed())
|
||||
|
||||
|
||||
class TestBrowserInstalled(unittest.TestCase):
|
||||
def test_a_browser_without_any_font_is_not_installed(self) -> None:
|
||||
with _environment() as (_, cache):
|
||||
_install_browser(cache, REVISION)
|
||||
with mock.patch.object(mermaid_cli, "fonts_installed", return_value=False):
|
||||
self.assertFalse(mermaid_cli.browser_installed())
|
||||
|
||||
def test_only_the_pinned_revision_counts(self) -> None:
|
||||
with _environment() as (_, cache):
|
||||
_install_browser(cache, "155.0.8059.79")
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
ONION_SUFFIX = "_onion"
|
||||
|
||||
|
||||
def unserved_canonical_keys(services: Any) -> set[str]:
|
||||
"""Return the canonical domain keys an application does not serve.
|
||||
|
||||
Args:
|
||||
services: the application's ``services`` mapping. An entity that lists
|
||||
``domains`` claims those canonical keys.
|
||||
|
||||
Returns:
|
||||
The keys of every claiming entity that is disabled, or enabled but
|
||||
shared, because its provider serves that surface instead.
|
||||
"""
|
||||
keys: set[str] = set()
|
||||
if not isinstance(services, Mapping):
|
||||
return keys
|
||||
for entity in services.values():
|
||||
if not isinstance(entity, Mapping) or "domains" not in entity:
|
||||
continue
|
||||
if entity.get("enabled") and not entity.get("shared"):
|
||||
continue
|
||||
claimed = entity.get("domains")
|
||||
if isinstance(claimed, str):
|
||||
claimed = [claimed]
|
||||
if not isinstance(claimed, (list, tuple)):
|
||||
continue
|
||||
keys.update(str(key) for key in claimed if key)
|
||||
return keys
|
||||
|
||||
|
||||
def served_domains(domains: Any, services: Any) -> list[str]:
|
||||
"""Return the domains of one application that it serves itself.
|
||||
|
||||
Args:
|
||||
domains: the application's entry of the resolved domains map, a list,
|
||||
or a mapping of canonical key to domain where onion mirrors sit
|
||||
under ``<key>_onion``.
|
||||
services: the application's ``services`` mapping.
|
||||
|
||||
Returns:
|
||||
The domain values without those of the keys
|
||||
``unserved_canonical_keys`` names and without their onion mirrors.
|
||||
"""
|
||||
if not isinstance(domains, Mapping):
|
||||
return [str(domain) for domain in (domains or [])]
|
||||
skipped = unserved_canonical_keys(services)
|
||||
served: list[str] = []
|
||||
for key, domain in domains.items():
|
||||
name = str(key)
|
||||
base = name.removesuffix(ONION_SUFFIX)
|
||||
if name in skipped or base in skipped:
|
||||
continue
|
||||
served.append(str(domain))
|
||||
return served
|
||||
@@ -5,8 +5,10 @@ provisioned afterwards through the puppeteer that npm installed next to mmdc,
|
||||
at the revision its puppeteer-core pins. ``unzip`` is ensured first because
|
||||
puppeteer extracts the browser with it. Puppeteer installs the browser's
|
||||
shared libraries only through apt-get (``--install-deps``); on dnf, yum and
|
||||
pacman the libraries ``ldd`` reports missing are installed by soname. Every
|
||||
failure aborts ``install-lint``.
|
||||
pacman the libraries ``ldd`` reports missing are installed by soname, and a
|
||||
font by the distribution's font provide, because the browser aborts in its
|
||||
font fallback (``SkFontMgr_FontConfigInterface ... Not implemented``) on a
|
||||
host without any font. Every failure aborts ``install-lint``.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -25,12 +27,20 @@ from utils.install.system_pkg import detect_package_manager, install_command_via
|
||||
BROWSER = "chrome-headless-shell"
|
||||
PROVISION_TIMEOUT_S = 900
|
||||
|
||||
FONT_DIRECTORY = Path("/usr/share/fonts")
|
||||
|
||||
_INSTALL_ARGV = {
|
||||
"dnf": ["dnf", "-y", "install"],
|
||||
"yum": ["yum", "-y", "install"],
|
||||
"pacman": ["pacman", "-Syu", "--noconfirm", "--needed"],
|
||||
}
|
||||
|
||||
_FONT_PROVIDES = {
|
||||
"dnf": "font(:lang=en)",
|
||||
"yum": "font(:lang=en)",
|
||||
"pacman": "ttf-font",
|
||||
}
|
||||
|
||||
|
||||
def _ensure_unzip() -> None:
|
||||
if not which("unzip"):
|
||||
@@ -110,9 +120,19 @@ def missing_libraries(executable: Path) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def fonts_installed() -> bool:
|
||||
return FONT_DIRECTORY.is_dir() and any(
|
||||
path.is_file() for path in FONT_DIRECTORY.rglob("*")
|
||||
)
|
||||
|
||||
|
||||
def browser_installed() -> bool:
|
||||
executable = browser_executable()
|
||||
return executable is not None and not missing_libraries(executable)
|
||||
return (
|
||||
executable is not None
|
||||
and not missing_libraries(executable)
|
||||
and fonts_installed()
|
||||
)
|
||||
|
||||
|
||||
def _provision_browser(puppeteer: Path) -> subprocess.CompletedProcess[str]:
|
||||
@@ -206,6 +226,26 @@ def _ensure_browser_libraries(executable: Path) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _ensure_fonts() -> None:
|
||||
if fonts_installed():
|
||||
return
|
||||
manager = detect_package_manager()
|
||||
provide = _FONT_PROVIDES.get(manager)
|
||||
if provide is None:
|
||||
raise RuntimeError(
|
||||
f"{BROWSER} finds no font under {FONT_DIRECTORY} and {manager} has "
|
||||
f"no font provide; on apt-get the fonts come from --install-deps, "
|
||||
f"which needs root."
|
||||
)
|
||||
log(f"Installing a font for {BROWSER} via {manager}: {provide}")
|
||||
run_privileged([*_INSTALL_ARGV[manager], provide])
|
||||
if not fonts_installed():
|
||||
raise RuntimeError(
|
||||
f"{BROWSER} still finds no font under {FONT_DIRECTORY} after "
|
||||
f"installing {provide} via {manager}."
|
||||
)
|
||||
|
||||
|
||||
def _ensure_browser() -> None:
|
||||
executable = browser_executable()
|
||||
if executable is None:
|
||||
@@ -214,6 +254,7 @@ def _ensure_browser() -> None:
|
||||
if executable is None:
|
||||
raise RuntimeError(f"{BROWSER} is still missing after provisioning.")
|
||||
_ensure_browser_libraries(executable)
|
||||
_ensure_fonts()
|
||||
|
||||
|
||||
def ensure() -> None:
|
||||
|
||||
Reference in new issue
Block a user