diff --git a/.github/workflows/call-orchestrator.yml b/.github/workflows/call-orchestrator.yml index a33a06c221..1bd7148ee3 100644 --- a/.github/workflows/call-orchestrator.yml +++ b/.github/workflows/call-orchestrator.yml @@ -146,6 +146,7 @@ jobs: test-dns: needs: - build-ci-images + - images-mirror-missing - validate-selection uses: ./.github/workflows/call-test-dns.yml with: diff --git a/cli/administration/deploy/development/compose.py b/cli/administration/deploy/development/compose.py index 682c955d3a..3905356f7e 100644 --- a/cli/administration/deploy/development/compose.py +++ b/cli/administration/deploy/development/compose.py @@ -10,10 +10,13 @@ from .env import compose_file_args from .network import detect_outer_network_mtu from .proc import run_streaming from .profile import Profile +from .runner_mirror import env_image if TYPE_CHECKING: from pathlib import Path +INIT_IMAGE_KEY = "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE" + class Compose: """Wrapper around `docker compose` for the dev/CI stack.""" @@ -135,6 +138,11 @@ class Compose: / "package-frontend" / "certs.sh" ) + if self.profile.image_mirror_enabled(): + env = { + **env, + INIT_IMAGE_KEY: env_image(self.repo_root, INIT_IMAGE_KEY), + } print(">>> Generating package-cache-frontend CA + per-hostname certs") subprocess.run( [str(helper)], diff --git a/cli/administration/deploy/development/env.py b/cli/administration/deploy/development/env.py index f22b27622f..c5c705cb44 100644 --- a/cli/administration/deploy/development/env.py +++ b/cli/administration/deploy/development/env.py @@ -27,6 +27,12 @@ def compose_file_args() -> list[str]: out += ["-f", "compose/cache.shared.override.yml"] if (os.environ.get("INFINITO_PUBLISH_PORTS") or "").strip().lower() == "false": out += ["-f", "compose/noports.override.yml"] + if profile.image_mirror_enabled(): + from utils.cache.files import PROJECT_ROOT + + from .runner_mirror import write_override + + out += ["-f", write_override(PROJECT_ROOT, out[1::2])] return out diff --git a/cli/administration/deploy/development/runner_mirror.py b/cli/administration/deploy/development/runner_mirror.py new file mode 100644 index 0000000000..ced2b8fbbe --- /dev/null +++ b/cli/administration/deploy/development/runner_mirror.py @@ -0,0 +1,68 @@ +"""Point the images the CI runner pulls itself at their GHCR mirror.""" + +from __future__ import annotations + +import os +from typing import TYPE_CHECKING + +from cli.contributing.mirror.providers import GHCRProvider +from utils.cache.yaml import dump_yaml +from utils.docker.image.discovery import iter_runner_images + +if TYPE_CHECKING: + from pathlib import Path + +OVERRIDE = "build/compose/runner-mirror.override.yml" + + +def mirrored_images(repo_root: Path) -> dict[tuple[str, str], str]: + """Return ``{(source_file, service): mirror reference}`` for every runner image. + + Args: + repo_root: repository root the runner images are declared under. + """ + provider = GHCRProvider( + os.environ["GITHUB_REPOSITORY_OWNER"], + os.environ["GITHUB_REPOSITORY"].split("/", 1)[-1], + os.environ["INFINITO_GHCR_MIRROR_PREFIX"], + ) + return { + ( + image.source_file, + image.service, + ): f"{provider.image_base(image)}:{image.version}" + for image in iter_runner_images(repo_root) + } + + +def write_override(repo_root: Path, layered: list[str]) -> str: + """Write the compose override that swaps the runner's images for mirrors. + + Args: + repo_root: repository root the compose files are relative to. + layered: compose files the stack is built from. Only their services + are overridden, so the override never adds a service of its own. + + Returns: + The override path relative to ``repo_root``. + """ + services = { + service: {"image": reference} + for (source_file, service), reference in mirrored_images(repo_root).items() + if source_file in layered + } + target = repo_root / OVERRIDE + staging = target.with_name(f"{target.name}.{os.getpid()}") + dump_yaml(staging, {"services": services}) + staging.replace(target) + return OVERRIDE + + +def env_image(repo_root: Path, key: str) -> str: + """Return the mirror reference for an image ``default.env`` declares. + + Args: + repo_root: repository root holding ``default.env``. + key: the ``default.env`` key naming the image. + """ + return mirrored_images(repo_root)[("default.env", key)] diff --git a/cli/contributing/mirror/README.md b/cli/contributing/mirror/README.md index af6a5f8ae0..36f1b3bc47 100644 --- a/cli/contributing/mirror/README.md +++ b/cli/contributing/mirror/README.md @@ -1,3 +1,5 @@ # Mirror 🪞 Plan and execute the GHCR image mirror pipeline: emit the `mirrors.yml` mapping that redirects role-declared images to the GHCR mirror, push images upstream-to-GHCR, and clean up stale mirror packages. + +The sync also mirrors the images the CI runner pulls itself, outside every role: the tagged `image` literals of `compose.yml` and `compose/cache.override.yml`, and the image keys of `default.env` listed in `RUNNER_ENV_IMAGES` ([discovery.py](../../../utils/docker/image/discovery.py)). On a GitHub runner, [runner_mirror.py](../../administration/deploy/development/runner_mirror.py) layers a generated compose override that points those services at their mirror, and hands the certificate generator the mirrored init image. diff --git a/cli/contributing/mirror/sync/__main__.py b/cli/contributing/mirror/sync/__main__.py index b7a892c9cf..2212f332db 100644 --- a/cli/contributing/mirror/sync/__main__.py +++ b/cli/contributing/mirror/sync/__main__.py @@ -4,10 +4,11 @@ import argparse import subprocess import sys import time +from itertools import chain from pathlib import Path from cli.contributing.mirror.providers import GHCRProvider -from utils.docker.image.discovery import iter_role_images +from utils.docker.image.discovery import iter_role_images, iter_runner_images def _validate_positive_int(value: str) -> int: @@ -52,7 +53,8 @@ def _throttle_before_next_copy( def main() -> int: parser = argparse.ArgumentParser( description=( - "Mirror every role-declared image to the configured GHCR registry, " + "Mirror every role-declared image and every image the CI runner " + "pulls itself to the configured GHCR registry, " "optionally throttled and optionally skipping already-mirrored " "tags." ), @@ -80,7 +82,7 @@ def main() -> int: last_start_ts: float | None = None - for img in iter_role_images(repo_root): + for img in chain(iter_role_images(repo_root), iter_runner_images(repo_root)): last_start_ts = _throttle_before_next_copy( images_per_hour=args.images_per_hour, last_start_ts=last_start_ts, diff --git a/cli/contributing/mirror/wait/__main__.py b/cli/contributing/mirror/wait/__main__.py index 9f3d911ccd..85769b2f7c 100644 --- a/cli/contributing/mirror/wait/__main__.py +++ b/cli/contributing/mirror/wait/__main__.py @@ -3,10 +3,11 @@ from __future__ import annotations import argparse import sys import time +from itertools import chain from pathlib import Path from cli.contributing.mirror.providers import GHCRProvider -from utils.docker.image.discovery import ImageRef, iter_role_images +from utils.docker.image.discovery import ImageRef, iter_role_images, iter_runner_images def _validate_positive_int(value: str) -> int: @@ -22,7 +23,8 @@ def _validate_positive_int(value: str) -> int: def main() -> int: parser = argparse.ArgumentParser( description=( - "Wait until every role-declared image has been mirrored to the " + "Wait until every role-declared image and every image the CI runner " + "pulls itself has been mirrored to the " "configured GHCR registry. Used on fork pull_request runs that depend " "on a pull_request_target mirror job populating the destination first." ), @@ -47,7 +49,7 @@ def main() -> int: repo_root = Path(args.repo_root).resolve() refs: dict[str, ImageRef] = {} - for img in iter_role_images(repo_root): + for img in chain(iter_role_images(repo_root), iter_runner_images(repo_root)): refs.setdefault(f"{provider.image_base(img)}:{img.version}", img) total = len(refs) diff --git a/package-lock.json b/package-lock.json index 1d40cf4db5..19db992e0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "devDependencies": { "@eslint/js": "^10.0.1", - "@playwright/test": "^1.63.0", + "@playwright/test": "^1.64.0", "eslint": "^10.12.0", "eslint-plugin-playwright": "^2.12.1", "globals": "^17.13.0", @@ -484,13 +484,13 @@ } }, "node_modules/@playwright/test": { - "version": "1.63.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.63.0.tgz", - "integrity": "sha512-oxMK4vllB9RK5NQ2l1pq1IfOf2AvnEuj/vYGDj0H2nMtmtZpKtCwt/l00GEO6xjGfpBNAvjovvYdCm50dRQkpQ==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.0.tgz", + "integrity": "sha512-oTN9FNYuN6bqQMwiho6jJKLCG2/QOYCixGXuCjRmzOq23eODeukuY2XiAVoVpAECbuezMt1MHQjAiQxK8F+Y+g==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright": "1.63.0" + "playwright": "1.64.0" }, "bin": { "playwright": "cli.js" @@ -1817,13 +1817,13 @@ } }, "node_modules/playwright": { - "version": "1.63.0", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.63.0.tgz", - "integrity": "sha512-+7ziBLidS4NaNCdt57SUDT+wYmmd5fmiQejUic/kb+YsYSCPyOOE9sebzMjNmQrsnNpDJqd4WHvV/8lfKfUDUg==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.0.tgz", + "integrity": "sha512-kVzTnYFYEyQ9RGzBjNCd2+yEqWmVbxl3AHPynv3qQ6JTjv4a+kwRcnqQwIpuP3NnrnIrE/Q6wWAIAvMfIE2/Yg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "playwright-core": "1.63.0" + "playwright-core": "1.64.0" }, "bin": { "playwright": "cli.js" @@ -1833,9 +1833,9 @@ } }, "node_modules/playwright-core": { - "version": "1.63.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.63.0.tgz", - "integrity": "sha512-rYCsBF/M5HjUch52bbtVONEFjv6Xu8sm8h72dNlR5bzIE1fvC/bxgspzkjSfU+MweEMmPM8KJebG6nnyxo5mCg==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.0.tgz", + "integrity": "sha512-T9r+MZkTECl2+oUcZ26YgZzTrYidTsIhYYkJix+6iDOymOb1FB2RLLSOxRGnZGv5DStt+aduIVbt+E8WygXYpg==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index d52cb43baa..529ad81295 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "devDependencies": { "@eslint/js": "^10.0.1", - "@playwright/test": "^1.63.0", + "@playwright/test": "^1.64.0", "eslint": "^10.12.0", "eslint-plugin-playwright": "^2.12.1", "globals": "^17.13.0", diff --git a/roles/svc-ai-ollama/meta/services.yml b/roles/svc-ai-ollama/meta/services.yml index cba1342a36..77fc9801ed 100644 --- a/roles/svc-ai-ollama/meta/services.yml +++ b/roles/svc-ai-ollama/meta/services.yml @@ -13,7 +13,7 @@ ollama: backup: no_stop_required: true image: ollama/ollama - version: 0.40.2 + version: 0.40.3 name: ollama min_storage: 3473MB cpus: "4.0" diff --git a/roles/sys-svc-proxy/templates/headers/forwarded.conf.j2 b/roles/sys-svc-proxy/templates/headers/forwarded.conf.j2 new file mode 100644 index 0000000000..834e8e82a5 --- /dev/null +++ b/roles/sys-svc-proxy/templates/headers/forwarded.conf.j2 @@ -0,0 +1,6 @@ +proxy_set_header Host $host; +proxy_set_header X-Real-IP $remote_addr; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header X-Forwarded-Proto {{ proxy_x_forwarded_proto | default('$scheme') }}; +proxy_set_header X-Forwarded-Port {{ lookup('tls', application_id, 'ports.web') }}; +proxy_set_header X-Forwarded-Ssl {{ lookup('tls', application_id, 'enabled') | on_off }}; diff --git a/roles/sys-svc-proxy/templates/location/html.conf.j2 b/roles/sys-svc-proxy/templates/location/html.conf.j2 index b910730594..d112d21596 100644 --- a/roles/sys-svc-proxy/templates/location/html.conf.j2 +++ b/roles/sys-svc-proxy/templates/location/html.conf.j2 @@ -19,13 +19,8 @@ location {{location}} {{ lookup('proxy_pass', application_id, proxy_service_key | default(application_id | get_entity_name), 'http', tail='request', location=location, local_port=http_port, internal_port=proxy_internal_port | default('')) }} - proxy_set_header Host $host; proxy_set_header Authorization $http_authorization; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto {{ proxy_x_forwarded_proto | default('$scheme') }}; - proxy_set_header X-Forwarded-Port {{ lookup('tls', application_id, 'ports.web') }}; - proxy_set_header X-Forwarded-Ssl {{ lookup('tls', application_id, 'enabled') | on_off }}; + {% include 'roles/sys-svc-proxy/templates/headers/forwarded.conf.j2' %} proxy_pass_request_headers on; {% include 'roles/sys-svc-proxy/templates/headers/upstream_strips.conf.j2' %} diff --git a/roles/sys-svc-proxy/templates/location/upload.conf.j2 b/roles/sys-svc-proxy/templates/location/upload.conf.j2 index 8e0560b2f9..02e4d56145 100644 --- a/roles/sys-svc-proxy/templates/location/upload.conf.j2 +++ b/roles/sys-svc-proxy/templates/location/upload.conf.j2 @@ -3,10 +3,7 @@ location {{ location_upload }} { {{ lookup('proxy_pass', application_id, proxy_service_key | default(application_id | get_entity_name), 'http', tail='plain', local_port=http_port, internal_port=proxy_internal_port | default('')) }} {% include 'roles/sys-svc-proxy/templates/headers/identity_request_strips.conf.j2' %} - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto {{ proxy_x_forwarded_proto | default('$scheme') }}; + {% include 'roles/sys-svc-proxy/templates/headers/forwarded.conf.j2' %} proxy_buffering off; proxy_request_buffering off; proxy_read_timeout 120s; diff --git a/roles/sys-svc-proxy/templates/location/ws.conf.j2 b/roles/sys-svc-proxy/templates/location/ws.conf.j2 index 316610d1af..bf937015dc 100644 --- a/roles/sys-svc-proxy/templates/location/ws.conf.j2 +++ b/roles/sys-svc-proxy/templates/location/ws.conf.j2 @@ -1,10 +1,7 @@ location {{ webserver_websocket_location }} { {% include 'roles/sys-svc-proxy/templates/headers/identity_request_strips.conf.j2' %} - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto {{ proxy_x_forwarded_proto | default('$scheme') }}; + {% include 'roles/sys-svc-proxy/templates/headers/forwarded.conf.j2' %} {{ lookup('proxy_pass', application_id, proxy_service_key | default(application_id | get_entity_name), 'http', tail='plain', local_port=websocket_port, internal_port=proxy_internal_port | default('')) }} {% include 'roles/sys-svc-proxy/templates/headers/upstream_strips.conf.j2' %} diff --git a/roles/web-app-bigbluebutton/meta/services.yml b/roles/web-app-bigbluebutton/meta/services.yml index 1391350f6f..887ca0d0da 100644 --- a/roles/web-app-bigbluebutton/meta/services.yml +++ b/roles/web-app-bigbluebutton/meta/services.yml @@ -267,7 +267,7 @@ bbb-webrtc-recorder: # nocheck: dynamic-flag: fixed upstream-compose helper, not group-gated dockerize: image: ghcr.io/jwilder/dockerize - version: "v0.15.1" + version: "v0.15.2" enabled: false # nocheck: playwright-service-flag, dynamic-flag infrastructure backup consumer diff --git a/roles/web-app-gitlab/meta/services.yml b/roles/web-app-gitlab/meta/services.yml index 018c3f952a..27ac8c52a4 100644 --- a/roles/web-app-gitlab/meta/services.yml +++ b/roles/web-app-gitlab/meta/services.yml @@ -76,7 +76,7 @@ gitlab: lifecycle: beta webservice: image: registry.gitlab.com/gitlab-org/build/cng/gitlab-webservice-ce - version: v19.4.1 + version: v19.4.2 name: gitlab-webservice healthcheck: test: ["CMD", "/scripts/healthcheck"] @@ -95,7 +95,7 @@ sidekiq: flavor: tcp path: liveness image: registry.gitlab.com/gitlab-org/build/cng/gitlab-sidekiq-ce - version: v19.4.1 + version: v19.4.2 name: gitlab-sidekiq cpus: "1.0" mem_reservation: 2g @@ -106,7 +106,7 @@ sidekiq: http: 3808 workhorse: image: registry.gitlab.com/gitlab-org/build/cng/gitlab-workhorse-ce - version: v19.4.1 + version: v19.4.2 name: gitlab-workhorse healthcheck: test: ["CMD", "/scripts/healthcheck"] @@ -118,7 +118,7 @@ gitaly: # nocheck: single-replica replicas: 1 image: registry.gitlab.com/gitlab-org/build/cng/gitaly - version: v19.4.1 + version: v19.4.2 healthcheck: test: ["CMD", "/scripts/healthcheck"] name: gitlab-gitaly @@ -131,7 +131,7 @@ gitaly: pids_limit: 1024 shell: image: registry.gitlab.com/gitlab-org/build/cng/gitlab-shell - version: v19.4.1 + version: v19.4.2 name: gitlab-shell ports: internal: @@ -144,7 +144,7 @@ migrations: # nocheck: single-replica replicas: 1 image: registry.gitlab.com/gitlab-org/build/cng/gitlab-rails-ce - version: v19.4.1 + version: v19.4.2 name: gitlab-migrations cpus: "1.0" mem_reservation: 1g diff --git a/roles/web-app-keycloak/files/playwright/playwright.spec.js b/roles/web-app-keycloak/files/playwright/playwright.spec.js index 1aac1d7279..facd0596e2 100644 --- a/roles/web-app-keycloak/files/playwright/playwright.spec.js +++ b/roles/web-app-keycloak/files/playwright/playwright.spec.js @@ -109,11 +109,11 @@ test("keycloak enforces Content-Security-Policy and exposes canonical domain fro const response = await gotoOnion(page, `${appBaseUrl}/realms/${realmName}/account/`); expect(response, "Expected Keycloak account page response").toBeTruthy(); expect(response.status(), "Expected Keycloak account page to respond successfully").toBeLessThan(400); + const documentHtml = await response.text(); const directives = assertCspResponseHeader(response, "keycloak account page"); await assertCspMetaParity(page, directives, "keycloak account page"); - const documentHtml = await response.text(); expect( documentHtml.includes(canonicalDomain) || (await page.content()).includes(canonicalDomain), `Expected canonical domain "${canonicalDomain}" (from applications lookup) to appear in the Keycloak UI` diff --git a/roles/web-app-n8n/meta/services.yml b/roles/web-app-n8n/meta/services.yml index 156c60abc5..64aa57e29f 100644 --- a/roles/web-app-n8n/meta/services.yml +++ b/roles/web-app-n8n/meta/services.yml @@ -67,7 +67,7 @@ n8n: backup: no_stop_required: false image: docker.n8n.io/n8nio/n8n - version: "2.42.3" + version: "2.43.4" update: type: registry_tags image: docker.n8n.io/n8nio/n8n diff --git a/roles/web-app-pixelfed/templates/compose.yml.j2 b/roles/web-app-pixelfed/templates/compose.yml.j2 index b25729f570..d8350aa173 100644 --- a/roles/web-app-pixelfed/templates/compose.yml.j2 +++ b/roles/web-app-pixelfed/templates/compose.yml.j2 @@ -5,7 +5,7 @@ {{ lookup('compose_only', 'container_name', PIXELFED_CONTAINER) }} {% include 'roles/sys-svc-container/templates/base.yml.j2' %} entrypoint: "{{ PIXELFED_ENTRYPOINT_DOCKER }}" - {{ lookup('container_extra_hosts') | indent(4) }} + {{ lookup('container_extra_hosts', host_alias=true) | indent(4) }} {{ lookup('container_volumes', service_name) | indent(4) }} {{ lookup('container_ports', ['pixelfed', 'http', DOCKER_BIND_HOST]) | indent(4) }} {{ lookup('container_depends_on', application_id) | indent(4) }} @@ -22,6 +22,7 @@ AUTORUN_ENABLED: "false" {{ lookup('container_volumes', service_name) | indent(4) }} entrypoint: "{{ PIXELFED_WORKER_ENTRYPOINT_DOCKER }}" + {{ lookup('container_extra_hosts', host_alias=true) | indent(4) }} {{ lookup('container_healthcheck', service_name) | indent(4) }} {{ lookup('container_depends_on', application_id, extra={ 'pixelfed': {'condition': 'service_started'}, diff --git a/roles/web-app-pixelfed/templates/env.j2 b/roles/web-app-pixelfed/templates/env.j2 index 01d90b2566..5fdd4b158e 100644 --- a/roles/web-app-pixelfed/templates/env.j2 +++ b/roles/web-app-pixelfed/templates/env.j2 @@ -152,5 +152,11 @@ PF_OIDC_CLIENT_SECRET={{ OIDC.CLIENT.SECRET | dotenv_quote }} PF_OIDC_CLIENT_ID={{ OIDC.CLIENT.ID | dotenv_quote }} # nocheck: env-file-literal-quoted-value PF_OIDC_SCOPES="openid profile email" +{% if PIXELFED_OIDC_SOCKS_PROXY | length > 0 %} + +http_proxy={{ PIXELFED_OIDC_SOCKS_PROXY }} +https_proxy={{ PIXELFED_OIDC_SOCKS_PROXY }} +no_proxy={{ PIXELFED_NO_PROXY }} +{% endif %} {% endif %} diff --git a/roles/web-app-pixelfed/vars/main.yml b/roles/web-app-pixelfed/vars/main.yml index fc32d818cb..1106f6ba36 100644 --- a/roles/web-app-pixelfed/vars/main.yml +++ b/roles/web-app-pixelfed/vars/main.yml @@ -7,6 +7,9 @@ PIXELFED_CONTAINER: "{{ lookup('config', application_id, 'services.pixelfed.name PIXELFED_WORKER_CONTAINER: "{{ lookup('config', application_id, 'services.worker.name') }}" PIXELFED_TITEL: "{{ lookup('config', application_id, 'services.pixelfed.titel') }}" PIXELFED_OIDC_ENABLED: "{{ lookup('config', application_id, 'services.sso.enabled') }}" +PIXELFED_OIDC_ONION_ISSUER: "{{ lookup('tls', 'web-app-keycloak', 'domain').endswith('.onion') }}" +PIXELFED_OIDC_SOCKS_PROXY: "{{ lookup('tor_socks_proxy') if PIXELFED_OIDC_ONION_ISSUER | bool else '' }}" +PIXELFED_NO_PROXY: "{{ ['localhost', '127.0.0.1', lookup('objstore', application_id, 'host')] | select | join(',') }}" PIXELFED_APP_USER: "33" PIXELFED_INSTANCE_DIR: "{{ lookup('container', application_id, 'directories.instance') }}" PIXELFED_ENV_FILE: "{{ lookup('container', application_id, 'files.env') }}" diff --git a/roles/web-app-prometheus/templates/nginx/healthz.conf.j2 b/roles/web-app-prometheus/templates/nginx/healthz.conf.j2 index ef5282c46f..914f08201d 100644 --- a/roles/web-app-prometheus/templates/nginx/healthz.conf.j2 +++ b/roles/web-app-prometheus/templates/nginx/healthz.conf.j2 @@ -53,7 +53,7 @@ location = /_live_probe { internal; {{ prometheus_backend }} - proxy_set_header Host $host; + {% include 'roles/sys-svc-proxy/templates/headers/forwarded.conf.j2' %} proxy_connect_timeout 2s; proxy_read_timeout 3s; proxy_intercept_errors off; @@ -62,7 +62,7 @@ location = /healthz/ready { access_log off; {{ prometheus_ready_backend }} - proxy_set_header Host $host; + {% include 'roles/sys-svc-proxy/templates/headers/forwarded.conf.j2' %} proxy_connect_timeout 3s; proxy_read_timeout 5s; proxy_intercept_errors off; diff --git a/roles/web-app-socialhome/meta/services.yml b/roles/web-app-socialhome/meta/services.yml index 43f68c9d7a..6f9a86ae8b 100644 --- a/roles/web-app-socialhome/meta/services.yml +++ b/roles/web-app-socialhome/meta/services.yml @@ -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.8" + version: "2026.10.9" ports: local: http: 8089 diff --git a/roles/web-app-stalwart/meta/services.yml b/roles/web-app-stalwart/meta/services.yml index 9f0b082711..fcb805d964 100644 --- a/roles/web-app-stalwart/meta/services.yml +++ b/roles/web-app-stalwart/meta/services.yml @@ -43,7 +43,7 @@ stalwart: # nocheck: default-placement-manager mail edge at a known IP: MX A-record, PTR and SPF bind to the stack host IP (a floating task's egress IP breaks deliverability); the mail store is NFS-hostile and IS the app — same rationale as web-app-mailu placement: manager image: stalwartlabs/stalwart - version: "v0.16.25" + version: "v0.16.26" webui_version: "v1.0.11" update: key: webui_version diff --git a/tests/unit/python/cli/administration/deploy/development/test_compose.py b/tests/unit/python/cli/administration/deploy/development/test_compose.py index 9e878575e5..db5b966ab6 100644 --- a/tests/unit/python/cli/administration/deploy/development/test_compose.py +++ b/tests/unit/python/cli/administration/deploy/development/test_compose.py @@ -98,9 +98,13 @@ class TestComposeUpRetries(unittest.TestCase): }, clear=False, ) + @patch( + "cli.administration.deploy.development.runner_mirror.write_override", + return_value="build/compose/runner-mirror.override.yml", + ) @patch("subprocess.run", autospec=True) def test_run_skips_cache_override_on_github_runner( - self, run_mock: MagicMock + self, run_mock: MagicMock, _write_override: MagicMock ) -> None: compose = self._compose() @@ -126,6 +130,8 @@ class TestComposeUpRetries(unittest.TestCase): "compose", "-f", "compose.yml", + "-f", + "build/compose/runner-mirror.override.yml", "ps", "-q", "infinito", diff --git a/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py b/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py new file mode 100644 index 0000000000..cb9763515a --- /dev/null +++ b/tests/unit/python/cli/administration/deploy/development/test_runner_mirror.py @@ -0,0 +1,107 @@ +from __future__ import annotations + +import os +import tempfile +import unittest +from pathlib import Path +from unittest.mock import patch + +from cli.administration.deploy.development import runner_mirror +from cli.administration.deploy.development.compose import INIT_IMAGE_KEY, Compose +from cli.administration.deploy.development.env import compose_file_args +from utils.cache.files import PROJECT_ROOT +from utils.cache.yaml import load_yaml_any + +GITHUB = { + "GITHUB_REPOSITORY_OWNER": "Acme", + "GITHUB_REPOSITORY": "Acme/Core", + "INFINITO_GHCR_MIRROR_PREFIX": "mirror", +} + +COMPOSE = """\ +services: + coredns: + image: coredns/coredns:1.14.4 +""" + +CACHE_OVERRIDE = """\ +services: + package-cache-frontend: + image: nginx:1.27-alpine +""" + + +def _repo(root: Path) -> Path: + (root / "compose").mkdir() + (root / "compose.yml").write_text(COMPOSE) + (root / "compose" / "cache.override.yml").write_text(CACHE_OVERRIDE) + (root / "default.env").write_text( + "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE=alpine:latest\n" + ) + return root + + +class TestRunnerMirror(unittest.TestCase): + @patch.dict(os.environ, GITHUB, clear=False) + def test_the_override_covers_only_services_of_layered_files(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + root = _repo(Path(tmp)) + relative = runner_mirror.write_override(root, ["compose.yml"]) + written = load_yaml_any(str(root / relative), default_if_missing={}) + self.assertEqual( + written, + { + "services": { + "coredns": { + "image": "ghcr.io/acme/core/mirror/docker.io/coredns/coredns:1.14.4" + } + } + }, + ) + + @patch.dict(os.environ, GITHUB, clear=False) + def test_the_init_image_resolves_to_its_mirror(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + reference = runner_mirror.env_image( + _repo(Path(tmp)), "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE" + ) + self.assertEqual(reference, "ghcr.io/acme/core/mirror/docker.io/alpine:latest") + + @patch.dict( + os.environ, + { + **GITHUB, + "INFINITO_RUNNING_ON_GITHUB": "true", + "INFINITO_GIT_COMMON_DIR": "", + "INFINITO_CACHE_STACK": "", + "INFINITO_CACHE_NETWORK": "", + "INFINITO_PUBLISH_PORTS": "", + }, + clear=False, + ) + def test_a_github_runner_layers_the_mirror_override_last(self) -> None: + with patch.object( + runner_mirror, "write_override", return_value=runner_mirror.OVERRIDE + ) as write: + args = compose_file_args() + write.assert_called_once_with(PROJECT_ROOT, ["compose.yml"]) + self.assertEqual(args[-2:], ["-f", runner_mirror.OVERRIDE]) + + @patch.dict( + os.environ, {**GITHUB, "INFINITO_RUNNING_ON_GITHUB": "true"}, clear=False + ) + def test_the_cert_generator_gets_the_mirrored_init_image(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + compose = Compose(_repo(Path(tmp)), "arch") + with patch("subprocess.run") as run: + compose._generate_package_frontend_certs( + {INIT_IMAGE_KEY: "alpine:latest"} + ) + self.assertEqual( + run.call_args.kwargs["env"][INIT_IMAGE_KEY], + "ghcr.io/acme/core/mirror/docker.io/alpine:latest", + ) + + +if __name__ == "__main__": # pragma: no cover + unittest.main() diff --git a/tests/unit/python/cli/contributing/mirror/test_sync.py b/tests/unit/python/cli/contributing/mirror/test_sync.py index 5aed8e86ef..2f8860eb69 100644 --- a/tests/unit/python/cli/contributing/mirror/test_sync.py +++ b/tests/unit/python/cli/contributing/mirror/test_sync.py @@ -23,6 +23,10 @@ class TestMirrorSync(unittest.TestCase): "cli.contributing.mirror.sync.__main__.iter_role_images", return_value=[image], ), + patch( + "cli.contributing.mirror.sync.__main__.iter_runner_images", + return_value=[], + ), patch.object( sync_main.GHCRProvider, "image_base", @@ -50,6 +54,43 @@ class TestMirrorSync(unittest.TestCase): mock_tag_exists.assert_called_once_with(image) mock_mirror.assert_not_called() + def test_runner_images_are_mirrored_with_the_role_images(self) -> None: + image = ImageRef( + role="runner", + service="coredns", + name="coredns/coredns", + version="1.14.4", + source="docker.io/coredns/coredns:1.14.4", + registry="docker.io", + source_file="compose.yml", + ) + + with ( + patch( + "cli.contributing.mirror.sync.__main__.iter_role_images", + return_value=[], + ), + patch( + "cli.contributing.mirror.sync.__main__.iter_runner_images", + return_value=[image], + ), + patch.object(sync_main.GHCRProvider, "mirror") as mock_mirror, + patch( + "sys.argv", + [ + "mirror-sync", + "--ghcr-namespace", + "acme", + "--ghcr-repository", + "myrepo", + ], + ), + ): + result = sync_main.main() + + self.assertEqual(result, 0) + mock_mirror.assert_called_once_with(image) + if __name__ == "__main__": # pragma: no cover unittest.main() diff --git a/tests/unit/python/cli/contributing/mirror/test_wait.py b/tests/unit/python/cli/contributing/mirror/test_wait.py new file mode 100644 index 0000000000..6467cfadfb --- /dev/null +++ b/tests/unit/python/cli/contributing/mirror/test_wait.py @@ -0,0 +1,56 @@ +from __future__ import annotations + +import unittest +from unittest.mock import patch + +import cli.contributing.mirror.wait.__main__ as wait_main +from cli.contributing.mirror.model import ImageRef + + +class TestMirrorWait(unittest.TestCase): + def test_a_missing_runner_mirror_keeps_the_wait_open(self) -> None: + image = ImageRef( + role="runner", + service="coredns", + name="coredns/coredns", + version="1.14.4", + source="docker.io/coredns/coredns:1.14.4", + registry="docker.io", + source_file="compose.yml", + ) + + with ( + patch( + "cli.contributing.mirror.wait.__main__.iter_role_images", + return_value=[], + ), + patch( + "cli.contributing.mirror.wait.__main__.iter_runner_images", + return_value=[image], + ), + patch.object( + wait_main.GHCRProvider, "tag_exists", return_value=False + ) as tag_exists, + patch( + "sys.argv", + [ + "mirror-wait", + "--ghcr-namespace", + "acme", + "--ghcr-repository", + "myrepo", + "--attempts", + "1", + "--sleep-seconds", + "1", + ], + ), + ): + result = wait_main.main() + + self.assertEqual(result, 1) + tag_exists.assert_called_once_with(image) + + +if __name__ == "__main__": # pragma: no cover + unittest.main() diff --git a/tests/unit/python/utils/docker/test_runner_images.py b/tests/unit/python/utils/docker/test_runner_images.py new file mode 100644 index 0000000000..48787e736e --- /dev/null +++ b/tests/unit/python/utils/docker/test_runner_images.py @@ -0,0 +1,78 @@ +from __future__ import annotations + +import tempfile +import unittest +from pathlib import Path + +from utils.cache.files import PROJECT_ROOT +from utils.docker.image.discovery import iter_runner_images + +COMPOSE = """\ +services: + coredns: + image: coredns/coredns:1.14.4 + infinito: + build: + context: . + interpolated: + image: ${INFINITO_IMAGE} + untagged: + image: busybox + pinned: + image: nginx@sha256:d5591131b1d898cd02fc7a17adb8ea026352d67809bc9289707778e9e03a76a4 +""" + +CACHE_OVERRIDE = """\ +services: + package-cache-frontend: + image: nginx:1.27-alpine +""" + +DEFAULT_ENV = "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE=alpine:latest\n" + + +def _repo(root: Path) -> Path: + (root / "compose").mkdir() + (root / "compose.yml").write_text(COMPOSE) + (root / "compose" / "cache.override.yml").write_text(CACHE_OVERRIDE) + (root / "default.env").write_text(DEFAULT_ENV) + return root + + +class TestRunnerImages(unittest.TestCase): + def test_tagged_literals_and_the_init_image_are_found(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + found = [ + (image.source_file, image.service, image.source) + for image in iter_runner_images(_repo(Path(tmp))) + ] + self.assertEqual( + found, + [ + ("compose.yml", "coredns", "docker.io/coredns/coredns:1.14.4"), + ( + "compose/cache.override.yml", + "package-cache-frontend", + "docker.io/library/nginx:1.27-alpine", + ), + ( + "default.env", + "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE", + "docker.io/library/alpine:latest", + ), + ], + ) + + def test_the_repository_declares_coredns_where_the_runner_reads_it(self) -> None: + services = { + (image.source_file, image.service) + for image in iter_runner_images(PROJECT_ROOT) + } + self.assertIn(("compose.yml", "coredns"), services) + self.assertIn( + ("default.env", "INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE"), services + ) + + +if __name__ == "__main__": # pragma: no cover + unittest.main() diff --git a/utils/docker/image/discovery.py b/utils/docker/image/discovery.py index 559003e0e7..3246b8fdd5 100644 --- a/utils/docker/image/discovery.py +++ b/utils/docker/image/discovery.py @@ -51,7 +51,8 @@ class ImageRef: version: e.g. ``17-3.5`` source: full pull ref, e.g. ``docker.io/library/postgres:16`` registry: source registry hostname, e.g. ``docker.io``, ``quay.io`` - source_file: role-relative file the ref was read from + source_file: file the ref was read from, role-relative for a role + image and repository-relative for a ``runner`` image """ role: str @@ -225,3 +226,53 @@ def iter_role_images(repo_root: Path) -> Iterable[ImageRef]: registry=_detect_registry(image), source_file=ROLE_FILE_META_SERVICES, ) + + +RUNNER_ROLE = "runner" +RUNNER_COMPOSE_FILES = ("compose.yml", "compose/cache.override.yml") +RUNNER_ENV_IMAGES = ("INFINITO_CACHE_PACKAGE_FRONTEND_INIT_IMAGE",) + + +def _runner_image(service: str, image: str, source_file: str) -> ImageRef | None: + base, suffix = split_name_and_suffix(image) + if not suffix.startswith(":") or not is_mirrorable_image(base): + return None + version = suffix[1:] + return ImageRef( + role=RUNNER_ROLE, + service=service, + name=canonical_image_name(base), + version=version, + source=image_source(base, version), + registry=_detect_registry(base), + source_file=source_file, + ) + + +def iter_runner_images(repo_root: Path) -> Iterable[ImageRef]: + """Yield the images the CI runner pulls itself, outside every role. + + Args: + repo_root: repository root holding the RUNNER_COMPOSE_FILES and + ``default.env``. A compose ``image`` that interpolates a variable, + carries no tag or is pinned by digest yields nothing. + """ + from utils.env.parser import parse_static_env + + for source_file in RUNNER_COMPOSE_FILES: + services = load_yaml(repo_root / source_file).get("services") or {} + for service, spec in services.items(): + image = ( + str(spec.get("image") or "").strip() if isinstance(spec, dict) else "" + ) + if not image or "${" in image: + continue + ref = _runner_image(str(service), image, source_file) + if ref is not None: + yield ref + + declared = parse_static_env(repo_root / "default.env") + for key in RUNNER_ENV_IMAGES: + ref = _runner_image(key, declared[key], "default.env") + if ref is not None: + yield ref