diff --git a/docs/requirements/039-core-i18n-consumers.md b/docs/requirements/039-core-i18n-consumers.md index fbfae21255..0508c3ea32 100644 --- a/docs/requirements/039-core-i18n-consumers.md +++ b/docs/requirements/039-core-i18n-consumers.md @@ -15,7 +15,7 @@ The consumer repositories change afterwards and are not part of this requirement - One built version needs about 2.3 GB. Building every translated language up front multiplies that per language; `min_storage` MUST say so. `min_storage` also gates which roles a host deploys at all, so it counts the sites every deployment builds and names the growth per further language. - The documentation is built from the git mirror of `DOCS_SOURCE_REPO`. Catalogs that exist only in a local working tree never reach it. - [logout-panel.js.j2](../../roles/web-app-keycloak/templates/logout-panel.js.j2) inlines [logout_i18n.yml](../../roles/web-app-keycloak/files/logout_i18n.yml) as a `{language: {key: text, dir}}` object, and [logout-panel.js](../../roles/web-app-keycloak/files/javascript/logout-panel.js) picks the language from `` and `navigator.language`. Its 29 non-English blocks are the only human translations core owns. -- port-ui translates the rendered `config.yaml` through `app/i18n/content/.yaml`, a flat mapping from the English source string to its translation for the keys `description`, `info`, `name`, `subtitel`, `text`, `title` and `warning`. [web-app-dashboard](../../roles/web-app-dashboard/meta/volumes.yml) mounts only `config.yaml` today, so every card and menu text stays English. +- port-ui translates the rendered `config.yaml` through `app/i18n/content/.yaml`, a flat mapping from the English source string to its translation for the keys `description`, `info`, `name`, `subtitel`, `text`, `title` and `warning`. [web-app-dashboard](../../roles/web-app-dashboard/meta/volumes.yml) mounts only `config.yaml`, and the upstream image ships no catalog, so every card and menu text stays English until the role builds them in. - [csp_filters.py](../../plugins/filter/csp_filters.py) adds a provider origin to `connect-src` only for known feature flags such as `simpleicons`. [web-app-mig](../../roles/web-app-mig/templates/compose.yml.j2) renders no environment and no API origin. ## Acceptance Criteria @@ -29,7 +29,7 @@ The consumer repositories change afterwards and are not part of this requirement - [x] `logout_i18n.yml` holds only the English source strings, and the logout panel reads every other language from `core.po`. - [ ] For each of the 29 languages of the former `logout_i18n.yml`, the rendered panel catalogue holds the same strings as before the migration. - [x] The logout panel takes the text direction of every language from `meta/languages.yml`. -- [x] web-app-dashboard mounts one port-ui content catalog per language that has a translated dashboard string, generated from `core.po` at deploy time. +- [x] web-app-dashboard bakes one port-ui content catalog per language that has a translated dashboard string into its image, generated from `core.po` at deploy time. - [x] The dashboard at `/de/` shows the German translation of at least one card description and one menu category. - [x] A role that enables the `api` service gets the web-svc-api origin in its `connect-src`, and a role without it does not. - [x] web-app-mig enables the `api` service when web-svc-api is deployed and renders the API base URL into its environment. diff --git a/roles/web-app-dashboard/files/Dockerfile b/roles/web-app-dashboard/files/Dockerfile new file mode 100644 index 0000000000..61e5a4f998 --- /dev/null +++ b/roles/web-app-dashboard/files/Dockerfile @@ -0,0 +1,5 @@ +ARG DASHBOARD_IMAGE +ARG DASHBOARD_VERSION +FROM ${DASHBOARD_IMAGE}:${DASHBOARD_VERSION} + +COPY i18n-content/ /app/i18n/content/ diff --git a/roles/web-app-dashboard/filter_plugins/i18n_content.py b/roles/web-app-dashboard/filter_plugins/i18n_content.py deleted file mode 100644 index 46d84b9804..0000000000 --- a/roles/web-app-dashboard/filter_plugins/i18n_content.py +++ /dev/null @@ -1,27 +0,0 @@ -from __future__ import annotations - - -def i18n_content_templates( - catalogues: dict, directory: str, template: str -) -> list[dict]: - """Return one ``render_replicated_templates`` entry per content catalog. - - Args: - catalogues: the ``lookup('i18n_content', ...)`` result, keyed by language. - directory: host directory port-ui mounts as ``i18n/content``. - template: template rendering the catalog named by ``language``. - """ - return [ - { - "src": template, - "dest": f"{directory.rstrip('/')}/{code}.yaml", - "language": code, - "mode": "0644", - } - for code in sorted(catalogues) - ] - - -class FilterModule: - def filters(self): - return {"i18n_content_templates": i18n_content_templates} diff --git a/roles/web-app-dashboard/meta/services.yml b/roles/web-app-dashboard/meta/services.yml index c9f5e34469..299ffc3a4e 100644 --- a/roles/web-app-dashboard/meta/services.yml +++ b/roles/web-app-dashboard/meta/services.yml @@ -40,6 +40,7 @@ dashboard: name: dashboard image: ghcr.io/kevinveenbirkenbach/port-ui version: 2.2.2 + custom: true min_storage: 549MB cpus: "0.3" mem_reservation: 256m diff --git a/roles/web-app-dashboard/meta/volumes.yml b/roles/web-app-dashboard/meta/volumes.yml index b6407d1a1a..aa6633bd26 100644 --- a/roles/web-app-dashboard/meta/volumes.yml +++ b/roles/web-app-dashboard/meta/volumes.yml @@ -6,9 +6,3 @@ config: mounts: - service: dashboard target: /app/config.yaml -i18n_content: - type: bind - source: "{{ [lookup('container', 'web-app-dashboard', 'directories.volumes'), 'i18n-content'] | path_join }}" - mounts: - - service: dashboard - target: /app/i18n/content diff --git a/roles/web-app-dashboard/tasks/00_core.yml b/roles/web-app-dashboard/tasks/00_core.yml index 14a5e7f03d..329f22fa53 100644 --- a/roles/web-app-dashboard/tasks/00_core.yml +++ b/roles/web-app-dashboard/tasks/00_core.yml @@ -18,17 +18,42 @@ dashboard_i18n_content: "{{ lookup('i18n_content', 'role:', 'menu:') }}" run_once: true -- name: "📁 Ensure the port-ui content catalog directory exists on every node" +- name: "📁 Ensure the port-ui content catalog directory exists in the build context" ansible.builtin.file: path: "{{ DASHBOARD_I18N_CONTENT_DIR }}" state: directory mode: "0755" + when: IS_STACK_HOST | bool -- name: "🌐 Render the port-ui content catalogs (local + swarm peers)" - ansible.builtin.include_tasks: - file: "{{ lookup('path_absolute', 'roles/sys-svc-compose/tasks/utils/render_replicated_templates.yml') }}" - vars: - role_templates: "{{ dashboard_i18n_content | i18n_content_templates(DASHBOARD_I18N_CONTENT_DIR, 'i18n-content.yaml.j2') }}" +- name: "🌐 Render the port-ui content catalogs into the build context" + stack_host_template: + src: "i18n-content.yaml.j2" + dest: "{{ [ DASHBOARD_I18N_CONTENT_DIR, item ~ '.yaml' ] | path_join }}" + loop: "{{ dashboard_i18n_content | list | sort }}" + notify: + - compose-build + - compose-up + - container-recreate + +- name: "🔎 Find the port-ui content catalogs already in the build context" + ansible.builtin.find: + paths: "{{ DASHBOARD_I18N_CONTENT_DIR }}" + patterns: "*.yaml" + file_type: file + register: dashboard_i18n_rendered + +- name: "🗑️ Drop the catalog of a language core no longer translates" + ansible.builtin.file: + path: "{{ item.path }}" + state: absent + loop: "{{ dashboard_i18n_rendered.files }}" + loop_control: + label: "{{ item.path | basename }}" + when: item.path | basename | regex_replace('[.]yaml$', '') not in dashboard_i18n_content + notify: + - compose-build + - compose-up + - container-recreate - name: "👔 Dashboard manager-side operations (file deploys + container exec)" include_tasks: 02_manager_ops.yml diff --git a/roles/web-app-dashboard/templates/compose.yml.j2 b/roles/web-app-dashboard/templates/compose.yml.j2 index 619e8c6420..b6eabc488f 100644 --- a/roles/web-app-dashboard/templates/compose.yml.j2 +++ b/roles/web-app-dashboard/templates/compose.yml.j2 @@ -2,6 +2,10 @@ {% set service_name = 'dashboard' %} {{ service_name }}: {% include 'roles/sys-svc-container/templates/deploy.yml.j2' %} + {{ lookup('template', 'roles/sys-svc-container/templates/build.yml.j2') | indent(4) }} + args: + DASHBOARD_IMAGE: "{{ DASHBOARD_IMAGE }}" + DASHBOARD_VERSION: "{{ DASHBOARD_VERSION }}" {{ lookup('container_image', application_id, 'dashboard') }} {{ lookup('compose_only', 'container_name', DASHBOARD_CONTAINER) }} {{ lookup('container_ports', ['dashboard', 'http', DOCKER_BIND_HOST]) | indent(4) }} diff --git a/roles/web-app-dashboard/templates/i18n-content.yaml.j2 b/roles/web-app-dashboard/templates/i18n-content.yaml.j2 index 40c4eb0a66..577a6924da 100644 --- a/roles/web-app-dashboard/templates/i18n-content.yaml.j2 +++ b/roles/web-app-dashboard/templates/i18n-content.yaml.j2 @@ -1 +1 @@ -{{ dashboard_i18n_content[_tpl.language] | to_nice_yaml(width=100000) }} +{{ dashboard_i18n_content[item] | to_nice_yaml(width=100000) }} diff --git a/roles/web-app-dashboard/vars/main.yml b/roles/web-app-dashboard/vars/main.yml index 019a4503f4..49c57c8094 100644 --- a/roles/web-app-dashboard/vars/main.yml +++ b/roles/web-app-dashboard/vars/main.yml @@ -21,7 +21,9 @@ DASHBOARD_LOCATION_SILENT_CHECK: "/silent-check-sso.html" DASHBOARD_CONFIG_YML_SRC_FILE: "config.yaml.j2" DASHBOARD_CONFIG_INV_PATH: "{{ [ inventory_dir, 'files', inventory_hostname ,'docker', DASHBOARD_APPLICATION_ID, DASHBOARD_CONFIG_YML_SRC_FILE] | path_join }}" DASHBOARD_CONFIG_YML_DEST: "{{ [ lookup('container', DASHBOARD_APPLICATION_ID, 'directories.volumes'), 'config.yaml' ] | path_join }}" -DASHBOARD_I18N_CONTENT_DIR: "{{ [ lookup('container', DASHBOARD_APPLICATION_ID, 'directories.volumes'), 'i18n-content' ] | path_join }}" +DASHBOARD_I18N_CONTENT_DIR: "{{ [ lookup('container', DASHBOARD_APPLICATION_ID, 'directories.instance'), 'i18n-content' ] | path_join }}" +DASHBOARD_IMAGE: "{{ lookup('config', DASHBOARD_APPLICATION_ID, 'services.dashboard.image') }}" +DASHBOARD_VERSION: "{{ lookup('config', DASHBOARD_APPLICATION_ID, 'services.dashboard.version') }}" DASHBOARD_APP_BASE_URL: "{{ lookup('tls', DASHBOARD_APPLICATION_ID, 'url.base') | regex_replace('/+$', '') }}/" DASHBOARD_KEYCLOAK_LOGIN_URL: >-